From cbf831bd314730c46ab64b6bb5bdce99b9a5aa22 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 Sep 2020 22:38:26 +0200 Subject: [PATCH] improve storage permission handling to fix an Android 11 issue --- .../gallery/pro/activities/MainActivity.kt | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index b21fbca6e..6d9362de0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -436,22 +436,27 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun tryLoadGallery() { - if (hasPermission(PERMISSION_WRITE_STORAGE)) { - if (!config.wasUpgradedFromFreeShown && isPackageInstalled("com.simplemobiletools.gallery")) { - ConfirmationDialog(this, "", R.string.upgraded_from_free, R.string.ok, 0) {} - config.wasUpgradedFromFreeShown = true - } + handlePermission(PERMISSION_WRITE_STORAGE) { + if (it) { + if (!config.wasUpgradedFromFreeShown && isPackageInstalled("com.simplemobiletools.gallery")) { + ConfirmationDialog(this, "", R.string.upgraded_from_free, R.string.ok, 0) {} + config.wasUpgradedFromFreeShown = true + } - checkOTGPath() - checkDefaultSpamFolders() + checkOTGPath() + checkDefaultSpamFolders() - if (config.showAll) { - showAllMedia() + if (config.showAll) { + showAllMedia() + } else { + getDirectories() + } + + setupLayoutManager() } else { - getDirectories() + toast(R.string.no_storage_permissions) + finish() } - - setupLayoutManager() } }