1
0
Fork 0

For #2230 - Persist Theme Through RadioButtonPreference (#2235)

master
Emily Kager 2019-05-02 12:34:48 -07:00 committed by Colin Lee
parent 7dda013ad1
commit 2397b22d09
2 changed files with 15 additions and 5 deletions

View File

@ -16,6 +16,7 @@ import androidx.core.content.res.TypedArrayUtils
import androidx.core.text.HtmlCompat
import androidx.preference.Preference
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Settings
class RadioButtonPreference : Preference {
private val radioGroups = mutableListOf<RadioButtonPreference>()
@ -68,6 +69,8 @@ class RadioButtonPreference : Preference {
private fun updateRadioValue(isChecked: Boolean) {
persistBoolean(isChecked)
radioButton.isChecked = isChecked
Settings.getInstance(summaryView.context).preferences.edit().putBoolean(key, isChecked)
.apply()
}
private fun bindRadioButton(holder: PreferenceViewHolder) {
@ -77,9 +80,15 @@ class RadioButtonPreference : Preference {
private fun initDefaultValue(typedArray: TypedArray) {
if (typedArray.hasValue(androidx.preference.R.styleable.Preference_defaultValue)) {
defaultValue = typedArray.getBoolean(androidx.preference.R.styleable.Preference_defaultValue, false)
defaultValue = typedArray.getBoolean(
androidx.preference.R.styleable.Preference_defaultValue,
false
)
} else if (typedArray.hasValue(androidx.preference.R.styleable.Preference_android_defaultValue)) {
defaultValue = typedArray.getBoolean(androidx.preference.R.styleable.Preference_android_defaultValue, false)
defaultValue = typedArray.getBoolean(
androidx.preference.R.styleable.Preference_android_defaultValue,
false
)
}
}
@ -101,7 +110,8 @@ class RadioButtonPreference : Preference {
summaryView = holder.findViewById(R.id.widget_summary) as TextView
if (!TextUtils.isEmpty(summary)) {
if (shouldSummaryBeParsedAsHtmlContent) {
summaryView.text = HtmlCompat.fromHtml(summary.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT)
summaryView.text =
HtmlCompat.fromHtml(summary.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT)
} else {
summaryView.text = summary
}

View File

@ -6,7 +6,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:defaultValue="@bool/underAPI28"
android:key="@string/pref_key_light_theme"
android:title="@string/preference_light_theme" />
@ -22,7 +22,7 @@
app:isPreferenceVisible="@bool/underAPI28" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:defaultValue="@bool/API28"
android:key="@string/pref_key_follow_device_theme"
android:title="@string/preference_follow_device_theme"
app:isPreferenceVisible="@bool/API28" />