From 98099303909d59c20c21c6b2b134cd58baff7ec0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 2 Jul 2019 23:18:07 +0200 Subject: [PATCH] properly handle locked folders and third party intents --- app/build.gradle | 2 +- .../gallery/pro/activities/MainActivity.kt | 10 +- .../pro/activities/PhotoVideoActivity.kt | 33 +++++-- .../gallery/pro/adapters/DirectoryAdapter.kt | 98 +++++++++++-------- .../pro/dialogs/PickDirectoryDialog.kt | 12 ++- 5 files changed, 98 insertions(+), 57 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fdebd0c0d..ff68d9cf1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.14.9' + implementation 'com.simplemobiletools:commons:5.14.11' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 aa8ab3f8a..fb3de0bde 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 @@ -769,10 +769,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun itemClicked(path: String) { - handleLockedFolderOpening(path) { - Intent(this, MediaActivity::class.java).apply { - putExtra(DIRECTORY, path) - handleMediaIntent(this) + handleLockedFolderOpening(path) { success -> + if (success) { + Intent(this, MediaActivity::class.java).apply { + putExtra(DIRECTORY, path) + handleMediaIntent(this) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt index c27186cd4..f8746bfa9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt @@ -98,8 +98,13 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList if (realPath != null && File(realPath).exists()) { if (realPath.getFilenameFromPath().contains('.') || filename.contains('.')) { if (isFileTypeVisible(realPath)) { - sendViewPagerIntent(realPath) - finish() + bottom_actions.beGone() + handleLockedFolderOpening(realPath.getParentPath()) { success -> + if (success) { + sendViewPagerIntent(realPath) + } + finish() + } return } } else { @@ -110,18 +115,28 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList if (mUri!!.scheme == "file") { if (filename.contains('.')) { - rescanPaths(arrayListOf(mUri!!.path)) - sendViewPagerIntent(mUri!!.path) - finish() - return + bottom_actions.beGone() + handleLockedFolderOpening(mUri!!.path.getParentPath()) { success -> + if (success) { + rescanPaths(arrayListOf(mUri!!.path)) + sendViewPagerIntent(mUri!!.path) + } + finish() + } } + return } else { val path = applicationContext.getRealPathFromURI(mUri!!) ?: "" if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms" && filename.contains('.') && File(path).exists()) { if (isFileTypeVisible(path)) { - rescanPaths(arrayListOf(mUri!!.path)) - sendViewPagerIntent(path) - finish() + bottom_actions.beGone() + handleLockedFolderOpening(path.getParentPath()) { success -> + if (success) { + rescanPaths(arrayListOf(mUri!!.path)) + sendViewPagerIntent(path) + } + finish() + } return } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 23ee7e7cf..cb1e7dba7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -159,8 +159,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + PropertiesDialog(activity, path, config.shouldShowHidden) + } } } } else { @@ -180,18 +182,20 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + RenameItemDialog(activity, dir.absolutePath) { + activity.runOnUiThread { + firstDir.apply { + path = it + name = it.getFilenameFromPath() + tmb = File(it, tmb.getFilenameFromPath()).absolutePath + } + updateDirs(dirs) + ensureBackgroundThread { + activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath) + listener?.refreshItems() + } } } } @@ -218,26 +222,32 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + hideFolder(path) + } } } else { config.wasHideFolderTooltipShown = true ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) { - activity.handleLockedFolderOpening(path) { - hideFolder(path) + activity.handleLockedFolderOpening(path) { success -> + if (success) { + hideFolder(path) + } } } } } else { - activity.handleLockedFolderOpening(path) { - activity.removeNoMedia(path) { - if (activity.config.shouldShowHidden) { - updateFolderNames() - } else { - activity.runOnUiThread { - listener?.refreshItems() - finishActMode() + activity.handleLockedFolderOpening(path) { success -> + if (success) { + activity.removeNoMedia(path) { + if (activity.config.shouldShowHidden) { + updateFolderNames() + } else { + activity.runOnUiThread { + listener?.refreshItems() + finishActMode() + } } } } @@ -257,18 +267,22 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + activity.emptyTheRecycleBin { + listener?.refreshItems() + } } } } private fun emptyAndDisableRecycleBin() { - activity.handleLockedFolderOpening(RECYCLE_BIN) { - activity.showRecycleBinEmptyingDialog { - activity.emptyAndDisableTheRecycleBin { - listener?.refreshItems() + activity.handleLockedFolderOpening(RECYCLE_BIN) { success -> + if (success) { + activity.showRecycleBinEmptyingDialog { + activity.emptyAndDisableTheRecycleBin { + listener?.refreshItems() + } } } } @@ -424,8 +438,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + createShortcut() + } } } @@ -524,8 +540,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + listener?.deleteFolders(foldersToDelete) + } } } else { foldersToDelete = foldersToDelete.filter { !activity.config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList @@ -535,8 +553,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (success) { + changeAlbumCover(useDefault) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt index 606c6ef12..c29f1e6b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt @@ -76,8 +76,10 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri private fun showOtherFolder() { FilePickerDialog(activity, sourcePath, false, showHidden, true, true) { - activity.handleLockedFolderOpening(it) { - callback(it) + activity.handleLockedFolderOpening(it) { success -> + if (success) { + callback(it) + } } } } @@ -102,8 +104,10 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri activity.toast(R.string.source_and_destination_same) return@DirectoryAdapter } else { - activity.handleLockedFolderOpening(path) { - callback(path) + activity.handleLockedFolderOpening(path) { success -> + if (success) { + callback(path) + } } dialog.dismiss() }