properly handle moving multiple items in the recycle bin too
This commit is contained in:
parent
87fde0f813
commit
721890ce67
|
@ -772,6 +772,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {
|
||||
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
|
||||
if (config.useRecycleBin) {
|
||||
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
|
||||
if (it) {
|
||||
deleteFilteredFiles(filtered)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deleteFilteredFiles(filtered)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteFilteredFiles(filtered: ArrayList<FileDirItem>) {
|
||||
deleteFiles(filtered) {
|
||||
if (!it) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
|
@ -782,8 +796,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
Thread {
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
val useRecycleBin = config.useRecycleBin
|
||||
filtered.forEach {
|
||||
mediumDao.deleteMediumPath(it.path)
|
||||
if (!useRecycleBin) {
|
||||
mediumDao.deleteMediumPath(it.path)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
|
||||
|
|
|
@ -838,19 +838,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun deleteConfirmed() {
|
||||
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return
|
||||
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||
if (config.useRecycleBin) {
|
||||
Thread {
|
||||
movePathInRecycleBin(path) {
|
||||
if (it) {
|
||||
galleryDB.MediumDao().updateDeleted(path, System.currentTimeMillis())
|
||||
movePathInRecycleBin(path) {
|
||||
if (it) {
|
||||
tryDeleteFileDirItem(fileDirItem, false, false) {
|
||||
refreshViewPager()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
} else {
|
||||
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||
tryDeleteFileDirItem(fileDirItem, false, true) {
|
||||
refreshViewPager()
|
||||
}
|
||||
|
|
|
@ -181,18 +181,23 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
|||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.movePathInRecycleBin(path: String, callback: (success: Boolean) -> Unit) {
|
||||
val file = File(path)
|
||||
val internalFile = File(filesDir, path)
|
||||
return try {
|
||||
file.copyRecursively(internalFile, true)
|
||||
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||
tryDeleteFileDirItem(fileDirItem, getIsPathDirectory(path), false) {
|
||||
Thread {
|
||||
callback(it)
|
||||
}.start()
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
callback(false)
|
||||
}
|
||||
fun BaseSimpleActivity.movePathInRecycleBin(path: String, callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||
movePathsInRecycleBin(arrayListOf(path), callback)
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||
Thread {
|
||||
var pathsCnt = paths.size
|
||||
paths.forEach {
|
||||
val file = File(it)
|
||||
val internalFile = File(filesDir, it)
|
||||
try {
|
||||
file.copyRecursively(internalFile, true)
|
||||
galleryDB.MediumDao().updateDeleted(it, System.currentTimeMillis())
|
||||
pathsCnt--
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
callback?.invoke(pathsCnt == 0)
|
||||
}.start()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue