allow permanent delete to items already in the recycle bin

This commit is contained in:
tibbi 2018-06-27 14:45:50 +02:00
parent 11fde4daa0
commit f852b69f6e
6 changed files with 13 additions and 7 deletions

View File

@ -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'

View File

@ -774,7 +774,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {
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<String>) {
if (it) {
deleteFilteredFiles(filtered)

View File

@ -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) {

View File

@ -279,7 +279,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private fun askConfirmDelete() {
val items = resources.getQuantityString(R.plurals.delete_items, selectedPositions.size, selectedPositions.size)
val baseString = if (config.useRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation
val isRecycleBin = getSelectedPaths().first().startsWith(activity.filesDir.toString())
val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation
val question = String.format(resources.getString(baseString), items)
DeleteWithRememberDialog(activity, question) {
config.tempSkipDeleteConfirmation = it

View File

@ -171,12 +171,15 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList<FileDirItem>,
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)
}
}
}

View File

@ -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