clock: watch pager is the main-clock, world, alarms trio
- Commit
de03527b3bfcae81a064a71a673b24a43e1d9001- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 06:17 UTC (6 hours ago)
- Parents
3b5b640
Owner correction: the swipeable watch Clock pages are the trio named on the main clock page - the clock face itself, World clock and Alarms - not the five sections the just-merged pager (48eafba7b) used. WearClockPage is now HOME/WORLD/ALARMS, and WearPagerScreen hosts only those three swipe pages. Timers and Stopwatch keep full functionality but are no longer swipe pages. They are WearRoute.Timers / WearRoute.Stopwatch detail routes pushed over the pager from chips on the main clock page, mirroring how AlarmDetail already pushes over the pager. WearMainActivity renders them from the same hoisted pager state, so system back (the shell WearBackStack) or the detail's home navigation pops back to the pager page the user left. Both screens gain an onBack parameter on the AlarmDetail pattern, and their watch-native behaviour is untouched: timers still arm via WatchTimerScheduler, the stopwatch keeps dual-base elapsed and laps, and per-screen state survives as before because WearClockStore is unchanged - timers and the stopwatch keep running from the persisted store while their routes are closed. WearClockPageTest pins the trio order, index round-trips and the timers/stopwatch-are-routes split (one new test). Wear listing previews document that timers/stopwatch have no pager preview, and :clock:metadata regenerated wear 1-2 (the page indicator now shows three pages; 3, the direct home body, is unchanged). Verified: :clock:metadata; :clock:lint and :clock:lintVitalRelease pass; :clock:testDevUnitTest 297 tests with the single pre-existing ClockPagesUiTest.mainActivityLaunches failure (UnsatisfiedLinkError at SQLiteConnection), proven identical on the unmodified 48eafba7b base - same test, same error, same cause. Local commit only; not pushed.
Diff
clock/AGENTS.md
diff --git a/clock/AGENTS.md b/clock/AGENTS.mdindex 77953ae50c..fc44349e8e 100644--- a/clock/AGENTS.md+++ b/clock/AGENTS.md@@ -44,7 +44,7 @@ same way — `platform/BootReceiver` (phone) and - **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first. ## Watch experience (in this module)-- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute`: the root `Home` is a swipe pager (`ui/WearPagerScreen` + `ui/WearClockPage`: home time face, world clocks, alarms, timers, stopwatch) and `AlarmDetail` pushes over it on the shell back stack. World clocks are synced/display-only; alarms are synced and armed on the watch by `platform/WatchAlarmScheduler` (armed proof in `domain/WearAlarmState.kt`); timers + stopwatch are watch-native (`platform/WatchTimerScheduler`, `domain/WatchTimerState.kt`). The pager uses the Material 1 wear generation the repo ships (foundation `HorizontalPager` + Material `Scaffold` TimeText/page-indicator, `TransformingLazyColumn` per page); see `ui/WearPagerScreen.kt` for the Material 3 hierarchy mapping.+- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute`: the root `Home` is a swipe pager (`ui/WearPagerScreen` + `ui/WearClockPage`: main clock face, world clock, alarms) and `AlarmDetail`, `Timers` and `Stopwatch` push over it on the shell back stack from the main clock page, popping back to the pager page left. World clocks are synced/display-only; alarms are synced and armed on the watch by `platform/WatchAlarmScheduler` (armed proof in `domain/WearAlarmState.kt`); timers + stopwatch are watch-native (`platform/WatchTimerScheduler`, `domain/WatchTimerState.kt`). The pager uses the Material 1 wear generation the repo ships (foundation `HorizontalPager` + Material `Scaffold` TimeText/page-indicator, `TransformingLazyColumn` per page); see `ui/WearPagerScreen.kt` for the Material 3 hierarchy mapping. - Watch state persists in `data/WearClockStore` (`wear-clock.json`); `ui/WearRingActivity` + `platform/WatchRingNotifier` are the ringing surface. - Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:clock:metadata` into `metadata_data/photos/clock/wear/`; phone shots use the `phone` bucket. **Gotchas:**
clock/src/main/java/com/vayunmathur/clock/ui/WearClockPage.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearClockPage.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearClockPage.ktindex b49ac6b27b..0a41585642 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearClockPage.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearClockPage.kt@@ -1,20 +1,19 @@ package com.vayunmathur.clock.ui /**- * The watch Clock's top-level swipe pages, in swipe order.+ * The watch Clock's top-level swipe pages, in swipe order: the main+ * clock face, world clock, alarms. *- * This is the root-level page set of the watch experience: [HOME] is the- * time face with jump chips, the other four are the clock sections that- * used to be separate back-stack destinations. Alarm detail is not a- * page — it pushes over the pager as a [WearRoute.AlarmDetail] route.+ * This is the root-level page set of the watch experience. Timers and+ * stopwatch are not pages — they keep their full function as+ * [WearRoute.Timers] / [WearRoute.Stopwatch] detail routes pushed over+ * the pager from the main clock page, like [WearRoute.AlarmDetail]. * Pure (no Compose/Android) so the ordering contract is unit-testable. */ enum class WearClockPage { HOME, WORLD, ALARMS,- TIMERS,- STOPWATCH, ; companion object {
clock/src/main/java/com/vayunmathur/clock/ui/WearHomeScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearHomeScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearHomeScreen.ktindex c5a8e0f02d..792931da13 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearHomeScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearHomeScreen.kt@@ -26,11 +26,17 @@ import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime import kotlin.time.Instant -/** First pager page: the watch's own time plus jump chips to the other pages. */+/**+ * First pager page (the main clock page): the watch's own time plus+ * entry chips. World clock and alarms jump the pager to their swipe+ * pages; timers and stopwatch push their detail routes over the pager.+ */ @Composable fun WearHomeScreen( contentPadding: PaddingValues = PaddingValues(), onOpenPage: (WearClockPage) -> Unit,+ onOpenTimers: () -> Unit,+ onOpenStopwatch: () -> Unit, ) { var nowMillis by remember { mutableLongStateOf(System.currentTimeMillis()) } LaunchedEffect(Unit) {@@ -39,19 +45,28 @@ fun WearHomeScreen( delay(1_000) } }- WearHomeContent(nowMillis = nowMillis, contentPadding = contentPadding, onOpenPage = onOpenPage)+ WearHomeContent(+ nowMillis = nowMillis,+ contentPadding = contentPadding,+ onOpenPage = onOpenPage,+ onOpenTimers = onOpenTimers,+ onOpenStopwatch = onOpenStopwatch,+ ) } /** * Stateless home body behind [WearHomeScreen]: the instant is a parameter, so * Compose previews (src/screenshotTest) render a fixed, reproducible time.- * Chips jump the pager; swiping reaches the same pages.+ * World/alarms chips jump the pager (swiping reaches the same pages);+ * timers/stopwatch chips push their routes. */ @Composable internal fun WearHomeContent( nowMillis: Long, contentPadding: PaddingValues = PaddingValues(), onOpenPage: (WearClockPage) -> Unit,+ onOpenTimers: () -> Unit,+ onOpenStopwatch: () -> Unit, ) { val local = remember(nowMillis) {@@ -76,15 +91,15 @@ internal fun WearHomeContent( WearMenuChip(stringResource(R.string.wear_alarms)) { onOpenPage(WearClockPage.ALARMS) } } item {- WearMenuChip(stringResource(R.string.wear_timers)) { onOpenPage(WearClockPage.TIMERS) }+ WearMenuChip(stringResource(R.string.wear_timers)) { onOpenTimers() } } item {- WearMenuChip(stringResource(R.string.wear_stopwatch)) { onOpenPage(WearClockPage.STOPWATCH) }+ WearMenuChip(stringResource(R.string.wear_stopwatch)) { onOpenStopwatch() } } } } -/** One home-menu row: a jump to a pager page. */+/** One home-menu row: a pager jump or a pushed detail route. */ @Composable private fun WearMenuChip( label: String,
clock/src/main/java/com/vayunmathur/clock/ui/WearMainActivity.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearMainActivity.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearMainActivity.ktindex 1b1c66356a..12b8c47767 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearMainActivity.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearMainActivity.kt@@ -9,10 +9,10 @@ import com.vayunmathur.library.wearlink.WearShellActivity /** * Watch clock entry: the root is a swipeable pager over the watch Clock- * pages (home time face, world clocks, alarms, timers, stopwatch);- * alarm detail pushes over it on the shell's back stack. Everything- * renders from the locally persisted store so it works with the phone- * absent.+ * pages (main clock face, world clock, alarms). Alarm detail, timers+ * and stopwatch push over it on the shell's back stack and pop back to+ * the pager page the user left. Everything renders from the locally+ * persisted store so it works with the phone absent. */ class WearMainActivity : WearShellActivity<WearRoute, WearClockStore>(WearRoute.Home) { // No Bluetooth prompt here: the Watch app owns the conduit link@@ -30,7 +30,7 @@ class WearMainActivity : WearShellActivity<WearRoute, WearClockStore>(WearRoute. route: WearRoute, navigate: (WearRoute) -> Unit, ) {- // Hoisted above the route switch: pushing alarm detail and+ // Hoisted above the route switch: pushing a detail route and // popping back returns to the pager page the user left. val pagerState = rememberPagerState(initialPage = 0) { WearClockPage.entries.size } when (val current = route) {@@ -39,6 +39,8 @@ class WearMainActivity : WearShellActivity<WearRoute, WearClockStore>(WearRoute. store = store, pagerState = pagerState, onOpenAlarm = { navigate(WearRoute.AlarmDetail(it)) },+ onOpenTimers = { navigate(WearRoute.Timers) },+ onOpenStopwatch = { navigate(WearRoute.Stopwatch) }, ) is WearRoute.AlarmDetail -> WearAlarmDetailScreen(@@ -46,6 +48,16 @@ class WearMainActivity : WearShellActivity<WearRoute, WearClockStore>(WearRoute. alarmId = current.alarmId, onBack = { navigate(WearRoute.Home) }, )+ WearRoute.Timers ->+ WearTimersScreen(+ store = store,+ onBack = { navigate(WearRoute.Home) },+ )+ WearRoute.Stopwatch ->+ WearStopwatchScreen(+ store = store,+ onBack = { navigate(WearRoute.Home) },+ ) } } }
clock/src/main/java/com/vayunmathur/clock/ui/WearPagerScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearPagerScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearPagerScreen.ktindex 8cf2a9df6c..2f362569c8 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearPagerScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearPagerScreen.kt@@ -40,17 +40,20 @@ import kotlinx.coroutines.launch * and passes it into its own `TransformingLazyColumn`, with a separate * `rememberTransformingLazyColumnState` inside each page scope. *- * [pagerState] is hoisted by the activity, so swiping away to a pushed- * detail route and back returns to the same page. All pages stay- * composed (`beyondViewportPageCount` covers the whole set), so each- * page keeps its scroll and UI state across swipes; stopwatch/timers- * keep running from the persisted store regardless.+ * [pagerState] is hoisted by the activity, so pushing a detail route+ * (alarm detail, timers, stopwatch) and popping back returns to the+ * same page. All pages stay composed (`beyondViewportPageCount` covers+ * the whole set), so each page keeps its scroll and UI state across+ * swipes; timers/stopwatch keep running from the persisted store+ * while their detail routes are closed. */ @Composable fun WearPagerScreen( store: WearClockStore, pagerState: PagerState, onOpenAlarm: (Long) -> Unit,+ onOpenTimers: () -> Unit,+ onOpenStopwatch: () -> Unit, ) { val scope = rememberCoroutineScope() WearPagerContent(pagerState = pagerState) { page, contentPadding ->@@ -63,6 +66,8 @@ fun WearPagerScreen( pagerState.animateScrollToPage(WearClockPage.indexOf(target)) } },+ onOpenTimers = onOpenTimers,+ onOpenStopwatch = onOpenStopwatch, ) WearClockPage.WORLD -> WearWorldClockScreen(@@ -75,16 +80,6 @@ fun WearPagerScreen( contentPadding = contentPadding, onOpenAlarm = onOpenAlarm, )- WearClockPage.TIMERS ->- WearTimersScreen(- store = store,- contentPadding = contentPadding,- )- WearClockPage.STOPWATCH ->- WearStopwatchScreen(- store = store,- contentPadding = contentPadding,- ) } } }
clock/src/main/java/com/vayunmathur/clock/ui/WearRoute.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearRoute.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearRoute.ktindex ca3d4a3971..9476cba90b 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearRoute.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearRoute.kt@@ -2,8 +2,11 @@ package com.vayunmathur.clock.ui /** * Watch navigation destinations. The root is the swipe pager- * ([WearClockPage]s under [Home]); detail is a route carrying the alarm- * id, never selection state, and pushes over the pager.+ * ([WearClockPage]s under [Home]); detail screens are routes, never+ * selection state, and push over the pager: one alarm by id, plus the+ * watch-native timers and stopwatch reached from the main clock page.+ * Back (system back, or a detail's explicit home navigation) pops back+ * to the pager page the user left. */ sealed interface WearRoute { /** Root: the swipeable pager of top-level watch Clock pages. */@@ -13,4 +16,10 @@ sealed interface WearRoute { data class AlarmDetail( val alarmId: Long, ) : WearRoute++ /** Watch-native timers, pushed over the pager from the main clock page. */+ data object Timers : WearRoute++ /** Watch-native stopwatch, pushed over the pager from the main clock page. */+ data object Stopwatch : WearRoute }
clock/src/main/java/com/vayunmathur/clock/ui/WearStopwatchScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearStopwatchScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearStopwatchScreen.ktindex 0c2937ce31..51cb9ec28d 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearStopwatchScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearStopwatchScreen.kt@@ -31,10 +31,17 @@ import com.vayunmathur.clock.domain.startWatchStopwatch import com.vayunmathur.clock.domain.watchStopwatchElapsedMillis import kotlinx.coroutines.delay -/** Watch-native stopwatch: dual-base elapsed, laps, persisted across process death. */+/**+ * Watch-native stopwatch, a detail route pushed over the pager from+ * the main clock page: dual-base elapsed, laps, persisted across+ * process death. Back (system back in the shell, or [onBack]) pops+ * back to the pager; the stopwatch keeps its persisted state either+ * way.+ */ @Composable fun WearStopwatchScreen( store: WearClockStore,+ onBack: () -> Unit, contentPadding: PaddingValues = PaddingValues(), ) { val persisted by store.state.collectAsState()
clock/src/main/java/com/vayunmathur/clock/ui/WearTimersScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WearTimersScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WearTimersScreen.ktindex 3b7e392e4a..b8df30db33 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/WearTimersScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WearTimersScreen.kt@@ -36,13 +36,17 @@ import com.vayunmathur.clock.platform.WatchTimerScheduler import kotlinx.coroutines.delay /**- * Watch-native timers: presets start a real countdown on this watch, armed- * with its AlarmManager — it rings here even with the phone absent. A timer- * is only shown running after the scheduler accepted it.+ * Watch-native timers, a detail route pushed over the pager from the+ * main clock page: presets start a real countdown on this watch, armed+ * with its AlarmManager — it rings here even with the phone absent. A+ * timer is only shown running after the scheduler accepted it. Back+ * (system back in the shell, or [onBack]) pops back to the pager;+ * timers keep running from the persisted store either way. */ @Composable fun WearTimersScreen( store: WearClockStore,+ onBack: () -> Unit, contentPadding: PaddingValues = PaddingValues(), ) { val persisted by store.state.collectAsState()
clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/WearMetadataPreviews.kt
diff --git a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/WearMetadataPreviews.kt b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/WearMetadataPreviews.ktindex f69ea34694..39fdab7f21 100644--- a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/WearMetadataPreviews.kt+++ b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/WearMetadataPreviews.kt@@ -32,9 +32,11 @@ private const val FIXED_NOW_MILLIS = 1795617660000L * `./gradlew :clock:metadata` renders these and copies the PNGs into * `metadata_data/photos/clock/wear/` — the merged app's wear bucket — where the release build picks them up. *- * The watch root is a swipe pager: previews 1–2 render [WearPagerContent]+ * The watch root is a swipe pager over the main clock page, world+ * clock and alarms: previews 1–2 render [WearPagerContent] * (TimeText + page-indicator dots over the page) at a fixed page, the square- * preview renders the home page body directly.+ * preview renders the home page body directly. Timers/stopwatch are+ * detail routes, not pages, so they have no pager preview here. * * Rules (same as every other module's MetadataPreviews): order comes from the * function names, each preview needs `@PreviewTest` plus `group = "wear"`, previews@@ -55,6 +57,8 @@ class WearMetadataPreviews { nowMillis = FIXED_NOW_MILLIS, contentPadding = contentPadding, onOpenPage = {},+ onOpenTimers = {},+ onOpenStopwatch = {}, ) } }@@ -131,7 +135,12 @@ class WearMetadataPreviews { fun Preview3HomeSquare() { MaterialTheme { Box(Modifier.fillMaxSize().background(MaterialTheme.colors.background)) {- WearHomeContent(nowMillis = FIXED_NOW_MILLIS, onOpenPage = {})+ WearHomeContent(+ nowMillis = FIXED_NOW_MILLIS,+ onOpenPage = {},+ onOpenTimers = {},+ onOpenStopwatch = {},+ ) } } }
clock/src/test/java/com/vayunmathur/clock/ui/WearClockPageTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/WearClockPageTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/WearClockPageTest.ktindex bfe1b7fc0d..19b37ca133 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/WearClockPageTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/WearClockPageTest.kt@@ -6,23 +6,24 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue /**- * Pager-state contract for the watch Clock root: page order, index- * round-trips, and the route split (pages at the root, detail pushed).- * The pager itself is Compose; this pins the pure state it is built from.+ * Pager-state contract for the watch Clock root: the swipe trio (main+ * clock page, world clock, alarms), index round-trips, and the route+ * split (pages at the root, timers/stopwatch/alarm detail pushed over+ * the pager). The pager itself is Compose; this pins the pure state+ * it is built from. */ class WearClockPageTest { @Test- fun pagesAreHomeThenSectionsInMenuOrder() {+ fun pagesAreMainClockWorldThenAlarms() { assertEquals( listOf( WearClockPage.HOME, WearClockPage.WORLD, WearClockPage.ALARMS,- WearClockPage.TIMERS,- WearClockPage.STOPWATCH, ), WearClockPage.entries.toList(), )+ assertEquals(3, WearClockPage.entries.size) } @Test@@ -31,16 +32,16 @@ class WearClockPageTest { assertEquals(page, WearClockPage.fromIndex(WearClockPage.indexOf(page))) } assertEquals(0, WearClockPage.indexOf(WearClockPage.HOME))- assertEquals(WearClockPage.entries.size - 1, WearClockPage.indexOf(WearClockPage.STOPWATCH))+ assertEquals(WearClockPage.entries.size - 1, WearClockPage.indexOf(WearClockPage.ALARMS)) } @Test fun fromIndexNeverGoesOutOfBounds() { assertEquals(WearClockPage.HOME, WearClockPage.fromIndex(0))- assertEquals(WearClockPage.STOPWATCH, WearClockPage.fromIndex(WearClockPage.entries.size - 1))+ assertEquals(WearClockPage.ALARMS, WearClockPage.fromIndex(WearClockPage.entries.size - 1)) // Wrap, never crash, on any index a pager could report mid-fling. assertEquals(WearClockPage.HOME, WearClockPage.fromIndex(WearClockPage.entries.size))- assertEquals(WearClockPage.STOPWATCH, WearClockPage.fromIndex(-1))+ assertEquals(WearClockPage.ALARMS, WearClockPage.fromIndex(-1)) } @Test@@ -52,4 +53,23 @@ class WearClockPageTest { assertEquals(42L, (detail as WearRoute.AlarmDetail).alarmId) assertFalse(detail == WearRoute.Home) }++ @Test+ fun timersAndStopwatchAreRoutesNotPages() {+ // Timers/stopwatch keep full function as detail routes pushed+ // from the main clock page; they are not swipe pages.+ val timers: WearRoute = WearRoute.Timers+ val stopwatch: WearRoute = WearRoute.Stopwatch+ assertTrue(timers is WearRoute.Timers)+ assertTrue(stopwatch is WearRoute.Stopwatch)+ assertFalse(timers == WearRoute.Home)+ assertFalse(stopwatch == WearRoute.Home)+ assertFalse(timers == stopwatch)+ // The trio is exactly the swipe set: three pages, none of them+ // a timers/stopwatch page.+ assertEquals(+ listOf("HOME", "WORLD", "ALARMS"),+ WearClockPage.entries.map { it.name },+ )+ } }
metadata_data/photos/clock/wear/1.png
diff --git a/metadata_data/photos/clock/wear/1.png b/metadata_data/photos/clock/wear/1.pngindex 4edeafa726..c3d8bbed68 100644Binary files a/metadata_data/photos/clock/wear/1.png and b/metadata_data/photos/clock/wear/1.png differ
metadata_data/photos/clock/wear/2.png
diff --git a/metadata_data/photos/clock/wear/2.png b/metadata_data/photos/clock/wear/2.pngindex 6f1fed5cdf..568750582e 100644Binary files a/metadata_data/photos/clock/wear/2.png and b/metadata_data/photos/clock/wear/2.png differ