From e1d8f601d781a3cfd7951bd2683053963ea1fddc Mon Sep 17 00:00:00 2001 From: darthpaul Date: Sun, 10 Apr 2022 09:56:21 +0100 Subject: [PATCH] fix renaming - show error message when a user tries to rename a file on the root of the SD Card in ViewPagerActivity and MediaAdapter - in PickDirectoryDialog, use the Activity.isAStorageRootFolder method instead of String.isBasePath --- .../gallery/pro/activities/ViewPagerActivity.kt | 7 +++++++ .../gallery/pro/adapters/MediaAdapter.kt | 14 +++++++++++--- .../gallery/pro/dialogs/PickDirectoryDialog.kt | 2 +- 3 files changed, 19 insertions(+), 4 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 6a29622b3..8b5562a8a 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 @@ -1166,6 +1166,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun renameFile() { val oldPath = getCurrentPath() + + val isSDOrOtgRootFolder = isAStorageRootFolder(oldPath.getParentPath()) && !oldPath.startsWith(internalStoragePath) + if (isRPlus() && isSDOrOtgRootFolder) { + toast(R.string.rename_in_sd_card_system_restriction) + return + } + RenameItemDialog(this, oldPath) { getCurrentMedia()[mPos].apply { path = it diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 9b07dca42..1a9f6fcbf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -234,11 +234,19 @@ class MediaAdapter( } private fun renameFile() { + val firstPath = getFirstSelectedItemPath() ?: return + + val isSDOrOtgRootFolder = activity.isAStorageRootFolder(firstPath.getParentPath()) && !firstPath.startsWith(activity.internalStoragePath) + if (isRPlus() && isSDOrOtgRootFolder) { + activity.toast(R.string.rename_in_sd_card_system_restriction) + finishActMode() + return + } + if (selectedKeys.size == 1) { - val oldPath = getFirstSelectedItemPath() ?: return - RenameItemDialog(activity, oldPath) { + RenameItemDialog(activity, firstPath) { ensureBackgroundThread { - activity.updateDBMediaPath(oldPath, it) + activity.updateDBMediaPath(firstPath, it) activity.runOnUiThread { enableInstantLoad() 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 06a80e232..b9d39ef40 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 @@ -111,7 +111,7 @@ class PickDirectoryDialog( if (path.trimEnd('/') == sourcePath) { activity.toast(R.string.source_and_destination_same) return@DirectoryAdapter - } else if (isRPlus() && path.isBasePath(activity)) { + } else if (isRPlus() && activity.isAStorageRootFolder(path)) { activity.toast(R.string.copy_to_restricted_folder_message) return@DirectoryAdapter } else {