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,22 +228,57 @@ 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 lastModified = file.lastModified()
|
||||
try {
|
||||
if (file.copyRecursively(internalFile, true)) {
|
||||
mediumDao.updateDeleted("$RECYCLE_BIN$it", System.currentTimeMillis(), it)
|
||||
pathsCnt--
|
||||
val OTGPath = config.OTGPath
|
||||
|
||||
if (config.keepLastModified) {
|
||||
internalFile.setLastModified(lastModified)
|
||||
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$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)
|
||||
|
|
Loading…
Reference in a new issue