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.
This commit is contained in:
parent
d9e2d7f07a
commit
a51f1aa5b9
1 changed files with 2 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue