mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +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
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -626,37 +626,43 @@ class DirectoryAdapter(
|
||||||
return@handleSAFDialog
|
return@handleSAFDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
var foldersToDelete = ArrayList<File>(selectedKeys.size)
|
activity.handleSAFDeleteSdk30Dialog(SAFPath){
|
||||||
selectedDirs.forEach {
|
if (!it) {
|
||||||
if (it.areFavorites() || it.isRecycleBin()) {
|
return@handleSAFDeleteSdk30Dialog
|
||||||
if (it.isRecycleBin()) {
|
}
|
||||||
tryEmptyRecycleBin(false)
|
|
||||||
|
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 {
|
} else {
|
||||||
ensureBackgroundThread {
|
foldersToDelete.add(File(it.path))
|
||||||
activity.mediaDB.clearFavorites()
|
}
|
||||||
activity.favoritesDB.clearFavorites()
|
}
|
||||||
listener?.refreshItems()
|
|
||||||
|
if (foldersToDelete.size == 1) {
|
||||||
|
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
|
||||||
|
if (success) {
|
||||||
|
listener?.deleteFolders(foldersToDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedKeys.size == 1) {
|
|
||||||
finishActMode()
|
|
||||||
}
|
|
||||||
} else {
|
} 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
|
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 fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
|
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
|
||||||
val removeMedia = ArrayList<Medium>(selectedKeys.size)
|
activity.handleSAFDeleteSdk30Dialog(sdk30SafPath){
|
||||||
val positions = getSelectedItemPositions()
|
if (!it) {
|
||||||
|
return@handleSAFDeleteSdk30Dialog
|
||||||
|
}
|
||||||
|
|
||||||
getSelectedItems().forEach {
|
val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
|
||||||
fileDirItems.add(FileDirItem(it.path, it.name))
|
val removeMedia = ArrayList<Medium>(selectedKeys.size)
|
||||||
removeMedia.add(it)
|
val positions = getSelectedItemPositions()
|
||||||
}
|
|
||||||
|
|
||||||
media.removeAll(removeMedia)
|
selectedItems.forEach {
|
||||||
listener?.tryDeleteFiles(fileDirItems){
|
fileDirItems.add(FileDirItem(it.path, it.name))
|
||||||
|
removeMedia.add(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
media.removeAll(removeMedia)
|
||||||
|
listener?.tryDeleteFiles(fileDirItems)
|
||||||
|
listener?.updateMediaGridDecoration(media)
|
||||||
removeSelectedItems(positions)
|
removeSelectedItems(positions)
|
||||||
currentMediaHash = media.hashCode()
|
currentMediaHash = media.hashCode()
|
||||||
}
|
}
|
||||||
listener?.updateMediaGridDecoration(media)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue