Revert changes and handle recycler view animation with SDK-30 delete
This commit is contained in:
parent
bbcb41cf1f
commit
8af61d89bb
5 changed files with 64 additions and 53 deletions
|
@ -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
|
||||
if (filtered.isEmpty()) {
|
||||
return
|
||||
|
@ -867,7 +867,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
|
||||
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
|
||||
if (it) {
|
||||
deleteFilteredFiles(filtered, onDelete)
|
||||
deleteFilteredFiles(filtered)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
|
@ -875,17 +875,15 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
} else {
|
||||
val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size)
|
||||
toast(deletingItems)
|
||||
deleteFilteredFiles(filtered, onDelete)
|
||||
deleteFilteredFiles(filtered)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldSkipAuthentication() = intent.getBooleanExtra(SKIP_AUTHENTICATION, false)
|
||||
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
|
||||
deleteFiles(filtered) { deleteSuccess ->
|
||||
if (deleteSuccess) {
|
||||
onDelete.invoke()
|
||||
} else {
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) {
|
||||
deleteFiles(filtered) {
|
||||
if (!it) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return@deleteFiles
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ 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
|
||||
|
||||
|
@ -251,7 +252,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
|||
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
|
||||
if (filtered.isEmpty()) {
|
||||
return
|
||||
|
@ -263,7 +264,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
|||
|
||||
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
|
||||
if (it) {
|
||||
deleteFilteredFiles(filtered, onDelete)
|
||||
deleteFilteredFiles(filtered)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
|
@ -271,15 +272,13 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
|
|||
} else {
|
||||
val deletingItems = resources.getQuantityString(R.plurals.deleting_items, filtered.size, filtered.size)
|
||||
toast(deletingItems)
|
||||
deleteFilteredFiles(filtered, onDelete)
|
||||
deleteFilteredFiles(filtered)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>, onDelete: () -> Unit) {
|
||||
deleteFiles(filtered) { deleteSuccess ->
|
||||
if (deleteSuccess) {
|
||||
onDelete.invoke()
|
||||
} else {
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) {
|
||||
deleteFiles(filtered) {
|
||||
if (!it) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return@deleteFiles
|
||||
}
|
||||
|
|
|
@ -626,6 +626,11 @@ class DirectoryAdapter(
|
|||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
activity.handleSAFDeleteSdk30Dialog(SAFPath){
|
||||
if (!it) {
|
||||
return@handleSAFDeleteSdk30Dialog
|
||||
}
|
||||
|
||||
var foldersToDelete = ArrayList<File>(selectedKeys.size)
|
||||
selectedDirs.forEach {
|
||||
if (it.areFavorites() || it.isRecycleBin()) {
|
||||
|
@ -659,6 +664,7 @@ class DirectoryAdapter(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryChangeAlbumCover(useDefault: Boolean) {
|
||||
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
|
||||
|
|
|
@ -459,27 +459,35 @@ class MediaAdapter(
|
|||
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) {
|
||||
if (!it) {
|
||||
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 removeMedia = ArrayList<Medium>(selectedKeys.size)
|
||||
val positions = getSelectedItemPositions()
|
||||
|
||||
getSelectedItems().forEach {
|
||||
selectedItems.forEach {
|
||||
fileDirItems.add(FileDirItem(it.path, it.name))
|
||||
removeMedia.add(it)
|
||||
}
|
||||
|
||||
media.removeAll(removeMedia)
|
||||
listener?.tryDeleteFiles(fileDirItems){
|
||||
listener?.tryDeleteFiles(fileDirItems)
|
||||
listener?.updateMediaGridDecoration(media)
|
||||
removeSelectedItems(positions)
|
||||
currentMediaHash = media.hashCode()
|
||||
}
|
||||
listener?.updateMediaGridDecoration(media)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
|||
interface MediaOperationsListener {
|
||||
fun refreshItems()
|
||||
|
||||
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>, onDelete: () -> Unit)
|
||||
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>)
|
||||
|
||||
fun selectedPaths(paths: ArrayList<String>)
|
||||
|
||||
|
|
Loading…
Reference in a new issue