Skip to content

Commit

Permalink
make isR() an Extension and rename aboveQ() for more clearness
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraReichel committed Oct 28, 2020
1 parent 7ac03aa commit d8c836b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.lovoo.android.pickcore.destination.PrivateDirectory
import com.lovoo.android.pickcore.destination.PublicDirectory
import com.lovoo.android.pickcore.loader.CameraLoader
import com.lovoo.android.pickcore.permission.Permission
import com.lovoo.android.pickcore.util.isMinimumR

/**
* Ready to use solution to handle Android Camera capture.
Expand Down Expand Up @@ -122,7 +123,7 @@ class PickPicCaptureFragment : DialogFragment() {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == PERMISSION_REQUEST_CODE) {
val preferences = requireContext().getSharedPreferences(PREF_CATEGORY, Context.MODE_PRIVATE)
if (isR()) {
if (isMinimumR()) {
grantResults.forEach {
preferences.edit().putBoolean(PREF_KEY_PERMISSION, it != PackageManager.PERMISSION_DENIED).apply()
}
Expand Down Expand Up @@ -172,8 +173,6 @@ class PickPicCaptureFragment : DialogFragment() {
}
}

private fun isR() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R

companion object {
private const val CAMERA_REQUEST_CODE = 2734
private const val PERMISSION_REQUEST_CODE = 2735
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.lovoo.android.pickcore.contract.CameraDestination
import com.lovoo.android.pickcore.destination.PrivateDirectory
import com.lovoo.android.pickcore.destination.moveToPublicDirectory
import com.lovoo.android.pickcore.loader.CameraLoader
import com.lovoo.android.pickcore.util.aboveQ
import com.lovoo.android.pickcore.util.isMinimumQ
import io.reactivex.Single
import java.io.File

Expand All @@ -56,7 +56,7 @@ class CaptureResultWorker(

override fun createWork(): Single<Result> {
return Single.create<Result> { emitter ->
val file = if (isPublic || aboveQ()) inputFile else inputFile.moveToPublicDirectory().file
val file = if (isPublic || isMinimumQ()) inputFile else inputFile.moveToPublicDirectory().file

if (file == null) {
context.sendBroadcast(Intent(INTENT_ACTION_ON_RESULT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import androidx.exifinterface.media.ExifInterface
import androidx.fragment.app.Fragment
import com.lovoo.android.pickcore.contract.CameraDestination
import com.lovoo.android.pickcore.contract.getUri
import com.lovoo.android.pickcore.util.aboveQ
import com.lovoo.android.pickcore.util.isMinimumQ
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
Expand Down Expand Up @@ -133,7 +133,7 @@ object CameraLoader {

val shouldScale = scale < 0.9f
val shouldRotate = degree % 360 != 0
if (!shouldScale && !shouldRotate && !aboveQ()) {
if (!shouldScale && !shouldRotate && !isMinimumQ()) {
updateMediaScanner(context, arrayOf(filePath), null, listener)
return
}
Expand All @@ -159,7 +159,7 @@ object CameraLoader {
val appName = context.getString(context.applicationInfo.labelRes)

// Calculate new relative path for Q and before Q
val newFilePath = if (aboveQ()) {
val newFilePath = if (isMinimumQ()) {
val tempPath = filePath // .replace(".jpg", "-2.jpg")
val lastItem = tempPath.split("/").last()
tempPath.replaceAfterLast("/", "$appName/$lastItem")
Expand All @@ -174,7 +174,7 @@ object CameraLoader {
var fos: OutputStream? = null
try {
// Separate logic for Q and before Q
if (aboveQ()) {
if (isMinimumQ()) {
// Prepare file values for insertion
val values = ContentValues().apply {
val now = System.currentTimeMillis()
Expand Down Expand Up @@ -214,7 +214,7 @@ object CameraLoader {
val curUri = uri ?: fileUri ?: Uri.parse(path)
listener.onScanCompleted(path, curUri)
context.sendBroadcast(Intent(INTENT_INVALIDATE_GALLERY))
if (!aboveQ()) {
if (!isMinimumQ()) {
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, curUri))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import android.provider.MediaStore
import androidx.loader.content.CursorLoader
import com.lovoo.android.pickcore.Constants
import com.lovoo.android.pickcore.model.GalleryLib
import com.lovoo.android.pickcore.util.aboveQ
import com.lovoo.android.pickcore.util.isMinimumQ

/**
* A [CursorLoader] implementation that fetch album information from external [MediaStore.Files]
Expand All @@ -47,7 +47,7 @@ class GalleryLoader(
"${MediaStore.Images.Media.DISPLAY_NAME} ASC"
) {

private val columns = if (aboveQ()) arrayOf(
private val columns = if (isMinimumQ()) arrayOf(
MediaStore.Files.FileColumns._ID,
COLUMN_NAME_ID,
COLUMN_NAME_DISPLAY_NAME,
Expand All @@ -65,7 +65,7 @@ class GalleryLoader(
return try {
val galleries = super.loadInBackground()
val allEntry = MatrixCursor(columns)
if (aboveQ()) {
if (isMinimumQ()) {
loadCursorPostQ(galleries, allEntry)
} else {
loadCursorPreQ(galleries, allEntry)
Expand Down Expand Up @@ -159,7 +159,7 @@ class GalleryLoader(
private const val COLUMN_NAME_COUNT = "count"

private val query = MediaStore.Files.getContentUri("external")
private val projection = if (aboveQ()) arrayOf(
private val projection = if (isMinimumQ()) arrayOf(
MediaStore.Files.FileColumns._ID,
COLUMN_NAME_ID,
COLUMN_NAME_DISPLAY_NAME,
Expand All @@ -172,7 +172,7 @@ class GalleryLoader(
MediaStore.MediaColumns.DATA,
"COUNT(*) AS $COLUMN_NAME_COUNT"
)
private val group = if (aboveQ()) "" else ") GROUP BY ($COLUMN_NAME_ID"
private val group = if (isMinimumQ()) "" else ") GROUP BY ($COLUMN_NAME_ID"
private val selection = "${MediaStore.Files.FileColumns.MEDIA_TYPE}=? AND ${MediaStore.MediaColumns.SIZE}>0$group"
private val selectArguments = arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE.toString())

Expand All @@ -190,7 +190,7 @@ class GalleryLoader(
* @param cursor the [Cursor]
* @return the [GalleryLib] object with the data from the [Cursor]
*/
fun convert(cursor: Cursor) = if (aboveQ()) GalleryLib(
fun convert(cursor: Cursor) = if (isMinimumQ()) GalleryLib(
cursor.getString(cursor.getColumnIndex(COLUMN_NAME_ID)),
getUri(cursor)?.toString(),
cursor.getString(cursor.getColumnIndex(COLUMN_NAME_DISPLAY_NAME)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ package com.lovoo.android.pickcore.util

import android.os.Build

fun aboveQ() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
fun isMinimumQ() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q

fun isMinimumR() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R


0 comments on commit d8c836b

Please sign in to comment.