mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57: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() {
|
private fun deleteConfirmed() {
|
||||||
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return
|
val path = getCurrentMedia().getOrNull(mPos)?.path ?: return
|
||||||
if (File(path).isDirectory || !path.isMediaFile()) {
|
if (getIsPathDirectory(path) || !path.isMediaFile()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,22 +228,57 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
||||||
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
var pathsCnt = paths.size
|
var pathsCnt = paths.size
|
||||||
paths.forEach {
|
val OTGPath = config.OTGPath
|
||||||
val file = File(it)
|
|
||||||
val internalFile = File(recycleBinPath, it)
|
|
||||||
val lastModified = file.lastModified()
|
|
||||||
try {
|
|
||||||
if (file.copyRecursively(internalFile, true)) {
|
|
||||||
mediumDao.updateDeleted("$RECYCLE_BIN$it", System.currentTimeMillis(), it)
|
|
||||||
pathsCnt--
|
|
||||||
|
|
||||||
if (config.keepLastModified) {
|
for (source in paths) {
|
||||||
internalFile.setLastModified(lastModified)
|
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$source", System.currentTimeMillis(), source)
|
||||||
|
pathsCnt--
|
||||||
|
|
||||||
|
if (config.keepLastModified) {
|
||||||
|
internalFile.setLastModified(lastModified)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
|
return@ensureBackgroundThread
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
showErrorToast(e)
|
|
||||||
return@forEach
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback?.invoke(pathsCnt == 0)
|
callback?.invoke(pathsCnt == 0)
|
||||||
|
|
Loading…
Reference in a new issue