From 59cb293d987e52f094c22f1cbaa4719ea62ed42c Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 15:20:22 +0200 Subject: [PATCH] add handling for moving whole folders in the recycle bin --- .../gallery/activities/MainActivity.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index c4bc687b5..46211993b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -395,6 +395,26 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun deleteFolders(folders: ArrayList) { val fileDirItems = folders.map { FileDirItem(it.absolutePath, it.name, true) } as ArrayList + if (config.useRecycleBin) { + val pathsToDelete = ArrayList() + fileDirItems.filter { it.isDirectory }.forEach { + val files = File(it.path).listFiles() + files?.filter { it.absolutePath.isImageVideoGif() }?.mapTo(pathsToDelete) { it.absolutePath } + } + + movePathsInRecycleBin(pathsToDelete) { + if (it) { + deleteFilteredFolders(fileDirItems, folders) + } else { + toast(R.string.unknown_error_occurred) + } + } + } else { + deleteFilteredFolders(fileDirItems, folders) + } + } + + private fun deleteFilteredFolders(fileDirItems: ArrayList, folders: ArrayList) { deleteFolders(fileDirItems) { runOnUiThread { refreshItems()