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 065c24b94..2fe3db372 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 @@ -626,37 +626,43 @@ class DirectoryAdapter( return@handleSAFDialog } - var foldersToDelete = ArrayList(selectedKeys.size) - selectedDirs.forEach { - if (it.areFavorites() || it.isRecycleBin()) { - if (it.isRecycleBin()) { - tryEmptyRecycleBin(false) + activity.handleSAFDeleteSdk30Dialog(SAFPath){ + if (!it) { + return@handleSAFDeleteSdk30Dialog + } + + var foldersToDelete = ArrayList(selectedKeys.size) + selectedDirs.forEach { + if (it.areFavorites() || it.isRecycleBin()) { + if (it.isRecycleBin()) { + tryEmptyRecycleBin(false) + } else { + ensureBackgroundThread { + activity.mediaDB.clearFavorites() + activity.favoritesDB.clearFavorites() + listener?.refreshItems() + } + } + + if (selectedKeys.size == 1) { + finishActMode() + } } else { - ensureBackgroundThread { - activity.mediaDB.clearFavorites() - activity.favoritesDB.clearFavorites() - listener?.refreshItems() + foldersToDelete.add(File(it.path)) + } + } + + if (foldersToDelete.size == 1) { + activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success -> + if (success) { + listener?.deleteFolders(foldersToDelete) } } - - if (selectedKeys.size == 1) { - finishActMode() - } } else { - foldersToDelete.add(File(it.path)) + foldersToDelete = foldersToDelete.filter { !config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList + listener?.deleteFolders(foldersToDelete) } } - - if (foldersToDelete.size == 1) { - activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success -> - if (success) { - listener?.deleteFolders(foldersToDelete) - } - } - } else { - foldersToDelete = foldersToDelete.filter { !config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList - listener?.deleteFolders(foldersToDelete) - } } } 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 f25cb718d..e048add72 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 @@ -459,26 +459,35 @@ class MediaAdapter( return } - val SAFPath = getSelectedPaths().firstOrNull { activity.needsStupidWritePermissions(it) } ?: getFirstSelectedItemPath() ?: return + val selectedItems = getSelectedItems() + val selectedPaths = selectedItems.map { it.path } as ArrayList + val SAFPath = selectedPaths.firstOrNull { activity.needsStupidWritePermissions(it) } ?: getFirstSelectedItemPath() ?: return activity.handleSAFDialog(SAFPath) { if (!it) { return@handleSAFDialog } - val fileDirItems = ArrayList(selectedKeys.size) - val removeMedia = ArrayList(selectedKeys.size) - val positions = getSelectedItemPositions() + val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog + activity.handleSAFDeleteSdk30Dialog(sdk30SafPath){ + if (!it) { + return@handleSAFDeleteSdk30Dialog + } - getSelectedItems().forEach { - fileDirItems.add(FileDirItem(it.path, it.name)) - removeMedia.add(it) + val fileDirItems = ArrayList(selectedKeys.size) + val removeMedia = ArrayList(selectedKeys.size) + val positions = getSelectedItemPositions() + + selectedItems.forEach { + fileDirItems.add(FileDirItem(it.path, it.name)) + removeMedia.add(it) + } + + media.removeAll(removeMedia) + listener?.tryDeleteFiles(fileDirItems) + listener?.updateMediaGridDecoration(media) + removeSelectedItems(positions) + currentMediaHash = media.hashCode() } - - media.removeAll(removeMedia) - listener?.tryDeleteFiles(fileDirItems) - listener?.updateMediaGridDecoration(media) - removeSelectedItems(positions) - currentMediaHash = media.hashCode() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index e1a1e3f61..c3ac770a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -259,7 +259,7 @@ fun BaseSimpleActivity.tryDeleteFileDirItem( fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean, callback: ((wasSuccess: Boolean) -> Unit)? = null ) { - deleteFile(fileDirItem, allowDeleteFolder) { + deleteFile(fileDirItem, allowDeleteFolder, isDeletingMultipleFiles = false) { if (deleteFromDatabase) { ensureBackgroundThread { deleteDBPath(fileDirItem.path)