From a51f1aa5b95e4859f79c3d5c3d9a01de70fea88e Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Sun, 6 Feb 2022 19:17:49 -0700 Subject: [PATCH] pref: fix application of m3 switches Fix an issue with M3SwitchPreference where the switch would not update properly. When reacing M3SwitchPreference, I wanted to make an optimization regarding updating the switch to M3, so I decided to make the preference check if they have already applied the switch, and then ignore it if that's the case. However, I ended up forgetting that ViewHolders tend to need to be re-bound, which resulted in this optimization leading to inconsistent application of the M3 switches. Fix this by removing that optimization. --- .../org/oxycblt/auxio/settings/pref/M3SwitchPreference.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/settings/pref/M3SwitchPreference.kt b/app/src/main/java/org/oxycblt/auxio/settings/pref/M3SwitchPreference.kt index db2598f1e..db4204fee 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/pref/M3SwitchPreference.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/pref/M3SwitchPreference.kt @@ -20,13 +20,11 @@ class M3SwitchPreference @JvmOverloads constructor( defStyleAttr: Int = R.attr.switchPreferenceCompatStyle, defStyleRes: Int = 0 ) : SwitchPreferenceCompat(context, attrs, defStyleAttr, defStyleRes) { - // Lollipop cannot into ColorStateList, disable this feature on that version - private var needToUpdateSwitch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) - if (needToUpdateSwitch) { + // Lollipop cannot into ColorStateList, disable this feature on that version + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val switch = holder.findViewById(androidx.preference.R.id.switchWidget) if (switch is SwitchCompat) { @@ -36,8 +34,6 @@ class M3SwitchPreference @JvmOverloads constructor( thumbDrawable = context.getDrawableSafe(R.drawable.ui_m3_switch_thumb) thumbTintList = context.getColorStateListSafe(R.color.sel_m3_switch_thumb) } - - needToUpdateSwitch = false } } }