fix: show delete animation after file delete

This commit is contained in:
darthpaul 2022-02-15 00:21:53 +00:00
parent 5ae167c7d8
commit bbcb41cf1f
5 changed files with 22 additions and 18 deletions

View file

@ -855,7 +855,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
} }
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit) {
val filtered = fileDirItems.filter { !getIsPathDirectory(it.path) && it.path.isMediaFile() } as ArrayList val filtered = fileDirItems.filter { !getIsPathDirectory(it.path) && it.path.isMediaFile() } as ArrayList
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
return return
@ -867,7 +867,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) { movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
if (it) { if (it) {
deleteFilteredFiles(filtered) deleteFilteredFiles(filtered, onDelete)
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
@ -875,15 +875,17 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
} else { } else {
val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size) val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size)
toast(deletingItems) toast(deletingItems)
deleteFilteredFiles(filtered) deleteFilteredFiles(filtered, onDelete)
} }
} }
private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false) private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false)
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) { private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
deleteFiles(filtered) { deleteFiles(filtered) { deleteSuccess ->
if (!it) { if (deleteSuccess) {
onDelete.invoke()
} else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return@deleteFiles return@deleteFiles
} }

View file

@ -25,7 +25,6 @@ import com.simplemobiletools.gallery.pro.helpers.*
import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener
import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.Medium
import com.simplemobiletools.gallery.pro.models.ThumbnailItem import com.simplemobiletools.gallery.pro.models.ThumbnailItem
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_search.* import kotlinx.android.synthetic.main.activity_search.*
import java.io.File import java.io.File
@ -252,7 +251,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
startAsyncTask(true) startAsyncTask(true)
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit) {
val filtered = fileDirItems.filter { File(it.path).isFile && it.path.isMediaFile() } as ArrayList val filtered = fileDirItems.filter { File(it.path).isFile && it.path.isMediaFile() } as ArrayList
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
return return
@ -264,7 +263,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) { movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
if (it) { if (it) {
deleteFilteredFiles(filtered) deleteFilteredFiles(filtered, onDelete)
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
@ -272,13 +271,15 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
} else { } else {
val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size) val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size)
toast(deletingItems) toast(deletingItems)
deleteFilteredFiles(filtered) deleteFilteredFiles(filtered, onDelete)
} }
} }
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) { private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
deleteFiles(filtered) { deleteFiles(filtered) { deleteSuccess ->
if (!it) { if (deleteSuccess) {
onDelete.invoke()
} else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return@deleteFiles return@deleteFiles
} }

View file

@ -475,10 +475,11 @@ class MediaAdapter(
} }
media.removeAll(removeMedia) media.removeAll(removeMedia)
listener?.tryDeleteFiles(fileDirItems) listener?.tryDeleteFiles(fileDirItems){
removeSelectedItems(positions)
currentMediaHash = media.hashCode()
}
listener?.updateMediaGridDecoration(media) listener?.updateMediaGridDecoration(media)
removeSelectedItems(positions)
currentMediaHash = media.hashCode()
} }
} }

View file

@ -245,7 +245,7 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(
fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean, fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean,
callback: ((wasSuccess: Boolean) -> Unit)? = null callback: ((wasSuccess: Boolean) -> Unit)? = null
) { ) {
deleteFile(fileDirItem, allowDeleteFolder) { deleteFile(fileDirItem, allowDeleteFolder, isDeletingMultipleFiles = false) {
if (deleteFromDatabase) { if (deleteFromDatabase) {
ensureBackgroundThread { ensureBackgroundThread {
deleteDBPath(fileDirItem.path) deleteDBPath(fileDirItem.path)

View file

@ -6,7 +6,7 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem
interface MediaOperationsListener { interface MediaOperationsListener {
fun refreshItems() fun refreshItems()
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit)
fun selectedPaths(paths: ArrayList<String>) fun selectedPaths(paths: ArrayList<String>)