From 9ca6f2235b6e7a7914ad8cd1a5f48fcc2f10a204 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Mar 2019 21:13:31 +0100 Subject: [PATCH] fix #1313, delete only the visible files at deleting folders --- .../gallery/pro/activities/MainActivity.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) 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 46240a664..365aaec98 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 @@ -500,36 +500,39 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } + val itemsToDelete = ArrayList() + val filter = config.filterMedia + val showHidden = config.shouldShowHidden + fileDirItems.filter { it.isDirectory }.forEach { + val files = File(it.path).listFiles() + files?.filter { + it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && + ((it.isImageFast() && filter and TYPE_IMAGES != 0) || + (it.isVideoFast() && filter and TYPE_VIDEOS != 0) || + (it.isGif() && filter and TYPE_GIFS != 0) || + (it.isRawFast() && filter and TYPE_RAWS != 0) || + (it.isSvg() && filter and TYPE_SVGS != 0)) + }?.mapTo(itemsToDelete) { it.toFileDirItem(this) } + } + if (config.useRecycleBin) { val pathsToDelete = ArrayList() - val filter = config.filterMedia - val showHidden = config.shouldShowHidden - fileDirItems.filter { it.isDirectory }.forEach { - val files = File(it.path).listFiles() - files?.filter { - it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && - ((it.isImageFast() && filter and TYPE_IMAGES != 0) || - (it.isVideoFast() && filter and TYPE_VIDEOS != 0) || - (it.isGif() && filter and TYPE_GIFS != 0) || - (it.isRawFast() && filter and TYPE_RAWS != 0) || - (it.isSvg() && filter and TYPE_SVGS != 0)) - }?.mapTo(pathsToDelete) { it.absolutePath } - } + itemsToDelete.mapTo(pathsToDelete) { it.path } movePathsInRecycleBin(pathsToDelete, mMediumDao) { if (it) { - deleteFilteredFolders(fileDirItems, folders) + deleteFilteredFileDirItems(itemsToDelete, folders) } else { toast(R.string.unknown_error_occurred) } } } else { - deleteFilteredFolders(fileDirItems, folders) + deleteFilteredFileDirItems(itemsToDelete, folders) } } - private fun deleteFilteredFolders(fileDirItems: ArrayList, folders: ArrayList) { - deleteFolders(fileDirItems) { + private fun deleteFilteredFileDirItems(fileDirItems: ArrayList, folders: ArrayList) { + deleteFiles(fileDirItems) { runOnUiThread { refreshItems() }