Revert changes and handle recycler view animation with SDK-30 delete

This commit is contained in:
darthpaul 2022-02-24 16:27:33 +00:00
parent bbcb41cf1f
commit 8af61d89bb
5 changed files with 64 additions and 53 deletions

View file

@ -855,7 +855,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
} }
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {
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, onDelete) deleteFilteredFiles(filtered)
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
@ -875,17 +875,15 @@ 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, onDelete) deleteFilteredFiles(filtered)
} }
} }
private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false) private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false)
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) { private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) {
deleteFiles(filtered) { deleteSuccess -> deleteFiles(filtered) {
if (deleteSuccess) { if (!it) {
onDelete.invoke()
} else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return@deleteFiles return@deleteFiles
} }

View file

@ -25,6 +25,7 @@ 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
@ -251,7 +252,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
startAsyncTask(true) startAsyncTask(true)
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {
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
@ -263,7 +264,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, onDelete) deleteFilteredFiles(filtered)
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
@ -271,15 +272,13 @@ 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, onDelete) deleteFilteredFiles(filtered)
} }
} }
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) { private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) {
deleteFiles(filtered) { deleteSuccess -> deleteFiles(filtered) {
if (deleteSuccess) { if (!it) {
onDelete.invoke()
} else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return@deleteFiles return@deleteFiles
} }

View file

@ -626,6 +626,11 @@ class DirectoryAdapter(
return@handleSAFDialog return@handleSAFDialog
} }
activity.handleSAFDeleteSdk30Dialog(SAFPath){
if (!it) {
return@handleSAFDeleteSdk30Dialog
}
var foldersToDelete = ArrayList<File>(selectedKeys.size) var foldersToDelete = ArrayList<File>(selectedKeys.size)
selectedDirs.forEach { selectedDirs.forEach {
if (it.areFavorites() || it.isRecycleBin()) { if (it.areFavorites() || it.isRecycleBin()) {
@ -659,6 +664,7 @@ class DirectoryAdapter(
} }
} }
} }
}
private fun tryChangeAlbumCover(useDefault: Boolean) { private fun tryChangeAlbumCover(useDefault: Boolean) {
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success -> activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->

View file

@ -459,27 +459,35 @@ class MediaAdapter(
return return
} }
val SAFPath = getSelectedPaths().firstOrNull { activity.needsStupidWritePermissions(it) } ?: getFirstSelectedItemPath() ?: return val selectedItems = getSelectedItems()
val selectedPaths = selectedItems.map { it.path } as ArrayList<String>
val SAFPath = selectedPaths.firstOrNull { activity.needsStupidWritePermissions(it) } ?: getFirstSelectedItemPath() ?: return
activity.handleSAFDialog(SAFPath) { activity.handleSAFDialog(SAFPath) {
if (!it) { if (!it) {
return@handleSAFDialog return@handleSAFDialog
} }
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
activity.handleSAFDeleteSdk30Dialog(sdk30SafPath){
if (!it) {
return@handleSAFDeleteSdk30Dialog
}
val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size) val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
val removeMedia = ArrayList<Medium>(selectedKeys.size) val removeMedia = ArrayList<Medium>(selectedKeys.size)
val positions = getSelectedItemPositions() val positions = getSelectedItemPositions()
getSelectedItems().forEach { selectedItems.forEach {
fileDirItems.add(FileDirItem(it.path, it.name)) fileDirItems.add(FileDirItem(it.path, it.name))
removeMedia.add(it) removeMedia.add(it)
} }
media.removeAll(removeMedia) media.removeAll(removeMedia)
listener?.tryDeleteFiles(fileDirItems){ listener?.tryDeleteFiles(fileDirItems)
listener?.updateMediaGridDecoration(media)
removeSelectedItems(positions) removeSelectedItems(positions)
currentMediaHash = media.hashCode() currentMediaHash = media.hashCode()
} }
listener?.updateMediaGridDecoration(media)
} }
} }

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>, onDelete: () -> Unit) fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>)
fun selectedPaths(paths: ArrayList<String>) fun selectedPaths(paths: ArrayList<String>)