From f852b69f6e7e8848fe81daf03e899c85d4e182be Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 14:45:50 +0200 Subject: [PATCH] allow permanent delete to items already in the recycle bin --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 4 ++-- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 3 ++- .../com/simplemobiletools/gallery/extensions/Activity.kt | 7 +++++-- .../kotlin/com/simplemobiletools/gallery/models/Medium.kt | 2 ++ 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08eda2400..137c3a2c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.4' + implementation 'com.simplemobiletools:commons:4.3.5' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 934b7263b..ae24492c6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -774,7 +774,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun tryDeleteFiles(fileDirItems: ArrayList) { val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList - if (config.useRecycleBin) { + if (config.useRecycleBin && !filtered.first().path.startsWith(filesDir.toString())) { movePathsInRecycleBin(filtered.map { it.path } as ArrayList) { if (it) { deleteFilteredFiles(filtered) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index b00879def..a7640970b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -833,7 +833,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - val message = if (config.useRecycleBin) R.string.are_you_sure_recycle_bin else R.string.are_you_sure_delete + val message = if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) R.string.are_you_sure_recycle_bin else R.string.are_you_sure_delete DeleteWithRememberDialog(this, getString(message)) { config.tempSkipDeleteConfirmation = it deleteConfirmed() @@ -843,7 +843,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { val path = getCurrentMedia().getOrNull(mPos)?.path ?: return val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) - if (config.useRecycleBin) { + if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { movePathInRecycleBin(path) { if (it) { tryDeleteFileDirItem(fileDirItem, false, false) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index c6e2decf5..438713baf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -279,7 +279,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, deleteFromDatabase: Boolean, callback: ((wasSuccess: Boolean) -> Unit)? = null) { deleteFile(fileDirItem, allowDeleteFolder) { - callback?.invoke(it) - if (deleteFromDatabase) { Thread { galleryDB.MediumDao().deleteMediumPath(fileDirItem.path) + runOnUiThread { + callback?.invoke(it) + } }.start() + } else { + callback?.invoke(it) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 1a7313d52..bc9eff1db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -59,6 +59,8 @@ data class Medium( } } + fun getIsInRecycleBin() = deletedTS != 0L + private fun getDayStartTS(ts: Long): String { val calendar = Calendar.getInstance(Locale.ENGLISH).apply { timeInMillis = ts