Fix crash when pref mapped to RadioGroup is out of bounds

This commit is contained in:
Jays2Kings 2022-04-16 15:58:36 -04:00
parent 2e5bf2d0de
commit d14dfaac89

View file

@ -37,7 +37,7 @@ fun CompoundButton.bindToPreference(pref: Preference<Boolean>, block: ((Boolean)
* Binds a radio group with a int preference.
*/
fun RadioGroup.bindToPreference(pref: Preference<Int>, block: (() -> Unit)? = null) {
(getChildAt(pref.get()) as RadioButton).isChecked = true
(getChildAt(pref.get()) as? RadioButton)?.isChecked = true
setOnCheckedChangeListener { _, checkedId ->
val index = indexOfChild(findViewById(checkedId))
pref.set(index)