Skip to content

Commit

Permalink
Merge pull request #1277 from Lenkomotive/PAINTROID-532
Browse files Browse the repository at this point in the history
PAINTROID-532: Update app for android 13
  • Loading branch information
ThorstenBandel authored Aug 3, 2023
2 parents 2e2ff7c + 1be1a99 commit bd080c0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions Paintroid/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<uses-permission
android:name="android.permission.DUMP"
Expand Down
1 change: 1 addition & 0 deletions Paintroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

Expand Down
6 changes: 3 additions & 3 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ object FileIO {
cursor?.use {
if (cursor.moveToFirst()) {
fileName =
cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME))
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DISPLAY_NAME))
}
}
if (fileName.endsWith(FileType.JPG.toExtension()) || fileName.endsWith(".jpeg")) {
Expand Down Expand Up @@ -406,9 +406,9 @@ object FileIO {
val cursor = resolver.query(contentLocationUri, null, selection, selectionArgs, null)
cursor?.run {
while (moveToNext()) {
val fileName = getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME))
val fileName = getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME))
if (fileName == filename) {
val id = cursor.getLong(cursor.getColumnIndex(MediaStore.MediaColumns._ID))
val id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID))
close()
return ContentUris.withAppendedId(contentLocationUri, id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface MainActivityContracts {
interface Navigator {
val isSdkAboveOrEqualM: Boolean
val isSdkAboveOrEqualQ: Boolean
val isSdkAboveOrEqualT: Boolean

fun showColorPickerDialog()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.catrobat.paintroid.presenter

import android.Manifest
import android.annotation.TargetApi
import android.app.Activity
import android.content.ContentResolver
import android.content.ContentUris
Expand Down Expand Up @@ -386,7 +387,22 @@ open class MainActivityPresenter(
)
return
}
if (navigator.isSdkAboveOrEqualQ) {

@TargetApi(Build.VERSION_CODES.TIRAMISU)
if (navigator.isSdkAboveOrEqualT) {
if (!navigator.doIHavePermission(Manifest.permission.READ_MEDIA_IMAGES)) {
navigator.askForPermission(
arrayOf(Manifest.permission.READ_MEDIA_IMAGES),
requestCode
)
} else {
handleRequestPermissionsResult(
requestCode,
arrayOf(Manifest.permission.READ_MEDIA_IMAGES),
intArrayOf(PackageManager.PERMISSION_GRANTED)
)
}
} else if (navigator.isSdkAboveOrEqualQ) {
if (!navigator.doIHavePermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
navigator.askForPermission(
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
Expand Down Expand Up @@ -472,7 +488,9 @@ open class MainActivityPresenter(
permissions: Array<String>,
grantResults: IntArray
) {
if (permissions.size == 1 && (permissions[0] == Manifest.permission.READ_EXTERNAL_STORAGE || permissions[0] == Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (permissions.size == 1 && (permissions[0] == Manifest.permission.READ_EXTERNAL_STORAGE ||
permissions[0] == Manifest.permission.WRITE_EXTERNAL_STORAGE ||
permissions[0] == Manifest.permission.READ_MEDIA_IMAGES)) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
when (requestCode) {
PERMISSION_EXTERNAL_STORAGE_SAVE -> {
Expand Down Expand Up @@ -1052,7 +1070,7 @@ open class MainActivityPresenter(
val cursor = fileActivity?.contentResolver?.query(uri, null, null, null, null)
cursor?.use {
if (it.moveToFirst()) {
result = it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME))
result = it.getString(it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class MainActivityNavigator(
@SuppressLint("AnnotateVersionCheck")
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q

override val isSdkAboveOrEqualT: Boolean
@SuppressLint("AnnotateVersionCheck")
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU

private var commandFactory: CommandFactory = DefaultCommandFactory()

private fun showFragment(
Expand Down Expand Up @@ -190,7 +194,7 @@ class MainActivityNavigator(
val queryCursor = mainActivity.contentResolver.query(uri, null, null, null, null)
queryCursor.use { cursor ->
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
result = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ class MainActivityPresenterTest {
false
)
presenter!!.switchBetweenVersions(PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW)

Mockito.verify<Interactor?>(interactor).saveImage(
presenter!!, SAVE_IMAGE_LOAD_NEW, workspace!!.layerModel,
commandSerializer!!, FileIO.storeImageUri,
Expand All @@ -1445,20 +1446,20 @@ class MainActivityPresenterTest {
@Test
fun testSaveAndLoadImagePermissionNotGranted() {
Mockito.`when`(navigator!!.doIHavePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE))
.thenReturn(false)
.thenReturn(false)
Mockito.`when`(navigator.isSdkAboveOrEqualM).thenReturn(false).thenReturn(true)
presenter!!.saveBeforeLoadImage()
Mockito.verify<MainActivityContracts.Navigator?>(navigator)
.showSaveImageInformationDialogWhenStandalone(
PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW,
sharedPreferences!!.preferenceImageNumber,
false
)
.showSaveImageInformationDialogWhenStandalone(
PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW,
sharedPreferences!!.preferenceImageNumber,
false
)
presenter!!.switchBetweenVersions(PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW)
Mockito.verify<MainActivityContracts.Navigator?>(navigator).askForPermission(
arrayOf<String>(
Manifest.permission.WRITE_EXTERNAL_STORAGE
), PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW
arrayOf<String>(
Manifest.permission.WRITE_EXTERNAL_STORAGE
), PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW
)
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ plugins {
}

ext {
androidCompileSdkVersion = 30
androidCompileSdkVersion = 33
androidMinSdkVersion = 21
androidTargetSdkVersion = 31
androidTargetSdkVersion = 33

androidSupportLibraryVersion = '28.0.0'

Expand Down

0 comments on commit bd080c0

Please sign in to comment.