From a2c5f0fce99c52fb0ca49c6d9c68dbfed61c0351 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Jun 2019 13:15:19 +0800 Subject: [PATCH] up --- .../app/ui/config/WebDavConfigFragment.kt | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index d933ea16d..01138e54f 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,13 +1,43 @@ package io.legado.app.ui.config import android.os.Bundle +import androidx.preference.EditTextPreference +import androidx.preference.ListPreference +import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat 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?) { addPreferencesFromResource(R.xml.pref_config_web_dav) + bindPreferenceSummaryToValue(findPreference("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, "") + ) + } + } } \ No newline at end of file