From 3951bf01d1732b5a7f5f5d3a5f3c71996d27fd02 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:42:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 3 + .../io/legado/app/help/storage/WebDavHelp.kt | 7 ++- .../app/ui/config/BackupConfigFragment.kt | 55 ++++++++++--------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 1bfd5b634..f6a1b33ef 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -26,4 +26,7 @@ object PreferKey { const val threadCount = "threadCount" const val keepLight = "keep_light" const val webService = "webService" + const val webDavUrl = "web_dav_url" + const val webDavAccount = "web_dav_account" + const val webDavPassword = "web_dav_password" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index abd7a8a8a..7612a6913 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -2,6 +2,7 @@ package io.legado.app.help.storage import android.content.Context import io.legado.app.App +import io.legado.app.constant.PreferKey import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth @@ -23,15 +24,15 @@ object WebDavHelp { } private fun getWebDavUrl(): String? { - var url = App.INSTANCE.getPrefString("web_dav_url") + var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl) if (url.isNullOrBlank()) return null if (!url.endsWith("/")) url += "/" return url } private fun initWebDav(): Boolean { - val account = App.INSTANCE.getPrefString("web_dav_account") - val password = App.INSTANCE.getPrefString("web_dav_password") + val account = App.INSTANCE.getPrefString(PreferKey.webDavAccount) + val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword) if (!account.isNullOrBlank() && !password.isNullOrBlank()) { HttpAuth.auth = HttpAuth.Auth(account, password) return true diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index d10385945..e27f82e11 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -51,19 +51,19 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } } addPreferencesFromResource(R.xml.pref_config_backup) - findPreference("web_dav_url")?.let { + findPreference(PreferKey.webDavUrl)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } bindPreferenceSummaryToValue(it) } - findPreference("web_dav_account")?.let { + findPreference(PreferKey.webDavAccount)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } bindPreferenceSummaryToValue(it) } - findPreference("web_dav_password")?.let { + findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) editText.inputType = @@ -85,28 +85,33 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - when { - preference?.key == "web_dav_password" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_pw_s) - } else { - preference.summary = "*".repeat(newValue.toString().length) - } - preference?.key == "web_dav_url" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_url_s) - } else { - preference.summary = newValue.toString() - } - preference?.key == "web_dav_account" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_account_s) - } else { - preference.summary = newValue.toString() - } - preference is ListPreference -> { - val index = preference.findIndexOfValue(newValue?.toString()) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } - else -> preference?.summary = newValue?.toString() + when (preference?.key) { + PreferKey.webDavUrl -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_url_s) + } else { + preference.summary = newValue.toString() + } + PreferKey.webDavAccount -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_account_s) + } else { + preference.summary = newValue.toString() + } + PreferKey.webDavPassword -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_pw_s) + } else { + preference.summary = "*".repeat(newValue.toString().length) + } + else -> + if (preference is ListPreference) { + val index = preference.findIndexOfValue(newValue?.toString()) + // Set the summary to reflect the new value. + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } else { + preference?.summary = newValue?.toString() + } } return false }