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..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 @@ -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,25 @@ 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() + DeleteWithRememberDialog(this, message, config.useRecycleBin) { remember, skipRecycleBin -> + config.tempSkipDeleteConfirmation = remember + + if (remember) { + config.tempSkipRecycleBin = skipRecycleBin + } + + deleteConfirmed(skipRecycleBin) } } - private fun deleteConfirmed() { + private fun deleteConfirmed(skipRecycleBin: Boolean) { val currentMedium = getCurrentMedium() val path = currentMedium?.path ?: return if (getIsPathDirectory(path) || !path.isMediaFile()) { @@ -1095,7 +1097,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..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 @@ -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,22 @@ 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() + + DeleteWithRememberDialog(activity, question, config.useRecycleBin) { remember, skipRecycleBin -> + config.tempSkipDeleteConfirmation = remember + + if (remember) { + config.tempSkipRecycleBin = skipRecycleBin + } + + deleteFiles(skipRecycleBin) } } - private fun deleteFiles() { + private fun deleteFiles(skipRecycleBin: Boolean) { if (selectedKeys.isEmpty()) { return } @@ -542,7 +549,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" /> + +