remember last used copy destination on "Select destination" picker -> "Other folder"

This commit is contained in:
fatih ergin 2023-06-21 22:43:45 +03:00
parent b972770986
commit b84faf1763
3 changed files with 27 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.extensions.*
import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Directory
import kotlinx.android.synthetic.main.dialog_directory_picker.view.* import kotlinx.android.synthetic.main.dialog_directory_picker.view.*
import java.io.File
class PickDirectoryDialog( class PickDirectoryDialog(
val activity: BaseSimpleActivity, val activity: BaseSimpleActivity,
@ -38,7 +39,7 @@ class PickDirectoryDialog(
private var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID private var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID
private var showHidden = activity.config.shouldShowHidden private var showHidden = activity.config.shouldShowHidden
private var currentPathPrefix = "" private var currentPathPrefix = ""
private val config = view.context.config private val config = activity.config
private val searchView = view.folder_search_view private val searchView = view.folder_search_view
private val searchEditText = view.findViewById<EditText>(R.id.top_toolbar_search) private val searchEditText = view.findViewById<EditText>(R.id.top_toolbar_search)
private val searchViewAppBarLayout = view.findViewById<View>(R.id.top_app_bar_layout) private val searchViewAppBarLayout = view.findViewById<View>(R.id.top_app_bar_layout)
@ -169,7 +170,8 @@ class PickDirectoryDialog(
private fun showOtherFolder() { private fun showOtherFolder() {
activity.hideKeyboard(searchEditText) 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 -> activity.handleLockedFolderOpening(it) { success ->
if (success) { if (success) {
callback(it) 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<Directory>) { private fun gotDirectories(newDirs: ArrayList<Directory>) {
if (allDirectories.isEmpty()) { if (allDirectories.isEmpty()) {
allDirectories = newDirs.clone() as ArrayList<Directory> allDirectories = newDirs.clone() as ArrayList<Directory>

View file

@ -363,6 +363,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(LAST_FILEPICKER_PATH, "")!! get() = prefs.getString(LAST_FILEPICKER_PATH, "")!!
set(lastFilepickerPath) = prefs.edit().putString(LAST_FILEPICKER_PATH, lastFilepickerPath).apply() 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 var tempSkipDeleteConfirmation: Boolean
get() = prefs.getBoolean(TEMP_SKIP_DELETE_CONFIRMATION, false) get() = prefs.getBoolean(TEMP_SKIP_DELETE_CONFIRMATION, false)
set(tempSkipDeleteConfirmation) = prefs.edit().putBoolean(TEMP_SKIP_DELETE_CONFIRMATION, tempSkipDeleteConfirmation).apply() 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 ALLOW_INSTANT_CHANGE = "allow_instant_change"
const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock" const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock"
const val LAST_FILEPICKER_PATH = "last_filepicker_path" 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_DELETE_CONFIRMATION = "temp_skip_delete_confirmation"
const val TEMP_SKIP_RECYCLE_BIN = "temp_skip_recycle_bin" const val TEMP_SKIP_RECYCLE_BIN = "temp_skip_recycle_bin"
const val BOTTOM_ACTIONS = "bottom_actions" const val BOTTOM_ACTIONS = "bottom_actions"