pull/32/head
gedoor 6 years ago
parent 63310bc1e7
commit a2c5f0fce9
  1. 32
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt

@ -1,13 +1,43 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.os.Bundle import android.os.Bundle
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.getPrefString
class WebDavConfigFragment : PreferenceFragmentCompat() { class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_web_dav) addPreferencesFromResource(R.xml.pref_config_web_dav)
bindPreferenceSummaryToValue(findPreference<EditTextPreference>("web_dav_url"))
}
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
}
return true
}
private fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.let {
preference.onPreferenceChangeListener = this
onPreferenceChange(
preference,
preference.context.getPrefString(preference.key, "")
)
}
} }
} }
Loading…
Cancel
Save