From b84faf17632efd5f8dd363f6c981250636157adf Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Wed, 21 Jun 2023 22:43:45 +0300 Subject: [PATCH] remember last used copy destination on "Select destination" picker -> "Other folder" --- .../pro/dialogs/PickDirectoryDialog.kt | 24 +++++++++++++++++-- .../gallery/pro/helpers/Config.kt | 4 ++++ .../gallery/pro/helpers/Constants.kt | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt index b5d5690f0..2e2c9c910 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/PickDirectoryDialog.kt @@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.pro.adapters.DirectoryAdapter import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.models.Directory import kotlinx.android.synthetic.main.dialog_directory_picker.view.* +import java.io.File class PickDirectoryDialog( val activity: BaseSimpleActivity, @@ -38,7 +39,7 @@ class PickDirectoryDialog( private var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID private var showHidden = activity.config.shouldShowHidden private var currentPathPrefix = "" - private val config = view.context.config + private val config = activity.config private val searchView = view.folder_search_view private val searchEditText = view.findViewById(R.id.top_toolbar_search) private val searchViewAppBarLayout = view.findViewById(R.id.top_app_bar_layout) @@ -169,7 +170,8 @@ class PickDirectoryDialog( private fun showOtherFolder() { activity.hideKeyboard(searchEditText) - FilePickerDialog(activity, sourcePath, !isPickingCopyMoveDestination && !isPickingFolderForWidget, showHidden, true, true) { + FilePickerDialog(activity, getOtherFolderOpeningPath(), !isPickingCopyMoveDestination && !isPickingFolderForWidget, showHidden, true, true) { + config.lastCopyPath = it activity.handleLockedFolderOpening(it) { success -> if (success) { callback(it) @@ -178,6 +180,24 @@ class PickDirectoryDialog( } } + private fun getOtherFolderOpeningPath(): String { + val lastCopyPath = config.lastCopyPath + + val lastCopyPathExist = { + activity.getDoesFilePathExist(lastCopyPath) + } + + val lastCopyPathVisible = { + showHidden || !lastCopyPath.split(File.separator).any { it.startsWith(".") && it.length > 1 } + } + + return if (lastCopyPathExist() && lastCopyPathVisible()) { + lastCopyPath + } else { + sourcePath + } + } + private fun gotDirectories(newDirs: ArrayList) { if (allDirectories.isEmpty()) { allDirectories = newDirs.clone() as ArrayList 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 9d0aa9fa3..7cd88caac 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 @@ -363,6 +363,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getString(LAST_FILEPICKER_PATH, "")!! set(lastFilepickerPath) = prefs.edit().putString(LAST_FILEPICKER_PATH, lastFilepickerPath).apply() + var lastCopyPath: String + get() = prefs.getString(LAST_COPY_PATH, "")!! + set(lastCopyPath) = prefs.edit().putString(LAST_COPY_PATH, lastCopyPath).apply() + var tempSkipDeleteConfirmation: Boolean get() = prefs.getBoolean(TEMP_SKIP_DELETE_CONFIRMATION, false) set(tempSkipDeleteConfirmation) = prefs.edit().putBoolean(TEMP_SKIP_DELETE_CONFIRMATION, tempSkipDeleteConfirmation).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 1f026dca1..f3a96c39a 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 @@ -56,6 +56,7 @@ const val HIDE_EXTENDED_DETAILS = "hide_extended_details" 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 LAST_COPY_PATH = "last_copy_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"