From 88b13012aad88e2546109a20c9ad3477562aabf1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 2 Dec 2018 20:53:25 +0100 Subject: [PATCH] fix deleting Recycle Bin files --- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/activities/MediaActivity.kt | 4 ++-- .../simplemobiletools/gallery/pro/extensions/Activity.kt | 2 +- .../simplemobiletools/gallery/pro/extensions/Context.kt | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 58d81d31c..7d2c9fbd7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -847,7 +847,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { if (!curMedia.contains(it)) { val path = (it as? Medium)?.path if (path != null) { - mMediumDao.deleteMediumPath(path) + deleteDBPath(mMediumDao, path) } } } 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 c0edd6a93..791cabd78 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 @@ -884,8 +884,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { Thread { val useRecycleBin = config.useRecycleBin filtered.forEach { - if (!useRecycleBin) { - mMediumDao.deleteMediumPath(it.path) + if (it.path.startsWith(recycleBinPath) || !useRecycleBin) { + deleteDBPath(mMediumDao, it.path) } } }.start() 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 2244823a9..21cf823ce 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 @@ -193,7 +193,7 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet deleteFile(fileDirItem, allowDeleteFolder) { if (deleteFromDatabase) { Thread { - galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) + deleteDBPath(galleryDB.MediumDao(), fileDirItem.path) runOnUiThread { callback?.invoke(it) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index b4936f781..d7430f161 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -218,7 +218,7 @@ fun Context.rescanFolderMediaSync(path: String) { if (!newMedia.contains(it)) { val mediumPath = (it as? Medium)?.path if (mediumPath != null) { - mediumDao.deleteMediumPath(mediumPath) + deleteDBPath(mediumDao, mediumPath) } } } @@ -437,7 +437,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag val mediaToDelete = ArrayList() media.filter { !getDoesFilePathExist(it.path) }.forEach { if (it.path.startsWith(recycleBinPath)) { - mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath)) + deleteDBPath(mediumDao, it.path) } else { mediaToDelete.add(it) } @@ -478,3 +478,7 @@ fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { } return media } + +fun Context.deleteDBPath(mediumDao: MediumDao, path: String) { + mediumDao.deleteMediumPath(path.replaceFirst(recycleBinPath, RECYCLE_BIN)) +}