Merge branch 'ref/delete-animation' of https://github.com/KryptKode/Simple-Gallery

This commit is contained in:
tibbi 2022-02-25 23:04:24 +01:00
commit 8cb4b9bc3b
3 changed files with 54 additions and 39 deletions

View file

@ -626,37 +626,43 @@ class DirectoryAdapter(
return@handleSAFDialog
}
var foldersToDelete = ArrayList<File>(selectedKeys.size)
selectedDirs.forEach {
if (it.areFavorites() || it.isRecycleBin()) {
if (it.isRecycleBin()) {
tryEmptyRecycleBin(false)
activity.handleSAFDeleteSdk30Dialog(SAFPath){
if (!it) {
return@handleSAFDeleteSdk30Dialog
}
var foldersToDelete = ArrayList<File>(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<File>
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<File>
listener?.deleteFolders(foldersToDelete)
}
}
}

View file

@ -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<String>
val SAFPath = selectedPaths.firstOrNull { activity.needsStupidWritePermissions(it) } ?: getFirstSelectedItemPath() ?: return
activity.handleSAFDialog(SAFPath) {
if (!it) {
return@handleSAFDialog
}
val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
val removeMedia = ArrayList<Medium>(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<FileDirItem>(selectedKeys.size)
val removeMedia = ArrayList<Medium>(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()
}
}

View file

@ -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)