Skip to content

Commit

Permalink
Merge pull request #23 from lovoo/android-30-upgrade
Browse files Browse the repository at this point in the history
Add query for Android 30 target
  • Loading branch information
SandraReichel authored Oct 28, 2020
2 parents c163622 + d8c836b commit a9e712e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object AppStart {
intent.addCategory(Intent.CATEGORY_HOME)
val pm = InstrumentationRegistry.getInstrumentation().context.packageManager
val resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
return resolveInfo.activityInfo.packageName
return resolveInfo?.activityInfo?.packageName ?: ""
}

fun launchApp(device: UiDevice) {
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ buildscript {
ext.orchestrator_version = "1.2.0"
ext.androidX_test_version = "1.2.0"

ext.target_version = 29
ext.target_version = 30
ext.min_version = 18

def version = System.getenv("VERSION")
def code = System.getenv("VERSION_CODE")
ext.version_name = version == null ? "1.2.1" : version
ext.version_name = version == null ? "1.3.0" : version
ext.version_code = code == null ? 10 : code.toInteger()

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:3.6.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:0.9.18'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.27.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
Expand All @@ -38,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 @@ -120,6 +122,15 @@ class PickPicCaptureFragment : DialogFragment() {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == PERMISSION_REQUEST_CODE) {
val preferences = requireContext().getSharedPreferences(PREF_CATEGORY, Context.MODE_PRIVATE)
if (isMinimumR()) {
grantResults.forEach {
preferences.edit().putBoolean(PREF_KEY_PERMISSION, it != PackageManager.PERMISSION_DENIED).apply()
}
} else {
preferences.edit().putBoolean(PREF_KEY_PERMISSION, false).apply()
}

val deniedPermissions = Permission.getDeniedPermissions(requireActivity(), Permission.cameraPermissions.plus(Permission.galleryPermissions))
if (deniedPermissions.isEmpty()) {
startCamera()
Expand All @@ -138,7 +149,6 @@ class PickPicCaptureFragment : DialogFragment() {
if (!isFirstTime && deniedList.firstOrNull { it.second } != null) {
Permission.openSettings(requireActivity())
} else {
preferences.edit().putBoolean(PREF_KEY_PERMISSION, false).apply()
val permissions = Array(deniedList.size) { i -> deniedList[i].first }
Permission.requestPermissions(this, PERMISSION_REQUEST_CODE, permissions)
}
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
6 changes: 6 additions & 0 deletions pickcore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:remove="android:maxSdkVersion" />

<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
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 a9e712e

Please sign in to comment.