Properly highlight selected event color

This commit is contained in:
Naveen 2023-04-08 18:28:24 +05:30
parent 06a6e3a3f7
commit 8cc2c85f44
2 changed files with 12 additions and 5 deletions

View File

@ -835,9 +835,16 @@ class EventActivity : SimpleActivity() {
ensureBackgroundThread {
val eventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendarId = mEventCalendarId)!!
runOnUiThread {
SelectEventColorDialog(activity = this, eventType = eventType, selectedColor = mEvent.color) { color ->
mEventColor = color
updateEventColorInfo(eventType.color)
val selectedColor = if (mEventColor == 0) {
eventType.color
} else {
mEventColor
}
SelectEventColorDialog(activity = this, eventType = eventType, selectedColor = selectedColor) { color ->
if (color != eventType.color) {
mEventColor = color
updateEventColorInfo(eventType.color)
}
}
}
}

View File

@ -26,7 +26,7 @@ class SelectEventColorDialog(val activity: Activity, val eventType: EventType, v
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_color, null) as ViewGroup
radioGroup = view.dialog_select_event_type_color_radio
addRadioButton(colorKey = colors.values.size.inc(), color = 0)
addRadioButton(colorKey = colors.values.size.inc(), color = eventType.color)
colors.forEach { (color, key) ->
addRadioButton(key.toInt(), color)
}
@ -43,7 +43,7 @@ class SelectEventColorDialog(val activity: Activity, val eventType: EventType, v
private fun addRadioButton(colorKey: Int, color: Int) {
val view = activity.layoutInflater.inflate(R.layout.radio_button_with_color, null)
(view.dialog_radio_button as RadioButton).apply {
text = if (color == 0) activity.getString(R.string.default_color) else String.format("#%06X", 0xFFFFFF and color)
text = if (color == eventType.color) activity.getString(R.string.default_color) else String.format("#%06X", 0xFFFFFF and color)
isChecked = color == selectedColor
id = colorKey
}