diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index c8d077376..a4f9ba824 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -855,7 +855,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } } - override fun tryDeleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList, onDelete: () -> Unit) { val filtered = fileDirItems.filter { !getIsPathDirectory(it.path) && it.path.isMediaFile() } as ArrayList if (filtered.isEmpty()) { return @@ -867,7 +867,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { movePathsInRecycleBin(filtered.map { it.path } as ArrayList) { if (it) { - deleteFilteredFiles(filtered) + deleteFilteredFiles(filtered, onDelete) } else { toast(R.string.unknown_error_occurred) } @@ -875,15 +875,17 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } else { val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size) toast(deletingItems) - deleteFilteredFiles(filtered) + deleteFilteredFiles(filtered, onDelete) } } private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false) - private fun deleteFilteredFiles(filtered: ArrayList) { - deleteFiles(filtered) { - if (!it) { + private fun deleteFilteredFiles(filtered: ArrayList, onDelete: () -> Unit) { + deleteFiles(filtered) { deleteSuccess -> + if (deleteSuccess) { + onDelete.invoke() + } else { toast(R.string.unknown_error_occurred) return@deleteFiles } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt index 73af513a2..fa4ec65ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt @@ -25,7 +25,6 @@ import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.ThumbnailItem -import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_search.* import java.io.File @@ -252,7 +251,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { startAsyncTask(true) } - override fun tryDeleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList, onDelete: () -> Unit) { val filtered = fileDirItems.filter { File(it.path).isFile && it.path.isMediaFile() } as ArrayList if (filtered.isEmpty()) { return @@ -264,7 +263,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { movePathsInRecycleBin(filtered.map { it.path } as ArrayList) { if (it) { - deleteFilteredFiles(filtered) + deleteFilteredFiles(filtered, onDelete) } else { toast(R.string.unknown_error_occurred) } @@ -272,13 +271,15 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { } else { val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size) toast(deletingItems) - deleteFilteredFiles(filtered) + deleteFilteredFiles(filtered, onDelete) } } - private fun deleteFilteredFiles(filtered: ArrayList) { - deleteFiles(filtered) { - if (!it) { + private fun deleteFilteredFiles(filtered: ArrayList, onDelete: () -> Unit) { + deleteFiles(filtered) { deleteSuccess -> + if (deleteSuccess) { + onDelete.invoke() + } else { toast(R.string.unknown_error_occurred) return@deleteFiles } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 6e3e0438f..036cf82ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -475,10 +475,11 @@ class MediaAdapter( } media.removeAll(removeMedia) - listener?.tryDeleteFiles(fileDirItems) + listener?.tryDeleteFiles(fileDirItems){ + removeSelectedItems(positions) + currentMediaHash = media.hashCode() + } listener?.updateMediaGridDecoration(media) - removeSelectedItems(positions) - currentMediaHash = media.hashCode() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 27bf5e88e..c42b53cb0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -245,7 +245,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) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt index 997adc44f..b25c92e01 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt @@ -6,7 +6,7 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem interface MediaOperationsListener { fun refreshItems() - fun tryDeleteFiles(fileDirItems: ArrayList) + fun tryDeleteFiles(fileDirItems: ArrayList, onDelete: () -> Unit) fun selectedPaths(paths: ArrayList)