From 8a79504e4be378d0eaa062086431619ea4d6cf0d Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Sun, 18 Jun 2023 02:22:31 +0300 Subject: [PATCH 1/2] allow skipping recycle bin at deletion --- .../gallery/pro/activities/MainActivity.kt | 9 +++++-- .../gallery/pro/activities/MediaActivity.kt | 6 +++-- .../gallery/pro/activities/SearchActivity.kt | 4 +-- .../pro/activities/ViewPagerActivity.kt | 25 +++++++++++-------- .../gallery/pro/adapters/DirectoryAdapter.kt | 2 +- .../gallery/pro/adapters/MediaAdapter.kt | 24 ++++++++++++------ .../pro/dialogs/DeleteWithRememberDialog.kt | 12 +++++++-- .../gallery/pro/helpers/Config.kt | 4 +++ .../gallery/pro/helpers/Constants.kt | 1 + .../pro/interfaces/MediaOperationsListener.kt | 2 +- .../layout/dialog_delete_with_remember.xml | 7 ++++++ 11 files changed, 67 insertions(+), 29 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 0bf1a864c..f1c9e9ff0 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 @@ -92,6 +92,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { config.temporarilyShowHidden = false config.temporarilyShowExcluded = false config.tempSkipDeleteConfirmation = false + config.tempSkipRecycleBin = false removeTempFolder() checkRecycleBinItems() startNewPhotoFetcher() @@ -270,6 +271,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { config.temporarilyShowHidden = false config.temporarilyShowExcluded = false config.tempSkipDeleteConfirmation = false + config.tempSkipRecycleBin = false }, SHOW_TEMP_HIDDEN_DURATION) } else { mTempShowHiddenHandler.removeCallbacksAndMessages(null) @@ -282,6 +284,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { config.temporarilyShowHidden = false config.temporarilyShowExcluded = false config.tempSkipDeleteConfirmation = false + config.tempSkipRecycleBin = false mTempShowHiddenHandler.removeCallbacksAndMessages(null) removeTempFolder() unregisterFileUpdateListener() @@ -319,6 +322,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true && intent.flags and Intent.FLAG_GRANT_WRITE_URI_PERMISSION != 0 -> { resultUri = fillExtraOutput(resultData) } + resultData.extras?.containsKey(PICKED_PATHS) == true -> fillPickedPaths(resultData, resultIntent) else -> fillIntentPath(resultData, resultIntent) } @@ -645,8 +649,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { showErrorToast(e) } } + else -> { - val baseString = if (config.useRecycleBin) R.plurals.moving_items_into_bin else R.plurals.delete_items + val baseString = if (config.useRecycleBin && !config.tempSkipRecycleBin) R.plurals.moving_items_into_bin else R.plurals.delete_items val deletingItems = resources.getQuantityString(baseString, fileDirItems.size, fileDirItems.size) toast(deletingItems) } @@ -667,7 +672,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { }?.mapTo(itemsToDelete) { it.toFileDirItem(applicationContext) } } - if (config.useRecycleBin) { + if (config.useRecycleBin && !config.tempSkipRecycleBin) { val pathsToDelete = ArrayList() itemsToDelete.mapTo(pathsToDelete) { it.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 fcc05d536..9738a8bfd 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 @@ -208,6 +208,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { mTempShowHiddenHandler.postDelayed({ config.temporarilyShowHidden = false config.tempSkipDeleteConfirmation = false + config.tempSkipRecycleBin = false }, SHOW_TEMP_HIDDEN_DURATION) } else { mTempShowHiddenHandler.removeCallbacksAndMessages(null) @@ -219,6 +220,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { if (config.showAll && !isChangingConfigurations) { config.temporarilyShowHidden = false config.tempSkipDeleteConfirmation = false + config.tempSkipRecycleBin = false unregisterFileUpdateListener() GalleryDatabase.destroyInstance() } @@ -885,13 +887,13 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } } - override fun tryDeleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList, skipRecycleBin: Boolean) { val filtered = fileDirItems.filter { !getIsPathDirectory(it.path) && it.path.isMediaFile() } as ArrayList if (filtered.isEmpty()) { return } - if (config.useRecycleBin && !filtered.first().path.startsWith(recycleBinPath)) { + if (config.useRecycleBin && !skipRecycleBin && !filtered.first().path.startsWith(recycleBinPath)) { val movingItems = resources.getQuantityString(R.plurals.moving_items_into_bin, filtered.size, filtered.size) toast(movingItems) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt index 00e58e819..91fdea955 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt @@ -237,13 +237,13 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener { startAsyncTask(true) } - override fun tryDeleteFiles(fileDirItems: ArrayList) { + override fun tryDeleteFiles(fileDirItems: ArrayList, skipRecycleBin: Boolean) { val filtered = fileDirItems.filter { File(it.path).isFile && it.path.isMediaFile() } as ArrayList if (filtered.isEmpty()) { return } - if (config.useRecycleBin && !filtered.first().path.startsWith(recycleBinPath)) { + if (config.useRecycleBin && !skipRecycleBin && !filtered.first().path.startsWith(recycleBinPath)) { val movingItems = resources.getQuantityString(R.plurals.moving_items_into_bin, filtered.size, filtered.size) toast(movingItems) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 64365f414..747757778 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.gallery.pro.activities import android.animation.Animator import android.animation.ValueAnimator import android.annotation.SuppressLint -import android.annotation.TargetApi import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent @@ -16,7 +15,6 @@ import android.graphics.Bitmap import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Icon -import android.os.Build import android.os.Bundle import android.os.Handler import android.provider.MediaStore.Images @@ -58,7 +56,6 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem import kotlinx.android.synthetic.main.activity_medium.* import kotlinx.android.synthetic.main.bottom_actions.* import java.io.File -import java.io.OutputStream import kotlin.math.min @Suppress("UNCHECKED_CAST") @@ -1058,10 +1055,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View handleMediaManagementPrompt { if (config.isDeletePasswordProtectionOn) { handleDeletePasswordProtection { - deleteConfirmed() + deleteConfirmed(config.tempSkipRecycleBin) } } else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) { - deleteConfirmed() + deleteConfirmed(config.tempSkipRecycleBin) } else { askConfirmDelete() } @@ -1074,20 +1071,26 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val filename = "\"${getCurrentPath().getFilenameFromPath()}\"" val filenameAndSize = "$filename ($size)" - val baseString = if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { + val baseString = if (config.useRecycleBin && !config.tempSkipRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { R.string.move_to_recycle_bin_confirmation } else { R.string.deletion_confirmation } val message = String.format(resources.getString(baseString), filenameAndSize) - DeleteWithRememberDialog(this, message) { - config.tempSkipDeleteConfirmation = it - deleteConfirmed() + val callback = fun(remember: Boolean, skipRecycleBin: Boolean) { + config.tempSkipDeleteConfirmation = remember + + if (remember) { + config.tempSkipRecycleBin = skipRecycleBin + } + + deleteConfirmed(skipRecycleBin) } + DeleteWithRememberDialog(this, message, config.useRecycleBin, callback) } - private fun deleteConfirmed() { + private fun deleteConfirmed(skipRecycleBin: Boolean) { val currentMedium = getCurrentMedium() val path = currentMedium?.path ?: return if (getIsPathDirectory(path) || !path.isMediaFile()) { @@ -1095,7 +1098,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } val fileDirItem = currentMedium.toFileDirItem() - if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { + if (config.useRecycleBin && !skipRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) { if (!it) { return@checkManageMediaOrHandleSAFDialogSdk30 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 0e727f854..dab4b2eab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -601,7 +601,7 @@ class DirectoryAdapter( } val fileDirItem = getFirstSelectedItem() ?: return - val baseString = if (!config.useRecycleBin || (isOneItemSelected() && fileDirItem.areFavorites())) { + val baseString = if (!config.useRecycleBin || config.tempSkipRecycleBin || (isOneItemSelected() && fileDirItem.areFavorites())) { R.string.deletion_confirmation } else { R.string.move_to_recycle_bin_confirmation diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index a19d09394..7b6a86fd5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -474,10 +474,10 @@ class MediaAdapter( activity.handleMediaManagementPrompt { if (config.isDeletePasswordProtectionOn) { activity.handleDeletePasswordProtection { - deleteFiles() + deleteFiles(config.tempSkipRecycleBin) } } else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) { - deleteFiles() + deleteFiles(config.tempSkipRecycleBin) } else { askConfirmDelete() } @@ -505,15 +505,23 @@ class MediaAdapter( } val isRecycleBin = firstPath.startsWith(activity.recycleBinPath) - val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation + val baseString = + if (config.useRecycleBin && !config.tempSkipRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation val question = String.format(resources.getString(baseString), itemsAndSize) - DeleteWithRememberDialog(activity, question) { - config.tempSkipDeleteConfirmation = it - deleteFiles() + + val callback = fun(remember: Boolean, skipRecycleBin: Boolean) { + config.tempSkipDeleteConfirmation = remember + + if (remember) { + config.tempSkipRecycleBin = skipRecycleBin + } + + deleteFiles(skipRecycleBin) } + DeleteWithRememberDialog(activity, question, config.useRecycleBin, callback) } - private fun deleteFiles() { + private fun deleteFiles(skipRecycleBin: Boolean) { if (selectedKeys.isEmpty()) { return } @@ -542,7 +550,7 @@ class MediaAdapter( } media.removeAll(removeMedia) - listener?.tryDeleteFiles(fileDirItems) + listener?.tryDeleteFiles(fileDirItems, skipRecycleBin) listener?.updateMediaGridDecoration(media) removeSelectedItems(positions) currentMediaHash = media.hashCode() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt index db401b0e2..8229668d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/DeleteWithRememberDialog.kt @@ -2,17 +2,25 @@ package com.simplemobiletools.gallery.pro.dialogs import android.app.Activity import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.extensions.beGoneIf import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import kotlinx.android.synthetic.main.dialog_delete_with_remember.view.* -class DeleteWithRememberDialog(val activity: Activity, val message: String, val callback: (remember: Boolean) -> Unit) { +class DeleteWithRememberDialog( + private val activity: Activity, + private val message: String, + private val showSkipRecycleBinOption: Boolean, + private val callback: (remember: Boolean, skipRecycleBin: Boolean) -> Unit +) { + private var dialog: AlertDialog? = null val view = activity.layoutInflater.inflate(R.layout.dialog_delete_with_remember, null)!! init { view.delete_remember_title.text = message + view.skip_the_recycle_bin_checkbox.beGoneIf(!showSkipRecycleBinOption) activity.getAlertDialogBuilder() .setPositiveButton(R.string.yes) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.no, null) @@ -25,6 +33,6 @@ class DeleteWithRememberDialog(val activity: Activity, val message: String, val private fun dialogConfirmed() { dialog?.dismiss() - callback(view.delete_remember_checkbox.isChecked) + callback(view.delete_remember_checkbox.isChecked, view.skip_the_recycle_bin_checkbox.isChecked) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index caacf636f..9d0aa9fa3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -367,6 +367,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(TEMP_SKIP_DELETE_CONFIRMATION, false) set(tempSkipDeleteConfirmation) = prefs.edit().putBoolean(TEMP_SKIP_DELETE_CONFIRMATION, tempSkipDeleteConfirmation).apply() + var tempSkipRecycleBin: Boolean + get() = prefs.getBoolean(TEMP_SKIP_RECYCLE_BIN, false) + set(tempSkipRecycleBin) = prefs.edit().putBoolean(TEMP_SKIP_RECYCLE_BIN, tempSkipRecycleBin).apply() + var wereFavoritesPinned: Boolean get() = prefs.getBoolean(WERE_FAVORITES_PINNED, false) set(wereFavoritesPinned) = prefs.edit().putBoolean(WERE_FAVORITES_PINNED, wereFavoritesPinned).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 767c0cad1..1f026dca1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -57,6 +57,7 @@ const val ALLOW_INSTANT_CHANGE = "allow_instant_change" const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock" const val LAST_FILEPICKER_PATH = "last_filepicker_path" const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation" +const val TEMP_SKIP_RECYCLE_BIN = "temp_skip_recycle_bin" const val BOTTOM_ACTIONS = "bottom_actions" const val LAST_VIDEO_POSITION_PREFIX = "last_video_position_" const val VISIBLE_BOTTOM_ACTIONS = "visible_bottom_actions" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt index 997adc44f..26a61b0aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediaOperationsListener.kt @@ -6,7 +6,7 @@ import com.simplemobiletools.gallery.pro.models.ThumbnailItem interface MediaOperationsListener { fun refreshItems() - fun tryDeleteFiles(fileDirItems: ArrayList) + fun tryDeleteFiles(fileDirItems: ArrayList, skipRecycleBin: Boolean) fun selectedPaths(paths: ArrayList) diff --git a/app/src/main/res/layout/dialog_delete_with_remember.xml b/app/src/main/res/layout/dialog_delete_with_remember.xml index ffb6890a2..24902b3d5 100644 --- a/app/src/main/res/layout/dialog_delete_with_remember.xml +++ b/app/src/main/res/layout/dialog_delete_with_remember.xml @@ -23,4 +23,11 @@ android:layout_below="@+id/delete_remember_title" android:text="@string/do_not_ask_again" /> + + From 116359c0c64ea84188aea211991149b905063601 Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Sun, 18 Jun 2023 13:08:01 +0300 Subject: [PATCH 2/2] move last callback param of DeleteWithRememberDialog out of the parentheses for better readability --- .../gallery/pro/activities/ViewPagerActivity.kt | 3 +-- .../com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 747757778..585fe2df2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1078,7 +1078,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } val message = String.format(resources.getString(baseString), filenameAndSize) - val callback = fun(remember: Boolean, skipRecycleBin: Boolean) { + DeleteWithRememberDialog(this, message, config.useRecycleBin) { remember, skipRecycleBin -> config.tempSkipDeleteConfirmation = remember if (remember) { @@ -1087,7 +1087,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View deleteConfirmed(skipRecycleBin) } - DeleteWithRememberDialog(this, message, config.useRecycleBin, callback) } private fun deleteConfirmed(skipRecycleBin: Boolean) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 7b6a86fd5..13bf88b8a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -509,7 +509,7 @@ class MediaAdapter( if (config.useRecycleBin && !config.tempSkipRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation val question = String.format(resources.getString(baseString), itemsAndSize) - val callback = fun(remember: Boolean, skipRecycleBin: Boolean) { + DeleteWithRememberDialog(activity, question, config.useRecycleBin) { remember, skipRecycleBin -> config.tempSkipDeleteConfirmation = remember if (remember) { @@ -518,7 +518,6 @@ class MediaAdapter( deleteFiles(skipRecycleBin) } - DeleteWithRememberDialog(activity, question, config.useRecycleBin, callback) } private fun deleteFiles(skipRecycleBin: Boolean) {