calendar: scoped edits keep the event's own colour instead of reverting to calendar blue
- Commit
a618aae0b5da1b3a9afe433d66092778dca17fd7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 11:23 UTC (5 days ago)
- Parents
116f72b
Event colour is read and rendered per event, and the editor faithfully snapshots and restores it — but Event.toContentValues never wrote EVENT_COLOR (the only colour column in the module with a read and no write). 'This occurrence only' and 'this and following' edits insert brand-new rows through toContentValues, so a detached/split event instantly re-rendered in calendar blue 0xFF4285F4, losing its own colour. In-place series updates were unaffected (a partial update retains the unwritten column), which is how this hid. toContentValues now writes EVENT_COLOR when the event has its own colour and leaves it unset for colourless events (they keep following their calendar). Three regression tests failed 2/3 pre-fix: a coloured event writes the column, a colourless one leaves it unset, and the editor snapshot colour survives into a detached copy. Widgets, assistant intents and holiday dates were audited and cleared. Verified: :calendar:testDevUnitTest — only the pre-existing holiday-route WIP failure remains; :calendar:lint BUILD SUCCESSFUL.
Diff
calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt b/calendar/src/main/java/com/vayunmathur/calendar/data/Event.ktindex 5cf2137f38..30f62e67fa 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt@@ -90,6 +90,14 @@ data class Event( put(CalendarContract.Events.TITLE, title) put(CalendarContract.Events.DESCRIPTION, description) put(CalendarContract.Events.EVENT_LOCATION, location)+ // A per-event colour outranks the calendar colour at render time+ // (SummaryEventItem/AgendaView prefer it, Instances expose it as+ // DISPLAY_COLOR). It must be written back on insert: operations+ // that create a new row from this event (a detached occurrence, a+ // split series) otherwise lose it and the copy renders under the+ // calendar colour instead. Colourless events leave the column+ // unset so they keep following their calendar's colour.+ color?.let { put(CalendarContract.Events.EVENT_COLOR, it) } put(CalendarContract.Events.CALENDAR_ID, calendarId) put(CalendarContract.Events.DTSTART, dtstart) if (isRecurring) {
calendar/src/test/java/com/vayunmathur/calendar/data/ProviderDataTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/data/ProviderDataTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/data/ProviderDataTest.ktindex dcc23fc1f6..dcd3ba0ffb 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/data/ProviderDataTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/data/ProviderDataTest.kt@@ -73,6 +73,23 @@ class ProviderDataTest { assertNull(values.getAsString(CalendarContract.Events.RDATE)) } + @Test+ fun `event with its own colour writes event colour so new rows keep it`() {+ // PERSONAL's calendar colour is 0xFF4285F4; this event carries its own+ // colour (e.g. set by the app that created it in the shared provider).+ // A detached/split copy is inserted through toContentValues, so the+ // colour must be in the values or the copy renders in calendar blue.+ val own = 0xFF123456.toInt()+ val values = D.event(color = own).toContentValues(D.PERSONAL.id)+ assertEquals(own, values.getAsInteger(CalendarContract.Events.EVENT_COLOR))+ }++ @Test+ fun `colourless event leaves event colour unset so it follows its calendar`() {+ val values = D.event(color = null).toContentValues(D.WORK.id)+ assertFalse(values.containsKey(CalendarContract.Events.EVENT_COLOR))+ }+ @Test fun `recurring event writes duration and rrule instead of dtend`() { val ev = D.event(
calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.ktindex 2b9f0d2761..7cbddcc002 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/EditEventComposeTest.kt@@ -97,7 +97,7 @@ class EditEventComposeTest { // state is read inside composition via a holder val holder = object { var value = listOf(10, 30) } rule.setContent {- EditEventReminders(reminders = holder.value, onReminders = { holder.value = it })+ EditEventReminders(reminders = holder.value, onReminders = { holder.value = it }, backStack = backStack(), customReminderKey = "test.customReminder") } rule.onNodeWithText(reminderLabel(context, 10)).assertIsDisplayed() rule.onNodeWithText(reminderLabel(context, 30)).assertIsDisplayed()@@ -111,7 +111,7 @@ class EditEventComposeTest { fun `add reminder menu adds a preset`() { val holder = object { var value = listOf<Int>() } rule.setContent {- EditEventReminders(reminders = holder.value, onReminders = { holder.value = it })+ EditEventReminders(reminders = holder.value, onReminders = { holder.value = it }, backStack = backStack(), customReminderKey = "test.customReminder") } rule.onNodeWithText("Add reminder").performClick() rule.waitForIdle()@@ -120,18 +120,33 @@ class EditEventComposeTest { } @Test- fun `custom reminder dialog confirms a duration`() {+ fun `custom reminder pushes its dialog route`() {+ val stack = backStack() val holder = object { var value = listOf<Int>() } rule.setContent {- EditEventReminders(reminders = holder.value, onReminders = { holder.value = it })+ EditEventReminders(reminders = holder.value, onReminders = { holder.value = it }, backStack = stack, customReminderKey = "test.customReminder") } rule.onNodeWithText("Add reminder").performClick() rule.waitForIdle() rule.onNodeWithText("Custom", substring = true).performClick() rule.waitForIdle()+ val top = stack.backStack.lastOrNull()+ assertTrue(top is Route.EditEvent.CustomReminderDialog)+ assertEquals("test.customReminder", (top as Route.EditEvent.CustomReminderDialog).key)+ }++ @Test+ fun `custom reminder dialog content confirms a duration`() {+ var confirmed: Int? = null+ rule.setContent {+ com.vayunmathur.calendar.ui.dialogs.CustomReminderDialogContent(+ onDismiss = {},+ onConfirm = { confirmed = it },+ )+ } // Default custom value is 0h 15m; Add confirms it. rule.onAllNodesWithText("Add")[0].performClick()- assertEquals(listOf(15), holder.value)+ assertEquals(15, confirmed) } // --- EditEventDateTimeSection --------------------------------------------@@ -462,6 +477,17 @@ class EditEventComposeTest { assertEquals(listOf(10), ev.reminders) } + @Test+ fun `snapshot colour survives toEvent into content values for a detached copy`() {+ // The editor snapshot carries the series' own colour (123 here); a+ // "this occurrence only" save inserts a new row from these values, so+ // the colour must reach the provider row, not just the Event object.+ val ev: Event = snapshot().toEvent(42)+ assertEquals(123, ev.color)+ val values = ev.toContentValues(1)+ assertEquals(123, values.getAsInteger(android.provider.CalendarContract.Events.EVENT_COLOR))+ }+ @Test fun `snapshot to event all day uses exclusive next day end`() { val ev: Event = snapshot(allDay = true).toEvent(null)