Fix flickering

This commit is contained in:
J-Jamet committed 2021-03-07 18:49:19 +01:00
1 parent 79d11138e6
commit d46edfc9b7
2 files changed
+12 -6

No files matched your search

@@ -51,7 +51,7 @@ class IconCustomFragment : IconFragment<IconImageCustom>() {
iconPickerAdapter.deselectAllIcons()
} else {
iconActionSelectionMode = true
iconPickerAdapter.updateIcons(customIconsSelected)
iconPickerAdapter.updateIconSelectedState(customIconsSelected)
}
}
iconPickerViewModel.customIconRemoved.observe(viewLifecycleOwner) { customIconRemoved ->
@@ -31,15 +31,21 @@ class IconPickerAdapter<I: IconImageDraw>(val context: Context, private val tint
}
fun updateIcon(icon: I) {
if (iconList.contains(icon)) {
iconList[iconList.indexOf(icon)] = icon
notifyItemChanged(iconList.indexOf(icon))
val index = iconList.indexOf(icon)
if (index != -1) {
iconList[index] = icon
notifyItemChanged(index)
}
}
fun updateIcons(icons: List<I>) {
fun updateIconSelectedState(icons: List<I>) {
icons.forEach { icon ->
updateIcon(icon)
val index = iconList.indexOf(icon)
if (index != -1
&& iconList[index].selected != icon.selected) {
iconList[index] = icon
notifyItemChanged(index)
}
}
}