remember the last used path at exporting settings

This commit is contained in:
tibbi 2019-12-03 23:52:22 +01:00
parent dfba507808
commit 32610d50b0
5 changed files with 27 additions and 3 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.20.4'
propVersionName = '5.20.6'
kotlin_version = '1.3.61'
}

View file

@ -468,9 +468,15 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
}
}
fun exportSettings(configItems: LinkedHashMap<String, Any>, defaultFilename: String) {
fun exportSettings(configItems: LinkedHashMap<String, Any>) {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
var defaultFilename = baseConfig.lastExportedSettingsFile
if (defaultFilename.isEmpty()) {
val appName = baseConfig.appId.removeSuffix(".debug").removeSuffix(".pro").removePrefix("com.simplemobiletools.")
defaultFilename = "$appName-settings.txt"
}
ExportSettingsDialog(this, defaultFilename) {
val file = File(it)
val fileDirItem = FileDirItem(file.absolutePath, file.name)

View file

@ -8,7 +8,13 @@ import kotlinx.android.synthetic.main.dialog_export_settings.view.*
class ExportSettingsDialog(val activity: BaseSimpleActivity, val defaultFilename: String, callback: (path: String) -> Unit) {
init {
var folder = activity.internalStoragePath
val lastUsedFolder = activity.baseConfig.lastExportedSettingsFolder
var folder = if (lastUsedFolder.isNotEmpty() && activity.getDoesFilePathExist(lastUsedFolder)) {
lastUsedFolder
} else {
activity.internalStoragePath
}
val view = activity.layoutInflater.inflate(R.layout.dialog_export_settings, null).apply {
export_settings_filename.setText(defaultFilename)
export_settings_path.text = activity.humanizePath(folder)
@ -32,12 +38,14 @@ class ExportSettingsDialog(val activity: BaseSimpleActivity, val defaultFilename
return@setOnClickListener
}
activity.baseConfig.lastExportedSettingsFile = filename
val newPath = "${folder.trimEnd('/')}/$filename"
if (!newPath.getFilenameFromPath().isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
activity.baseConfig.lastExportedSettingsFolder = folder
if (activity.getDoesFilePathExist(newPath)) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newPath.getFilenameFromPath())
ConfirmationDialog(activity, title) {

View file

@ -359,4 +359,12 @@ open class BaseConfig(val context: Context) {
var lastRenamePatternUsed: String
get() = prefs.getString(LAST_RENAME_PATTERN_USED, "")!!
set(lastRenamePatternUsed) = prefs.edit().putString(LAST_RENAME_PATTERN_USED, lastRenamePatternUsed).apply()
var lastExportedSettingsFolder: String
get() = prefs.getString(LAST_EXPORTED_SETTINGS_FOLDER, "")!!
set(lastExportedSettingsFolder) = prefs.edit().putString(LAST_EXPORTED_SETTINGS_FOLDER, lastExportedSettingsFolder).apply()
var lastExportedSettingsFile: String
get() = prefs.getString(LAST_EXPORTED_SETTINGS_FILE, "")!!
set(lastExportedSettingsFile) = prefs.edit().putString(LAST_EXPORTED_SETTINGS_FILE, lastExportedSettingsFile).apply()
}

View file

@ -120,6 +120,8 @@ const val WAS_SORTING_BY_NUMERIC_VALUE_ADDED = "was_sorting_by_numeric_value_add
const val WAS_FOLDER_LOCKING_NOTICE_SHOWN = "was_folder_locking_notice_shown"
const val LAST_RENAME_USED = "last_rename_used"
const val LAST_RENAME_PATTERN_USED = "last_rename_pattern_used"
const val LAST_EXPORTED_SETTINGS_FOLDER = "last_exported_settings_folder"
const val LAST_EXPORTED_SETTINGS_FILE = "last_exported_settings_file"
// licenses
internal const val LICENSE_KOTLIN = 1