From b84faf17632efd5f8dd363f6c981250636157adf Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Wed, 21 Jun 2023 22:43:45 +0300 Subject: [PATCH 1/3] 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" From 411c732fa805510bd460f786dba4b7ab59d5f929 Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Wed, 21 Jun 2023 23:56:35 +0300 Subject: [PATCH 2/3] remove useless function definition for copy path existency --- .../gallery/pro/dialogs/PickDirectoryDialog.kt | 6 +----- 1 file changed, 1 insertion(+), 5 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 2e2c9c910..d94bf155f 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 @@ -183,15 +183,11 @@ 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()) { + return if (activity.getDoesFilePathExist(lastCopyPath) && lastCopyPathVisible()) { lastCopyPath } else { sourcePath From ab6eb933948d1305d4374584064bd3eff0688e41 Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Thu, 22 Jun 2023 00:47:36 +0300 Subject: [PATCH 3/3] rename copy path getter method for common usage & simplify copy path checks --- .../pro/dialogs/PickDirectoryDialog.kt | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 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 d94bf155f..767457e75 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 @@ -170,7 +170,14 @@ class PickDirectoryDialog( private fun showOtherFolder() { activity.hideKeyboard(searchEditText) - FilePickerDialog(activity, getOtherFolderOpeningPath(), !isPickingCopyMoveDestination && !isPickingFolderForWidget, showHidden, true, true) { + FilePickerDialog( + activity, + getDefaultCopyDestinationPath(sourcePath), + !isPickingCopyMoveDestination && !isPickingFolderForWidget, + showHidden, + true, + true + ) { config.lastCopyPath = it activity.handleLockedFolderOpening(it) { success -> if (success) { @@ -180,17 +187,19 @@ class PickDirectoryDialog( } } - private fun getOtherFolderOpeningPath(): String { + private fun getDefaultCopyDestinationPath(currentPath: String): String { val lastCopyPath = config.lastCopyPath - val lastCopyPathVisible = { - showHidden || !lastCopyPath.split(File.separator).any { it.startsWith(".") && it.length > 1 } - } + return if (activity.getDoesFilePathExist(lastCopyPath)) { + val isLastCopyPathVisible = !lastCopyPath.split(File.separator).any { it.startsWith(".") && it.length > 1 } - return if (activity.getDoesFilePathExist(lastCopyPath) && lastCopyPathVisible()) { - lastCopyPath + if (showHidden || isLastCopyPathVisible) { + lastCopyPath + } else { + currentPath + } } else { - sourcePath + currentPath } }