Merge pull request #2882 from fatihergin/feature/remember-last-used-copy-destination

remember last used copy destination on "Select destination" ->  "Other folder"
This commit is contained in:
Tibor Kaputa 2023-06-22 08:29:36 +02:00 committed by GitHub
commit e7c776b812
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View file

@ -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<EditText>(R.id.top_toolbar_search)
private val searchViewAppBarLayout = view.findViewById<View>(R.id.top_app_bar_layout)
@ -169,7 +170,15 @@ class PickDirectoryDialog(
private fun showOtherFolder() {
activity.hideKeyboard(searchEditText)
FilePickerDialog(activity, sourcePath, !isPickingCopyMoveDestination && !isPickingFolderForWidget, showHidden, true, true) {
FilePickerDialog(
activity,
getDefaultCopyDestinationPath(sourcePath),
!isPickingCopyMoveDestination && !isPickingFolderForWidget,
showHidden,
true,
true
) {
config.lastCopyPath = it
activity.handleLockedFolderOpening(it) { success ->
if (success) {
callback(it)
@ -178,6 +187,22 @@ class PickDirectoryDialog(
}
}
private fun getDefaultCopyDestinationPath(currentPath: String): String {
val lastCopyPath = config.lastCopyPath
return if (activity.getDoesFilePathExist(lastCopyPath)) {
val isLastCopyPathVisible = !lastCopyPath.split(File.separator).any { it.startsWith(".") && it.length > 1 }
if (showHidden || isLastCopyPathVisible) {
lastCopyPath
} else {
currentPath
}
} else {
currentPath
}
}
private fun gotDirectories(newDirs: ArrayList<Directory>) {
if (allDirectories.isEmpty()) {
allDirectories = newDirs.clone() as ArrayList<Directory>

View file

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

View file

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