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