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. 55
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.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"
}

@ -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

@ -51,19 +51,19 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
}
}
addPreferencesFromResource(R.xml.pref_config_backup)
findPreference<EditTextPreference>("web_dav_url")?.let {
findPreference<EditTextPreference>(PreferKey.webDavUrl)?.let {
it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor)
}
bindPreferenceSummaryToValue(it)
}
findPreference<EditTextPreference>("web_dav_account")?.let {
findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let {
it.setOnBindEditTextListener { editText ->
ATH.setTint(editText, requireContext().accentColor)
}
bindPreferenceSummaryToValue(it)
}
findPreference<EditTextPreference>("web_dav_password")?.let {
findPreference<EditTextPreference>(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
}

Loading…
Cancel
Save