mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
fix: show delete animation after file delete
This commit is contained in:
parent
5ae167c7d8
commit
bbcb41cf1f
5 changed files with 22 additions and 18 deletions
|
@ -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
|
||||
if (filtered.isEmpty()) {
|
||||
return
|
||||
|
@ -867,7 +867,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
|
||||
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
|
||||
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<FileDirItem>) {
|
||||
deleteFiles(filtered) {
|
||||
if (!it) {
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
|
||||
deleteFiles(filtered) { deleteSuccess ->
|
||||
if (deleteSuccess) {
|
||||
onDelete.invoke()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return@deleteFiles
|
||||
}
|
||||
|
|
|
@ -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<FileDirItem>) {
|
||||
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, 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<String>) {
|
||||
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<FileDirItem>) {
|
||||
deleteFiles(filtered) {
|
||||
if (!it) {
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
|
||||
deleteFiles(filtered) { deleteSuccess ->
|
||||
if (deleteSuccess) {
|
||||
onDelete.invoke()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return@deleteFiles
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
|||
interface MediaOperationsListener {
|
||||
fun refreshItems()
|
||||
|
||||
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>)
|
||||
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit)
|
||||
|
||||
fun selectedPaths(paths: ArrayList<String>)
|
||||
|
||||
|
|
Loading…
Reference in a new issue