From 800fb29f21a748f99e13e355ac381b97786e680c Mon Sep 17 00:00:00 2001 From: Helium314 Date: Tue, 21 Nov 2023 14:07:18 +0100 Subject: [PATCH] update correct preview when setting colors, fixes #284 --- .../inputmethod/latin/settings/ColorsSettingsFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt index c472efb30..ae0eb1939 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt @@ -15,7 +15,7 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import androidx.core.view.MenuProvider -import androidx.core.view.forEachIndexed +import androidx.core.view.forEach import androidx.core.view.get import androidx.fragment.app.Fragment import com.rarepebble.colorpicker.ColorPickerView @@ -122,6 +122,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi if (!moreColors && colorPref in colorPrefsToHideInitially && autoColor) return@forEachIndexed val csb = ColorSettingBinding.inflate(layoutInflater, binding.colorSettingsContainer, true) + csb.root.tag = index csb.colorSwitch.isChecked = !autoColor csb.colorPreview.setColorFilter(Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight)) csb.colorText.text = colorPrefNames[index] @@ -203,7 +204,8 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi } private fun updateColorPreviews() { - binding.colorSettingsContainer.forEachIndexed { index, view -> + binding.colorSettingsContainer.forEach { view -> + val index = view.tag as Int val color = Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight) view.findViewById(R.id.color_preview)?.setColorFilter(color) }