From 399c8e241d49c994a85507cac9c929fc4646062a Mon Sep 17 00:00:00 2001 From: darthpaul Date: Sat, 19 Mar 2022 20:30:59 +0000 Subject: [PATCH] SDK 30 changes - handle SAF dialog on ViewPagerActivity before refreshing screen --- .../pro/activities/ViewPagerActivity.kt | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index d9c47db15..581b5ae47 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1109,20 +1109,26 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { - mIgnoredPaths.add(fileDirItem.path) - val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList - runOnUiThread { - gotMedia(media, true, false) - } + handleSAFDialogSdk30(fileDirItem.path) { + if (!it) { + return@handleSAFDialogSdk30 + } - movePathsInRecycleBin(arrayListOf(path)) { - if (it) { - tryDeleteFileDirItem(fileDirItem, false, false) { - mIgnoredPaths.remove(fileDirItem.path) - deleteDirectoryIfEmpty() + mIgnoredPaths.add(fileDirItem.path) + val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList + runOnUiThread { + gotMedia(media, true, false) + } + + movePathsInRecycleBin(arrayListOf(path)) { + if (it) { + tryDeleteFileDirItem(fileDirItem, false, false) { + mIgnoredPaths.remove(fileDirItem.path) + deleteDirectoryIfEmpty() + } + } else { + toast(R.string.unknown_error_occurred) } - } else { - toast(R.string.unknown_error_occurred) } } } else { @@ -1131,15 +1137,21 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun handleDeletion(fileDirItem: FileDirItem) { - mIgnoredPaths.add(fileDirItem.path) - val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList - runOnUiThread { - gotMedia(media, true, false) - } + handleSAFDialogSdk30(fileDirItem.path) { + if (!it) { + return@handleSAFDialogSdk30 + } - tryDeleteFileDirItem(fileDirItem, false, true) { - mIgnoredPaths.remove(fileDirItem.path) - deleteDirectoryIfEmpty() + mIgnoredPaths.add(fileDirItem.path) + val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList + runOnUiThread { + gotMedia(media, true, false) + } + + tryDeleteFileDirItem(fileDirItem, false, true) { + mIgnoredPaths.remove(fileDirItem.path) + deleteDirectoryIfEmpty() + } } }