mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
fix moving OTG files in the recycle bin
This commit is contained in:
parent
556a775848
commit
04ecb6e0b4
2 changed files with 49 additions and 14 deletions
|
@ -945,7 +945,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun deleteConfirmed() {
|
||||
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return
|
||||
if (File(path).isDirectory || !path.isMediaFile()) {
|
||||
if (getIsPathDirectory(path) || !path.isMediaFile()) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -228,13 +228,47 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
|||
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||
ensureBackgroundThread {
|
||||
var pathsCnt = paths.size
|
||||
paths.forEach {
|
||||
val file = File(it)
|
||||
val internalFile = File(recycleBinPath, it)
|
||||
val OTGPath = config.OTGPath
|
||||
|
||||
for (source in paths) {
|
||||
if (OTGPath.isNotEmpty() && source.startsWith(OTGPath)) {
|
||||
var inputStream: InputStream? = null
|
||||
var out: OutputStream? = null
|
||||
try {
|
||||
val destination = "$recycleBinPath/$source"
|
||||
val fileDocument = getSomeDocumentFile(source)
|
||||
inputStream = applicationContext.contentResolver.openInputStream(fileDocument?.uri)
|
||||
out = getFileOutputStreamSync(destination, source.getMimeType())
|
||||
|
||||
var copiedSize = 0L
|
||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var bytes = inputStream.read(buffer)
|
||||
while (bytes >= 0) {
|
||||
out!!.write(buffer, 0, bytes)
|
||||
copiedSize += bytes
|
||||
bytes = inputStream.read(buffer)
|
||||
}
|
||||
|
||||
out?.flush()
|
||||
|
||||
if (fileDocument?.getItemSize(false) == copiedSize && getDoesFilePathExist(destination)) {
|
||||
mediumDao.updateDeleted("$RECYCLE_BIN$source", System.currentTimeMillis(), source)
|
||||
pathsCnt--
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
return@ensureBackgroundThread
|
||||
} finally {
|
||||
inputStream?.close()
|
||||
out?.close()
|
||||
}
|
||||
} else {
|
||||
val file = File(source)
|
||||
val internalFile = File(recycleBinPath, source)
|
||||
val lastModified = file.lastModified()
|
||||
try {
|
||||
if (file.copyRecursively(internalFile, true)) {
|
||||
mediumDao.updateDeleted("$RECYCLE_BIN$it", System.currentTimeMillis(), it)
|
||||
mediumDao.updateDeleted("$RECYCLE_BIN$source", System.currentTimeMillis(), source)
|
||||
pathsCnt--
|
||||
|
||||
if (config.keepLastModified) {
|
||||
|
@ -243,7 +277,8 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao
|
|||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
return@forEach
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
}
|
||||
}
|
||||
callback?.invoke(pathsCnt == 0)
|
||||
|
|
Loading…
Reference in a new issue