From 1c7fbc19ade7169f7b8175ae9ca6d2977e0fed0a Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Nov 2019 00:12:07 +0100 Subject: [PATCH] adding some OTG file recycle bin related improvements --- app/build.gradle | 2 +- .../gallery/pro/activities/MediaActivity.kt | 2 +- .../gallery/pro/extensions/Activity.kt | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9819a6131..9bad80a65 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.18.26' + implementation 'com.simplemobiletools:commons:5.18.27' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 365307e86..dc44ff967 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -891,7 +891,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } override fun tryDeleteFiles(fileDirItems: ArrayList) { - val filtered = fileDirItems.filter { File(it.path).isFile && it.path.isMediaFile() } as ArrayList + val filtered = fileDirItems.filter { !getIsPathDirectory(it.path) && it.path.isMediaFile() } as ArrayList if (filtered.isEmpty()) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 0f6db3a75..438487891 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -251,7 +251,7 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList, mediumDao out?.flush() - if (fileDocument?.getItemSize(false) == copiedSize && getDoesFilePathExist(destination)) { + if (fileDocument?.getItemSize(true) == copiedSize && getDoesFilePathExist(destination)) { mediumDao.updateDeleted("$RECYCLE_BIN$source", System.currentTimeMillis(), source) pathsCnt-- } @@ -306,8 +306,19 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList, mediumDa try { out = getFileOutputStreamSync(destination, source.getMimeType()) inputStream = getFileInputStreamSync(source) - inputStream!!.copyTo(out!!) - if (File(source).length() == File(destination).length()) { + + 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 (File(source).length() == copiedSize) { mediumDao.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination") } newPaths.add(destination)