pull/90/head^2
kunfei 5 years ago
parent 15cc07e7be
commit 3951bf01d1
  1. 3
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 7
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt
  3. 31
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -26,4 +26,7 @@ object PreferKey {
const val threadCount = "threadCount" const val threadCount = "threadCount"
const val keepLight = "keep_light" const val keepLight = "keep_light"
const val webService = "webService" const val webService = "webService"
const val webDavUrl = "web_dav_url"
const val webDavAccount = "web_dav_account"
const val webDavPassword = "web_dav_password"
} }

@ -2,6 +2,7 @@ package io.legado.app.help.storage
import android.content.Context import android.content.Context
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.lib.webdav.http.HttpAuth
@ -23,15 +24,15 @@ object WebDavHelp {
} }
private fun getWebDavUrl(): String? { 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.isNullOrBlank()) return null
if (!url.endsWith("/")) url += "/" if (!url.endsWith("/")) url += "/"
return url return url
} }
private fun initWebDav(): Boolean { private fun initWebDav(): Boolean {
val account = App.INSTANCE.getPrefString("web_dav_account") val account = App.INSTANCE.getPrefString(PreferKey.webDavAccount)
val password = App.INSTANCE.getPrefString("web_dav_password") val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword)
if (!account.isNullOrBlank() && !password.isNullOrBlank()) { if (!account.isNullOrBlank() && !password.isNullOrBlank()) {
HttpAuth.auth = HttpAuth.Auth(account, password) HttpAuth.auth = HttpAuth.Auth(account, password)
return true return true

@ -51,19 +51,19 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
} }
} }
addPreferencesFromResource(R.xml.pref_config_backup) addPreferencesFromResource(R.xml.pref_config_backup)
findPreference<EditTextPreference>("web_dav_url")?.let { findPreference<EditTextPreference>(PreferKey.webDavUrl)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) ATH.setTint(editText, requireContext().accentColor)
} }
bindPreferenceSummaryToValue(it) bindPreferenceSummaryToValue(it)
} }
findPreference<EditTextPreference>("web_dav_account")?.let { findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) ATH.setTint(editText, requireContext().accentColor)
} }
bindPreferenceSummaryToValue(it) bindPreferenceSummaryToValue(it)
} }
findPreference<EditTextPreference>("web_dav_password")?.let { findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor) ATH.setTint(editText, requireContext().accentColor)
editText.inputType = editText.inputType =
@ -85,28 +85,33 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
} }
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
when { when (preference?.key) {
preference?.key == "web_dav_password" -> if (newValue == null) { PreferKey.webDavUrl ->
preference.summary = getString(R.string.web_dav_pw_s) if (newValue == null) {
} else {
preference.summary = "*".repeat(newValue.toString().length)
}
preference?.key == "web_dav_url" -> if (newValue == null) {
preference.summary = getString(R.string.web_dav_url_s) preference.summary = getString(R.string.web_dav_url_s)
} else { } else {
preference.summary = newValue.toString() preference.summary = newValue.toString()
} }
preference?.key == "web_dav_account" -> if (newValue == null) { PreferKey.webDavAccount ->
if (newValue == null) {
preference.summary = getString(R.string.web_dav_account_s) preference.summary = getString(R.string.web_dav_account_s)
} else { } else {
preference.summary = newValue.toString() preference.summary = newValue.toString()
} }
preference is ListPreference -> { 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()) val index = preference.findIndexOfValue(newValue?.toString())
// Set the summary to reflect the new value. // Set the summary to reflect the new value.
preference.setSummary(if (index >= 0) preference.entries[index] else null) preference.setSummary(if (index >= 0) preference.entries[index] else null)
} else {
preference?.summary = newValue?.toString()
} }
else -> preference?.summary = newValue?.toString()
} }
return false return false
} }

Loading…
Cancel
Save