mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
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,37 +626,43 @@ class DirectoryAdapter(
|
|||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
var foldersToDelete = ArrayList<File>(selectedKeys.size)
|
||||
selectedDirs.forEach {
|
||||
if (it.areFavorites() || it.isRecycleBin()) {
|
||||
if (it.isRecycleBin()) {
|
||||
tryEmptyRecycleBin(false)
|
||||
activity.handleSAFDeleteSdk30Dialog(SAFPath){
|
||||
if (!it) {
|
||||
return@handleSAFDeleteSdk30Dialog
|
||||
}
|
||||
|
||||
var foldersToDelete = ArrayList<File>(selectedKeys.size)
|
||||
selectedDirs.forEach {
|
||||
if (it.areFavorites() || it.isRecycleBin()) {
|
||||
if (it.isRecycleBin()) {
|
||||
tryEmptyRecycleBin(false)
|
||||
} else {
|
||||
ensureBackgroundThread {
|
||||
activity.mediaDB.clearFavorites()
|
||||
activity.favoritesDB.clearFavorites()
|
||||
listener?.refreshItems()
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedKeys.size == 1) {
|
||||
finishActMode()
|
||||
}
|
||||
} else {
|
||||
ensureBackgroundThread {
|
||||
activity.mediaDB.clearFavorites()
|
||||
activity.favoritesDB.clearFavorites()
|
||||
listener?.refreshItems()
|
||||
foldersToDelete.add(File(it.path))
|
||||
}
|
||||
}
|
||||
|
||||
if (foldersToDelete.size == 1) {
|
||||
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
|
||||
if (success) {
|
||||
listener?.deleteFolders(foldersToDelete)
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedKeys.size == 1) {
|
||||
finishActMode()
|
||||
}
|
||||
} else {
|
||||
foldersToDelete.add(File(it.path))
|
||||
foldersToDelete = foldersToDelete.filter { !config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File>
|
||||
listener?.deleteFolders(foldersToDelete)
|
||||
}
|
||||
}
|
||||
|
||||
if (foldersToDelete.size == 1) {
|
||||
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
|
||||
if (success) {
|
||||
listener?.deleteFolders(foldersToDelete)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foldersToDelete = foldersToDelete.filter { !config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File>
|
||||
listener?.deleteFolders(foldersToDelete)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
|
||||
val removeMedia = ArrayList<Medium>(selectedKeys.size)
|
||||
val positions = getSelectedItemPositions()
|
||||
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
|
||||
activity.handleSAFDeleteSdk30Dialog(sdk30SafPath){
|
||||
if (!it) {
|
||||
return@handleSAFDeleteSdk30Dialog
|
||||
}
|
||||
|
||||
getSelectedItems().forEach {
|
||||
fileDirItems.add(FileDirItem(it.path, it.name))
|
||||
removeMedia.add(it)
|
||||
}
|
||||
val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
|
||||
val removeMedia = ArrayList<Medium>(selectedKeys.size)
|
||||
val positions = getSelectedItemPositions()
|
||||
|
||||
media.removeAll(removeMedia)
|
||||
listener?.tryDeleteFiles(fileDirItems){
|
||||
selectedItems.forEach {
|
||||
fileDirItems.add(FileDirItem(it.path, it.name))
|
||||
removeMedia.add(it)
|
||||
}
|
||||
|
||||
media.removeAll(removeMedia)
|
||||
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