Modern Apps git

← Modern-Apps.git

calendar: restyle watch agenda like the agenda widget

Commit
190cdc38879dd83d7f30bf2187921019b48f82df
Author
Vayun Mathur <[email protected]>
When
2026-12-05 14:14 UTC (20 hours ago)
Parents
b161f94
The watch agenda used generic Wear Chip pills with centred
caption section labels (Today / Upcoming / Nov 25), a start
time only, and no calendar colour or location, so it read
nothing like the phone agenda widget the owner uses daily.

Mirror widget/CalendarGlanceWidget's visual language in
ui/WearAgendaScreen, adapted to the round display:
- Title is now the widget title-bar date
  (DateString.dateWeekdayNoYear) instead of the app name.
- Day headings replace the centred captions: left-aligned
  medium body2 labels reading Today / Tomorrow /
  weekday-date (the widget's dayHeaderLabel rule), aligned
  with the event text; the redundant Upcoming umbrella
  heading is dropped. The domain wearAgenda today/upcoming
  split, grouping, keys and order are unchanged.
- Event rows replace the Chip pills: a surface row with
  rounded corners inside the round safe inset, a 6dp
  leading colour bar in the event calendar colour (grey
  fallback matching the phone agenda), title over a
  start-end time range, and location when present, with
  the widget's compact 8dp vertical padding and
  onSurface/onSurfaceVariant typography.
- formatWearEventTime now prints true 12-hour time
  (2:41 PM, not 14:41 PM); it is shared with the watch
  event detail, which gains the same correction.

Behaviour is unchanged: same snapshot data, same tap to
the existing WearRoute.Event detail, same empty/truncated
states and the same Sync now chip.

Screenshot fixtures in WearMetadataPreviews now carry
deterministic calendar colours (the widget preview palette)
and a second today event, plus a new empty-agenda wear
preview; metadata_data wear images are regenerated
(wear/2 also reflects the 12-hour detail fix). A new
WearAgendaFormatTest pins the time-range and day-label
formatting.

Verified: ./gradlew :calendar:lint
:calendar:lintVitalRelease :calendar:testDevUnitTest
--max-workers=128 — lint green; 340 unit tests with only
the 2 pre-existing ImportGlanceHoliday failures, proven
at parity against a 337-test baseline run on origin/main
before the change. :calendar:metadata and
:calendar:compileDevScreenshotTestKotlin also pass.
ktlintCheck still reports the module's pre-existing
backlog in untouched files.

Diff

calendar/src/main/java/com/vayunmathur/calendar/ui/WearAgendaScreen.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/WearAgendaScreen.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/WearAgendaScreen.ktindex a05a85d1d9..a600d2c618 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/WearAgendaScreen.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/WearAgendaScreen.kt@@ -1,7 +1,17 @@ package com.vayunmathur.calendar.ui +import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.IntrinsicSize+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue@@ -10,8 +20,11 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.wear.compose.foundation.lazy.ScalingLazyColumn@@ -23,19 +36,21 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.calendar.R import com.vayunmathur.calendar.data.WearCalendarStore+import com.vayunmathur.library.ui.DateString import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent import com.vayunmathur.library.wearlink.calendar.WearCalendarSnapshot import com.vayunmathur.calendar.domain.wearAgenda import com.vayunmathur.calendar.domain.wearEventDay import com.vayunmathur.calendar.sync.requestWearSync import kotlinx.coroutines.launch+import kotlinx.datetime.DatePeriod import kotlinx.datetime.TimeZone import kotlinx.datetime.format import kotlinx.datetime.format.MonthNames import kotlinx.datetime.format.char+import kotlinx.datetime.plus import kotlin.time.Instant import kotlinx.datetime.LocalDate-import kotlinx.datetime.LocalDateTime import kotlinx.datetime.toLocalDateTime  /** Round-screen agenda: today's events first, then upcoming grouped by day. */@@ -54,6 +69,14 @@ fun WearAgendaScreen(store: WearCalendarStore, onOpenEvent: (WearCalendarEvent) /**  * Stateless agenda body behind [WearAgendaScreen]: snapshot and instant are parameters,  * so Compose previews (src/screenshotTest) render literal fixtures with no store or phone.+ *+ * Visual language mirrors the phone agenda Glance widget+ * (widget/CalendarGlanceWidget): a date title, per-day headings labelled+ * Today/Tomorrow/weekday-date, and flush event rows with a leading colour+ * bar, title over a time range, and location when present. The widget's+ * flat full-bleed rows are adapted to the round display as surface rows+ * with rounded corners inside the watch's safe horizontal inset, and the+ * generic Chip pills / centred section labels are dropped.  */ @Composable internal fun WearAgendaContent(@@ -70,12 +93,15 @@ internal fun WearAgendaContent(     val agenda = remember(snapshot, nowMillis) {         wearAgenda(snapshot, nowMillis, zone)     }+    val today = remember(nowMillis, zone) {+        Instant.fromEpochMilliseconds(nowMillis).toLocalDateTime(zone).date+    }     val listState = rememberScalingLazyListState()      ScalingLazyColumn(state = listState) {         item {             Text(-                stringResource(R.string.app_name),+                DateString.dateWeekdayNoYear(today),                 style = MaterialTheme.typography.title3,                 textAlign = TextAlign.Center,                 modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),@@ -102,18 +128,15 @@ internal fun WearAgendaContent(             }         } else {             if (agenda.today.isNotEmpty()) {-                item { WearSectionHeader(stringResource(R.string.wear_today)) }+                item { WearDayHeader(day = today, today = today) }                 items(agenda.today, key = { "${it.eventId}:${it.startMillis}" }) { event ->-                    WearEventChip(event, zone, onClick = { onOpenEvent(event) })+                    WearEventRow(event, zone, onClick = { onOpenEvent(event) })                 }             }-            if (agenda.upcoming.isNotEmpty()) {-                item { WearSectionHeader(stringResource(R.string.wear_upcoming)) }-                agenda.upcoming.groupBy { wearEventDay(it, zone) }.forEach { (day, dayEvents) ->-                    item(key = "day:$day") { WearSectionHeader(formatWearDay(day)) }-                    items(dayEvents, key = { "${it.eventId}:${it.startMillis}" }) { event ->-                        WearEventChip(event, zone, onClick = { onOpenEvent(event) })-                    }+            agenda.upcoming.groupBy { wearEventDay(it, zone) }.forEach { (day, dayEvents) ->+                item(key = "day:$day") { WearDayHeader(day = day, today = today) }+                items(dayEvents, key = { "${it.eventId}:${it.startMillis}" }) { event ->+                    WearEventRow(event, zone, onClick = { onOpenEvent(event) })                 }             }             if (snapshot.truncated) {@@ -142,27 +165,68 @@ internal fun WearAgendaContent(     } } -/** One section label in the agenda list. */+/**+ * One day-group heading, mirroring the widget's DayHeader: left-aligned+ * medium-weight label, "Today"/"Tomorrow" for those days and the+ * weekday + date otherwise. Left alignment is inset for the round screen.+ */ @Composable-private fun WearSectionHeader(text: String) {+private fun WearDayHeader(day: LocalDate, today: LocalDate) {+    val text = when (day) {+        today -> stringResource(R.string.wear_today)+        today + DatePeriod(days = 1) -> stringResource(R.string.tomorrow)+        else -> DateString.dateWeekday(day)+    }     Text(         text,-        style = MaterialTheme.typography.caption1,-        textAlign = TextAlign.Center,-        modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp),+        style = MaterialTheme.typography.body2.copy(fontWeight = FontWeight.Medium),+        color = MaterialTheme.colors.onSurface,+        modifier = Modifier.fillMaxWidth().padding(start = 28.dp, end = 12.dp, top = 10.dp, bottom = 2.dp),     ) } -/** One tappable event row: title plus its time (or All day). */+/**+ * One tappable event row, mirroring the widget's CalendarEventRow: a flush+ * surface row with a 6dp leading colour bar in the calendar colour, the+ * title over its time range, and the location when present. Rounded+ * corners keep the row inside the round display's usable width.+ */ @Composable-private fun WearEventChip(event: WearCalendarEvent, zone: TimeZone, onClick: () -> Unit) {-    Chip(-        onClick = onClick,-        label = { Text(event.title, maxLines = 1) },-        secondaryLabel = { Text(formatWearEventTime(event, zone), maxLines = 1) },-        colors = ChipDefaults.secondaryChipColors(),-        modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),-    )+private fun WearEventRow(event: WearCalendarEvent, zone: TimeZone, onClick: () -> Unit) {+    val barColor = if (event.color != 0) Color(event.color) else Color(0xFF808080.toInt())+    Row(+        modifier = Modifier+            .fillMaxWidth()+            .padding(horizontal = 12.dp, vertical = 1.dp)+            .clip(RoundedCornerShape(12.dp))+            .background(MaterialTheme.colors.surface)+            .clickable(onClick = onClick)+            .height(IntrinsicSize.Min),+    ) {+        Box(Modifier.width(6.dp).fillMaxHeight().background(barColor))+        Column(Modifier.fillMaxWidth().padding(horizontal = 10.dp, vertical = 8.dp)) {+            Text(+                event.title,+                style = MaterialTheme.typography.body2,+                color = MaterialTheme.colors.onSurface,+                maxLines = 1,+            )+            Text(+                formatWearEventTimeRange(event, zone),+                style = MaterialTheme.typography.caption2,+                color = MaterialTheme.colors.onSurfaceVariant,+                maxLines = 1,+            )+            if (event.location.isNotBlank()) {+                Text(+                    event.location,+                    style = MaterialTheme.typography.caption2,+                    color = MaterialTheme.colors.onSurfaceVariant,+                    maxLines = 1,+                )+            }+        }+    } }  private val wearDayFormat = LocalDate.Format {@@ -174,17 +238,19 @@ private val wearDayFormat = LocalDate.Format { /** "Nov 25" style day label. */ fun formatWearDay(date: LocalDate): String = date.format(wearDayFormat) -private val wearTimeFormat = LocalDateTime.Format {-    hour()-    char(':')-    minute()-    char(' ')-    amPmMarker("AM", "PM")-}- /** "All day" or "2:30 PM" for one event in [zone]. */ fun formatWearEventTime(event: WearCalendarEvent, zone: TimeZone): String {     if (event.allDay) return "All day"     val local = Instant.fromEpochMilliseconds(event.startMillis).toLocalDateTime(zone)-    return local.format(wearTimeFormat)+    val hour12 = if (local.hour % 12 == 0) 12 else local.hour % 12+    val minute = local.minute.toString().padStart(2, '0')+    val marker = if (local.hour < 12) "AM" else "PM"+    return "$hour12:$minute $marker"+}++/** "All day" or the widget-style "2:30 PM – 3:30 PM" range for one event in [zone]. */+fun formatWearEventTimeRange(event: WearCalendarEvent, zone: TimeZone): String {+    if (event.allDay) return "All day"+    val end = event.copy(startMillis = event.endMillis)+    return "${formatWearEventTime(event, zone)} – ${formatWearEventTime(end, zone)}" }
calendar/src/screenshotTest/kotlin/com/vayunmathur/calendar/ui/WearMetadataPreviews.kt
diff --git a/calendar/src/screenshotTest/kotlin/com/vayunmathur/calendar/ui/WearMetadataPreviews.kt b/calendar/src/screenshotTest/kotlin/com/vayunmathur/calendar/ui/WearMetadataPreviews.ktindex 833e3db1c9..ddc8dca8cc 100644--- a/calendar/src/screenshotTest/kotlin/com/vayunmathur/calendar/ui/WearMetadataPreviews.kt+++ b/calendar/src/screenshotTest/kotlin/com/vayunmathur/calendar/ui/WearMetadataPreviews.kt@@ -20,9 +20,10 @@ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320" private const val FIXED_NOW_MILLIS = 1795617660000L  private val fixtureEvents = listOf(-    WearCalendarEvent(eventId = 1, title = "Design review", location = "Room 4", description = "Bring the latest mockups.", calendarName = "Work", startMillis = FIXED_NOW_MILLIS + 3_600_000L, endMillis = FIXED_NOW_MILLIS + 7_200_000L),-    WearCalendarEvent(eventId = 2, title = "Dentist", location = "High Street", calendarName = "Personal", startMillis = FIXED_NOW_MILLIS + 86_400_000L, endMillis = FIXED_NOW_MILLIS + 90_000_000L),-    WearCalendarEvent(eventId = 3, title = "Public holiday", calendarName = "Holidays", startMillis = FIXED_NOW_MILLIS + 172_800_000L, endMillis = FIXED_NOW_MILLIS + 259_200_000L, allDay = true),+    WearCalendarEvent(eventId = 1, title = "Design review", location = "Room 4", description = "Bring the latest mockups.", calendarName = "Work", color = 0xFF4285F4.toInt(), startMillis = FIXED_NOW_MILLIS + 3_600_000L, endMillis = FIXED_NOW_MILLIS + 7_200_000L),+    WearCalendarEvent(eventId = 4, title = "Team standup", location = "", calendarName = "Work", color = 0xFF34A853.toInt(), startMillis = FIXED_NOW_MILLIS + 10_800_000L, endMillis = FIXED_NOW_MILLIS + 12_600_000L),+    WearCalendarEvent(eventId = 2, title = "Dentist", location = "High Street", calendarName = "Personal", color = 0xFFEA4335.toInt(), startMillis = FIXED_NOW_MILLIS + 86_400_000L, endMillis = FIXED_NOW_MILLIS + 90_000_000L),+    WearCalendarEvent(eventId = 3, title = "Public holiday", calendarName = "Holidays", color = 0xFFFBBC04.toInt(), startMillis = FIXED_NOW_MILLIS + 172_800_000L, endMillis = FIXED_NOW_MILLIS + 259_200_000L, allDay = true), )  /**@@ -51,6 +52,20 @@ class WearMetadataPreviews {     fun Preview2EventRound() {         RoundPreview { WearEventContent(event = fixtureEvents[0], onBack = {}) }     }++    @PreviewTest+    @Preview(name = "3-agenda-empty-round", device = ROUND, group = "wear")+    @Composable+    fun Preview3AgendaEmptyRound() {+        RoundPreview {+            WearAgendaContent(+                snapshot = WearCalendarSnapshot(generatedAtMillis = FIXED_NOW_MILLIS, events = emptyList()),+                nowMillis = FIXED_NOW_MILLIS,+                onOpenEvent = {},+                onRequestSync = { true },+            )+        }+    } }  /** Round-watch framing: clip Layoutlib's rectangular canvas to the watch shape. */
calendar/src/test/java/com/vayunmathur/calendar/ui/WearAgendaFormatTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/WearAgendaFormatTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/WearAgendaFormatTest.ktnew file mode 100644index 0000000000..89e070c3f7--- /dev/null+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/WearAgendaFormatTest.kt@@ -0,0 +1,41 @@+package com.vayunmathur.calendar.ui++import com.vayunmathur.library.wearlink.calendar.WearCalendarEvent+import kotlinx.datetime.LocalDate+import kotlinx.datetime.TimeZone+import org.junit.Assert.assertEquals+import org.junit.Test++class WearAgendaFormatTest {++    // 2026-11-25 14:41 UTC, matching the wear screenshot fixtures.+    private val startMillis = 1_795_617_660_000L++    @Test+    fun `time range shows start and end like the agenda widget`() {+        val event = WearCalendarEvent(+            eventId = 1,+            title = "Design review",+            startMillis = startMillis,+            endMillis = startMillis + 3_600_000L,+        )+        assertEquals("2:41 PM – 3:41 PM", formatWearEventTimeRange(event, TimeZone.UTC))+    }++    @Test+    fun `time range is all day for all day events`() {+        val event = WearCalendarEvent(+            eventId = 2,+            title = "Public holiday",+            startMillis = startMillis,+            endMillis = startMillis + 86_400_000L,+            allDay = true,+        )+        assertEquals("All day", formatWearEventTimeRange(event, TimeZone.UTC))+    }++    @Test+    fun `day label keeps the short month day form used on event detail`() {+        assertEquals("Nov 25", formatWearDay(LocalDate(2026, 11, 25)))+    }+}
metadata_data/photos/calendar/wear/1.png
diff --git a/metadata_data/photos/calendar/wear/1.png b/metadata_data/photos/calendar/wear/1.pngindex 912eacbfe2..b1cb50d626 100644Binary files a/metadata_data/photos/calendar/wear/1.png and b/metadata_data/photos/calendar/wear/1.png differ
metadata_data/photos/calendar/wear/2.png
diff --git a/metadata_data/photos/calendar/wear/2.png b/metadata_data/photos/calendar/wear/2.pngindex e07e9627d8..5c0fc38778 100644Binary files a/metadata_data/photos/calendar/wear/2.png and b/metadata_data/photos/calendar/wear/2.png differ
metadata_data/photos/calendar/wear/3.png
diff --git a/metadata_data/photos/calendar/wear/3.png b/metadata_data/photos/calendar/wear/3.pngnew file mode 100644index 0000000000..f1305700dbBinary files /dev/null and b/metadata_data/photos/calendar/wear/3.png differ