From 7600fa68b4992c14e9d2f2d7298feb0a15a71b5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 11:51:17 +0200 Subject: [PATCH] improve file deleting from thumbnails view --- .../gallery/activities/MediaActivity.kt | 23 +++++++++++-------- .../gallery/adapters/MediaAdapter.kt | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 63ce77841..68aca393e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -671,22 +671,27 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } } - override fun deleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList deleteFiles(filtered) { if (!it) { toast(R.string.unknown_error_occurred) - } else if (mMedia.isEmpty()) { + return@deleteFiles + } + + mMedia.removeAll { filtered.map { it.path }.contains(it.path) } + + Thread { + val mediumDao = galleryDB.MediumDao() + filtered.forEach { + mediumDao.deleteMediumPath(it.path) + } + }.start() + + if (mMedia.isEmpty()) { deleteDirectoryIfEmpty() deleteDBDirectory() finish() - } else { - Thread { - val mediumDao = galleryDB.MediumDao() - filtered.forEach { - mediumDao.deleteMediumPath(it.path) - } - }.start() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 46369f095..a20c58a82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -241,7 +241,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } media.removeAll(removeMedia) - listener?.deleteFiles(fileDirItems) + listener?.tryDeleteFiles(fileDirItems) removeSelectedItems() } } @@ -327,7 +327,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, interface MediaOperationsListener { fun refreshItems() - fun deleteFiles(fileDirItems: ArrayList) + fun tryDeleteFiles(fileDirItems: ArrayList) fun selectedPaths(paths: ArrayList) }