From 81c23b9379ebc3aa50f5dec40e903e9040a8e1e9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 17 Sep 2019 11:19:16 +0800 Subject: [PATCH] up --- .../app/ui/config/WebDavConfigFragment.kt | 37 ++++++++++++++----- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_web_dav.xml | 4 +- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 909454885..bfc2ca0ef 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -7,6 +7,8 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.prefs.ATEEditTextPreference import io.legado.app.utils.getPrefString @@ -19,6 +21,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference bindPreferenceSummaryToValue(findPreference("web_dav_account")) findPreference("web_dav_password")?.let { it.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT + bindPreferenceSummaryToValue(it) } } @@ -28,15 +31,23 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - val stringValue = newValue.toString() - - if (preference is ListPreference) { - val index = preference.findIndexOfValue(stringValue) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } else { - // For all other preferences, set the summary to the value's - preference?.summary = stringValue + newValue?.let { + val stringValue = it.toString() + if (preference?.key == "web_dav_password") { + if (stringValue.isBlank()) { + preference.summary = getString(R.string.web_dav_pw_s) + } else { + preference.summary = "*".repeat(stringValue.length) + } + } + if (preference is ListPreference) { + val index = preference.findIndexOfValue(stringValue) + // Set the summary to reflect the new value. + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } else { + // For all other preferences, set the summary to the value's + preference?.summary = stringValue + } } return true } @@ -51,4 +62,12 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } } + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + when (preference?.key) { + "web_dav_backup" -> Backup.backup() + "web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) + } + return super.onPreferenceTreeClick(preference) + } + } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d482ba1f6..a66f806b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -501,5 +501,6 @@ 启用所选 禁用所选 TTS + 输入你的WebDav授权密码 diff --git a/app/src/main/res/xml/pref_config_web_dav.xml b/app/src/main/res/xml/pref_config_web_dav.xml index 3bf47eecf..c16768a20 100644 --- a/app/src/main/res/xml/pref_config_web_dav.xml +++ b/app/src/main/res/xml/pref_config_web_dav.xml @@ -17,11 +17,11 @@