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
This commit is contained in:
darthpaul 2022-04-10 09:56:21 +01:00
parent 2ea542b461
commit e1d8f601d7
3 changed files with 19 additions and 4 deletions

View File

@ -1166,6 +1166,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun renameFile() { private fun renameFile() {
val oldPath = getCurrentPath() 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) { RenameItemDialog(this, oldPath) {
getCurrentMedia()[mPos].apply { getCurrentMedia()[mPos].apply {
path = it path = it

View File

@ -234,11 +234,19 @@ class MediaAdapter(
} }
private fun renameFile() { 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) { if (selectedKeys.size == 1) {
val oldPath = getFirstSelectedItemPath() ?: return RenameItemDialog(activity, firstPath) {
RenameItemDialog(activity, oldPath) {
ensureBackgroundThread { ensureBackgroundThread {
activity.updateDBMediaPath(oldPath, it) activity.updateDBMediaPath(firstPath, it)
activity.runOnUiThread { activity.runOnUiThread {
enableInstantLoad() enableInstantLoad()

View File

@ -111,7 +111,7 @@ class PickDirectoryDialog(
if (path.trimEnd('/') == sourcePath) { if (path.trimEnd('/') == sourcePath) {
activity.toast(R.string.source_and_destination_same) activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter return@DirectoryAdapter
} else if (isRPlus() && path.isBasePath(activity)) { } else if (isRPlus() && activity.isAStorageRootFolder(path)) {
activity.toast(R.string.copy_to_restricted_folder_message) activity.toast(R.string.copy_to_restricted_folder_message)
return@DirectoryAdapter return@DirectoryAdapter
} else { } else {