pull/34/head
kunfei 5 years ago
parent 01223ea0b1
commit 81c23b9379
  1. 23
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  2. 1
      app/src/main/res/values/strings.xml
  3. 4
      app/src/main/res/xml/pref_config_web_dav.xml

@ -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<ATEEditTextPreference>("web_dav_password")?.let {
it.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
bindPreferenceSummaryToValue(it)
}
}
@ -28,8 +31,15 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
}
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
val stringValue = newValue.toString()
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.
@ -38,6 +48,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
// 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)
}
}

@ -501,5 +501,6 @@
<string name="enable_selection">启用所选</string>
<string name="disable_selection">禁用所选</string>
<string name="tts">TTS</string>
<string name="web_dav_pw_s">输入你的WebDav授权密码</string>
</resources>

@ -17,11 +17,11 @@
<io.legado.app.lib.theme.prefs.ATEEditTextPreference
android:key="web_dav_password"
android:title="WebDav 密码"
android:summary="输入你的WebDav授权密码"
android:summary="@string/web_dav_pw_s"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="web_dav_restore"
android:key="web_dav_backup"
android:title="备份"
app:iconSpaceReserved="false" />

Loading…
Cancel
Save