update correct preview when setting colors, fixes #284

This commit is contained in:
Helium314 2023-11-21 14:07:18 +01:00
parent 4af0f2d3a1
commit 800fb29f21

View file

@ -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<ImageView>(R.id.color_preview)?.setColorFilter(color)
}