clock: swipeable clock-face, world-clock and alarm pages
- Commit
e0bb2e6d266833d35f5274a1b2f07b81a65843fa- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 06:26 UTC (4 hours ago)
- Parents
de03527
The phone Clock had four route-backed bottom-nav tabs (Alarm, Clock, Timer, Stopwatch) with no swipe between them, and the Clock tab combined the main clock face and the world-clock list on one page. Split the world-clock list into its own Route.WorldClock destination (WorldClockPage/WorldClockScreen, carrying the city rows, reorder and the add-city FAB that used to live in ClockScreen), leaving Route.Clock as the main clock face. ClockTabs keeps the route-backed TabbedPagerScaffold (five tabs: Clock, World clock, Alarm, Timer, Stopwatch) so the bottom bar is rendered outside the navigation host and stays still, and its content region now carries swipeBetweenRoutes over CLOCK_SWIPE_PAGES (Clock, WorldClock, Alarm): a horizontal swipe is the same sibling switch as a bottom-bar tap (navigateToSiblingOffset replaces the top, never pushes), so back, deep links and process restore see the real route. Timer and Stopwatch stay sibling tabs outside the swipe group - a swipe while either is on top does nothing - and no Bedtime/Focus sections exist in this app. Dialog and settings routes push over the tabs exactly as before; a deep link to WorldClock starts on that tab. Store previews follow the new tab order (clock face, world clock, alarms, timer, stopwatch) and the clock metadata was regenerated. The empty-stopwatch-toolbar fix (778b2ac19) is untouched. Verified: :clock:lint and :clock:lintVitalRelease pass; :clock:testDevUnitTest runs 298 tests with the single pre-existing ClockPagesUiTest.mainActivityLaunches SQLCipher UnsatisfiedLinkError, proven identical on an unmodified origin/main worktree (9 tests, same 1 failure); :clock:metadata regenerated.
Diff
clock/AGENTS.md
diff --git a/clock/AGENTS.md b/clock/AGENTS.mdindex fc44349e8e..bc14310dbe 100644--- a/clock/AGENTS.md+++ b/clock/AGENTS.md@@ -16,8 +16,8 @@ _Install: ./install clock (dev by default)._ - Alarms with full-screen lockscreen surface + sound service; timer + stopwatch controllable from notifications - World-clock city picker; analog Glance widget (`AnalogClockGlanceWidget` + `AnalogClockWidgetProvider` receiver) - Assistant `intents/` (`SetAlarm` / `SetTimer`) wired to the same schedulers as the UI-**Architecture / data-flow:** `ui/` tab pages → `platform/ClockViewModel` (+ `ClockUiContract`) → `data/ClockRepository` over Room; scheduling via `platform/AlarmScheduler` → `AlarmReceiver` → `AlarmActivity` + `service/AlarmSoundService`, re-armed by `BootReceiver`. Timer/stopwatch actions arrive from notifications via `*ActionReceiver`s.-**Entry points + reading order:** `Route` (alarm/timer/stopwatch/world-clock tabs) → `MainActivity.kt` → `Navigation.kt` → `ui/ClockTabs.kt` → `platform/ClockViewModel.kt` → `platform/AlarmScheduler.kt`.+**Architecture / data-flow:** `ui/` tab pages (phone: five sibling tabs — clock face / world clock / alarms / timer / stopwatch — with a horizontal swipe on the content region switching between the clock-face, world-clock and alarm routes only, the bottom bar staying still) → `platform/ClockViewModel` (+ `ClockUiContract`) → `data/ClockRepository` over Room; scheduling via `platform/AlarmScheduler` → `AlarmReceiver` → `AlarmActivity` + `service/AlarmSoundService`, re-armed by `BootReceiver`. Timer/stopwatch actions arrive from notifications via `*ActionReceiver`s.+**Entry points + reading order:** `Route` (clock-face/world-clock/alarm swipe group plus timer/stopwatch tabs) → `MainActivity.kt` → `Navigation.kt` → `ui/ClockTabs.kt` → `platform/ClockViewModel.kt` → `platform/AlarmScheduler.kt`. ## One APK, two form factors (phone + watch) This module is the single Clock APK for phones and watches: same@@ -76,9 +76,11 @@ same way — `platform/BootReceiver` (phone) and ### service/ — alarm sound - com/vayunmathur/clock/service/AlarmSoundService.kt ### ui/ + ui/components/ + ui/dialogs/ — tab pages and controls-- com/vayunmathur/clock/ui/ClockTabs.kt+- com/vayunmathur/clock/ui/ClockTabs.kt — five route tabs; `CLOCK_SWIPE_PAGES` (clock face, world clock, alarms) is the swipe-between-routes group on its content region - com/vayunmathur/clock/ui/ClockPage.kt - com/vayunmathur/clock/ui/ClockScreen.kt+- com/vayunmathur/clock/ui/WorldClockPage.kt+- com/vayunmathur/clock/ui/WorldClockScreen.kt - com/vayunmathur/clock/ui/AlarmPage.kt - com/vayunmathur/clock/ui/AlarmScreen.kt - com/vayunmathur/clock/ui/AlarmSettingsPage.kt
clock/src/main/java/com/vayunmathur/clock/Navigation.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/Navigation.kt b/clock/src/main/java/com/vayunmathur/clock/Navigation.ktindex b192302bfe..5acb4e7e26 100644--- a/clock/src/main/java/com/vayunmathur/clock/Navigation.kt+++ b/clock/src/main/java/com/vayunmathur/clock/Navigation.kt@@ -12,17 +12,18 @@ fun Navigation( clockViewModel: ClockViewModel, initialRoute: Route?, ) {- // A tab deep link (Alarm/Clock/Timer/Stopwatch) is the start destination- // itself; any other initial route (dialog/settings) is pushed over the- // default Alarm tab so back returns to a tab.+ // A tab deep link (Alarm/Clock/WorldClock/Timer/Stopwatch) is the start+ // destination itself; any other initial route (dialog/settings) is+ // pushed over the default Alarm tab so back returns to a tab. val startTab = when (initialRoute) { is Route.Clock -> Route.Clock+ is Route.WorldClock -> Route.WorldClock is Route.Timer -> Route.Timer is Route.Stopwatch -> Route.Stopwatch else -> Route.Alarm } val pushedRoute = when (initialRoute) {- is Route.Alarm, is Route.Clock, is Route.Timer, is Route.Stopwatch, null -> null+ is Route.Alarm, is Route.Clock, is Route.WorldClock, is Route.Timer, is Route.Stopwatch, null -> null else -> initialRoute } val backStack = rememberNavBackStack<Route>(listOfNotNull(startTab, pushedRoute).distinct())
clock/src/main/java/com/vayunmathur/clock/Route.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/Route.kt b/clock/src/main/java/com/vayunmathur/clock/Route.ktindex 901a02fd5f..10b4fa9746 100644--- a/clock/src/main/java/com/vayunmathur/clock/Route.kt+++ b/clock/src/main/java/com/vayunmathur/clock/Route.kt@@ -4,15 +4,23 @@ import com.vayunmathur.library.util.NavKey import kotlinx.datetime.LocalTime import kotlinx.serialization.Serializable -/** Navigation destinations for the clock app: sibling tab routes and their dialogs. */+/**+ * Navigation destinations for the clock app: sibling tab routes and their+ * dialogs. [Clock], [WorldClock] and [Alarm] form the swipeable sibling+ * group (see `ClockTabs`); [Timer] and [Stopwatch] are sibling tabs outside+ * that group.+ */ @Serializable sealed interface Route : NavKey { /** The alarm tab destination. */ @Serializable data object Alarm : Route- /** The world-clock tab destination. */+ /** The main clock-face tab destination. */ @Serializable data object Clock : Route+ /** The world-clock tab destination. */+ @Serializable+ data object WorldClock : Route /** The timer tab destination. */ @Serializable data object Timer : Route
clock/src/main/java/com/vayunmathur/clock/platform/ClockUiContract.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/platform/ClockUiContract.kt b/clock/src/main/java/com/vayunmathur/clock/platform/ClockUiContract.ktindex 0422c06823..3fe7bcff18 100644--- a/clock/src/main/java/com/vayunmathur/clock/platform/ClockUiContract.kt+++ b/clock/src/main/java/com/vayunmathur/clock/platform/ClockUiContract.kt@@ -9,7 +9,7 @@ import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Instant /**- * The UI contract between [ClockViewModel] and the four tabs.+ * The UI contract between [ClockViewModel] and the tabs. * * Screens take a state value plus an actions interface rather than the ViewModel itself, so * they can be rendered by a `@Preview` — which is what the store listing images are@@ -51,7 +51,7 @@ interface AlarmActions { /** One city on the world-clock list, with its zone already resolved from the city name. */ data class WorldClock(val city: String, val zone: TimeZone) -/** Everything the clock tab draws. */+/** Everything the clock face and world-clock tabs draw. */ data class ClockUiState( /** * The current instant, as a getter so the tick is read inside the header and the individual
clock/src/main/java/com/vayunmathur/clock/ui/ClockPage.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/ClockPage.kt b/clock/src/main/java/com/vayunmathur/clock/ui/ClockPage.ktindex 672ff6e1da..7b040b04fc 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/ClockPage.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/ClockPage.kt@@ -2,46 +2,29 @@ package com.vayunmathur.clock.ui import android.text.format.DateFormat import androidx.compose.runtime.Composable-import androidx.compose.runtime.collectAsState-import androidx.compose.runtime.getValue import androidx.compose.runtime.remember-import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.platform.LocalContext-import com.vayunmathur.clock.Route import com.vayunmathur.clock.platform.ClockUiState-import com.vayunmathur.clock.platform.ClockViewModel-import com.vayunmathur.clock.platform.WorldClock-import com.vayunmathur.clock.platform.WorldClockCities-import com.vayunmathur.library.util.DataStoreUtils-import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.ui.rememberClock-import kotlinx.coroutines.launch import kotlinx.datetime.TimeZone import kotlin.time.Instant -/** Binds [ClockViewModel] to the stateless [ClockScreen]. */+/** Binds the local time source to the stateless main clock face ([ClockScreen]). */ @Composable-fun ClockPage(backStack: NavBackStack<Route>, ds: DataStoreUtils, clockViewModel: ClockViewModel) {+fun ClockPage() { val context = LocalContext.current- val scope = rememberCoroutineScope()- // The clock tab shows seconds in the header and minutes in the rows, so it ticks once a- // second - not on the ViewModel's 100ms stopwatch flow, which this used to share. A getter- // rather than a value so the tick reaches only the labels that display it.+ // The clock face shows seconds, so it ticks once a second — not on the+ // ViewModel's 100ms stopwatch flow. A getter rather than a value so the+ // tick reaches only the labels that display it. val clock = rememberClock() val now = remember(clock) { { Instant.fromEpochMilliseconds(clock()) } }- val cities by clockViewModel.cities.collectAsState()- val selectedCities by WorldClockCities.flow(ds).collectAsState(listOf()) ClockScreen(- backStack = backStack,- state = ClockUiState(- now = now,- zone = TimeZone.currentSystemDefault(),- is24Hour = DateFormat.is24HourFormat(context),- worldClocks = selectedCities.mapNotNull { city ->- cities?.get(city)?.let { WorldClock(city, TimeZone.of(it)) }- },- ),- onReorder = { reordered -> scope.launch { WorldClockCities.set(ds, reordered) } },+ state =+ ClockUiState(+ now = now,+ zone = TimeZone.currentSystemDefault(),+ is24Hour = DateFormat.is24HourFormat(context),+ ), ) }
clock/src/main/java/com/vayunmathur/clock/ui/ClockScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/ClockScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/ClockScreen.ktindex ef67f80167..2fc8818b77 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/ClockScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/ClockScreen.kt@@ -1,98 +1,52 @@ package com.vayunmathur.clock.ui import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.itemsIndexed-import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffect-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.shadow-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.hapticfeedback.HapticFeedbackType-import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.vayunmathur.clock.R-import com.vayunmathur.clock.Route import com.vayunmathur.clock.platform.ClockUiState-import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DateString import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.FloatingActionButton-import com.vayunmathur.library.ui.IconAdd-import com.vayunmathur.library.ui.IconDragHandle import com.vayunmathur.library.ui.LazyListScaffold-import com.vayunmathur.library.ui.ListItem-import com.vayunmathur.library.ui.ListItemDefaults import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.ReorderableItem import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.animatedDp-import com.vayunmathur.library.ui.draggableHandle-import com.vayunmathur.library.ui.rememberReorderableLazyListState-import com.vayunmathur.library.util.NavBackStack import kotlinx.datetime.toLocalDateTime /**- * The clock tab, with no dependency on the ViewModel so it can be rendered from a+ * The main clock face, with no dependency on the ViewModel so it can be rendered from a * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.+ * World clocks live on their own sibling page ([WorldClockScreen]). */ @OptIn(ExperimentalMaterial3Api::class) @Composable-fun ClockScreen(- backStack: NavBackStack<Route>,- state: ClockUiState,- onReorder: (List<String>) -> Unit = {},-) {- val haptics = LocalHapticFeedback.current- val listState = rememberLazyListState()- var localClocks by remember { mutableStateOf(state.worldClocks) }- var hasDragged by remember { mutableStateOf(false) }-- val reorderState = rememberReorderableLazyListState(listState) { from, to ->- if (from.index in localClocks.indices && to.index in localClocks.indices) {- localClocks = localClocks.toMutableList().apply { add(to.index, removeAt(from.index)) }- hasDragged = true- haptics.performHapticFeedback(HapticFeedbackType.SegmentFrequentTick)- }- }-- LaunchedEffect(state.worldClocks) {- if (!reorderState.isAnyItemDragging) localClocks = state.worldClocks- }- LaunchedEffect(reorderState.isAnyItemDragging) {- if (!reorderState.isAnyItemDragging && hasDragged) {- onReorder(localClocks.map { it.city })- hasDragged = false- }- }-- LazyListScaffold(floatingActionButton = {- FloatingActionButton({- backStack.add(Route.SelectTimeZonesDialog)- }) { IconAdd() }- }, state = listState, verticalArrangement = Arrangement.spacedBy(4.dp)) {+fun ClockScreen(state: ClockUiState) {+ LazyListScaffold(verticalArrangement = Arrangement.spacedBy(4.dp)) { item { val is24h = state.is24Hour val time = state.now().toLocalDateTime(state.zone)- Row(Modifier.fillParentMaxWidth(), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.Bottom) {+ Row(+ Modifier.fillParentMaxWidth(),+ horizontalArrangement = Arrangement.Center,+ verticalAlignment = Alignment.Bottom,+ ) { Text(DateString.timeSecondsNumeric(time.time, is24h), style = MaterialTheme.typography.displayLarge) if (!is24h) { Spacer(Modifier.width(8.dp)) Text(- if (time.time.hour >= 12) stringResource(R.string.time_pm) else stringResource(R.string.time_am),- style = MaterialTheme.typography.displayMedium+ if (time.time.hour >=+ 12+ ) {+ stringResource(R.string.time_pm)+ } else {+ stringResource(R.string.time_am)+ },+ style = MaterialTheme.typography.displayMedium, ) } }@@ -101,38 +55,5 @@ fun ClockScreen( val time = state.now().toLocalDateTime(state.zone) Text(DateString.dateWeekdayNoYear(time.date), Modifier.fillParentMaxWidth(), textAlign = TextAlign.Center) }- itemsIndexed(localClocks, key = { _, worldClock -> worldClock.city }) { index, worldClock ->- val timeHere = state.now().toLocalDateTime(worldClock.zone)- val is24h = state.is24Hour- val amPm = if (is24h) "" else if (timeHere.time.hour >= 12) stringResource(R.string.time_pm) else stringResource(R.string.time_am)- ReorderableItem(reorderState, key = worldClock.city, modifier = Modifier.fillParentMaxWidth().animateItem()) { isDragging ->- val elevation = animatedDp(if (isDragging) 6.dp else 0.dp)- Card(Modifier.fillMaxWidth().shadow(elevation, MaterialTheme.shapes.medium)) {- ListItem({ Text(worldClock.city) }, trailingContent = {- Row(verticalAlignment = Alignment.CenterVertically) {- Text(DateString.timeNumeric(timeHere.time, is24h) + amPm)- if (localClocks.size > 1) {- // Drag handle demoted from IconButton: not a- // button — draggableHandle owns the gesture.- Box(- modifier = Modifier.size(48.dp).draggableHandle(- reorderState,- key = worldClock.city,- index = index,- onDragStarted = {- haptics.performHapticFeedback(HapticFeedbackType.GestureThresholdActivate)- },- onDragStopped = {- haptics.performHapticFeedback(HapticFeedbackType.GestureEnd)- },- ),- contentAlignment = Alignment.Center,- ) { IconDragHandle(tint = MaterialTheme.colorScheme.onSurfaceVariant) }- }- }- }, colors = ListItemDefaults.colors(containerColor = Color.Transparent))- }- }- } } }
clock/src/main/java/com/vayunmathur/clock/ui/ClockTabs.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/ClockTabs.kt b/clock/src/main/java/com/vayunmathur/clock/ui/ClockTabs.ktindex c0ccb09281..3c3ab19881 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/ClockTabs.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/ClockTabs.kt@@ -1,6 +1,9 @@ package com.vayunmathur.clock.ui +import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.vayunmathur.clock.R import com.vayunmathur.clock.Route@@ -10,22 +13,39 @@ import com.vayunmathur.clock.ui.dialogs.NewTimerDialog import com.vayunmathur.clock.ui.dialogs.SelectTimeZonesDialog import com.vayunmathur.library.ui.IconAccessTime import com.vayunmathur.library.ui.IconAlarm+import com.vayunmathur.library.ui.IconGlobe import com.vayunmathur.library.ui.IconHourglass import com.vayunmathur.library.ui.IconTimer import com.vayunmathur.library.ui.RouteTab import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.ui.dialog.TimePickerDialogContent+import com.vayunmathur.library.ui.swipeBetweenRoutes import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.library.util.DialogPage import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.SiblingPage+import com.vayunmathur.library.util.navigateToSiblingOffset /**- * The four bottom-nav tabs as sibling [Route] destinations: the route-backed- * [TabbedPagerScaffold] owns the chrome and resets the stack on tab select,- * while [MainNavigation] hosted in its content slot renders the tab on top- * (and any dialog/settings destination pushed over it, with no tab selected).+ * The swipeable phone Clock pages, in swipe order: the main clock face,+ * world clock and alarms. A horizontal swipe on the content region moves+ * between exactly these three sibling routes; [Route.Timer] and+ * [Route.Stopwatch] are sibling tabs outside the group, so a swipe while+ * either is on top does nothing.+ */+internal val CLOCK_SWIPE_PAGES: List<Route> = listOf(Route.Clock, Route.WorldClock, Route.Alarm)++/**+ * The five bottom-nav tabs as sibling [Route] destinations: the route-backed+ * [TabbedPagerScaffold] owns the chrome (bottom bar / rail, rendered outside+ * the navigation host so it stays still while content transitions) and resets+ * the stack on tab select, while [MainNavigation] hosted in its content slot+ * renders the tab on top (and any dialog/settings destination pushed over it,+ * with no tab selected). The content region carries+ * [swipeBetweenRoutes] over [CLOCK_SWIPE_PAGES]: a swipe and a bottom-bar+ * tap between the clock face, world clock and alarms are the same sibling+ * switch (replace, never push), so Back and deep links see the real route. */ @Composable fun ClockTabs(@@ -33,47 +53,60 @@ fun ClockTabs( ds: DataStoreUtils, clockViewModel: ClockViewModel, ) {- val tabs = listOf<RouteTab<Route>>(- RouteTab(Route.Alarm, stringResource(R.string.label_alarm)) { IconAlarm() },- RouteTab(Route.Clock, stringResource(R.string.app_name)) { IconAccessTime() },- RouteTab(Route.Timer, stringResource(R.string.label_timer)) { IconHourglass() },- RouteTab(Route.Stopwatch, stringResource(R.string.channel_stopwatch_name)) { IconTimer() },- )+ val tabs =+ listOf<RouteTab<Route>>(+ RouteTab(Route.Clock, stringResource(R.string.app_name)) { IconAccessTime() },+ RouteTab(Route.WorldClock, stringResource(R.string.label_world_clock)) { IconGlobe() },+ RouteTab(Route.Alarm, stringResource(R.string.label_alarm)) { IconAlarm() },+ RouteTab(Route.Timer, stringResource(R.string.label_timer)) { IconHourglass() },+ RouteTab(Route.Stopwatch, stringResource(R.string.channel_stopwatch_name)) { IconTimer() },+ ) TabbedPagerScaffold(backStack = backStack, tabs = tabs) {- MainNavigation(backStack) {- entry<Route.Alarm>(metadata = SiblingPage()) {- AlarmPage(backStack, clockViewModel)- }- entry<Route.Clock>(metadata = SiblingPage()) {- ClockPage(backStack, ds, clockViewModel)- }- entry<Route.Timer>(metadata = SiblingPage()) {- TimerPage(clockViewModel)- }- entry<Route.Stopwatch>(metadata = SiblingPage()) {- StopwatchPage(clockViewModel)- }- entry<Route.AlarmSettings> {- AlarmSettingsPage(backStack, ds)- }- entry<Route.SelectTimeZonesDialog>(metadata = DialogPage()) {- SelectTimeZonesDialog(backStack, ds, clockViewModel)- }- entry<Route.NewTimerDialog>(metadata = DialogPage()) { key ->- NewTimerDialog(backStack, clockViewModel, key.lengthSeconds, key.message)- }- entry<Route.NewAlarmDialog>(metadata = DialogPage()) { key ->- NewAlarmDialog(- backStack = backStack,- clockViewModel = clockViewModel,- initialHour = key.hour,- initialMinutes = key.minutes,- initialMessage = key.message,- initialDays = key.days,- )- }- entry<Route.AlarmSetTimeDialog>(metadata = DialogPage()) {- TimePickerDialogContent(backStack, "alarm_set_time_${it.id}", it.time)+ Box(+ Modifier+ .fillMaxSize()+ .swipeBetweenRoutes { offset ->+ backStack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, offset)+ },+ ) {+ MainNavigation(backStack) {+ entry<Route.Clock>(metadata = SiblingPage()) {+ ClockPage()+ }+ entry<Route.WorldClock>(metadata = SiblingPage()) {+ WorldClockPage(backStack, ds, clockViewModel)+ }+ entry<Route.Alarm>(metadata = SiblingPage()) {+ AlarmPage(backStack, clockViewModel)+ }+ entry<Route.Timer>(metadata = SiblingPage()) {+ TimerPage(clockViewModel)+ }+ entry<Route.Stopwatch>(metadata = SiblingPage()) {+ StopwatchPage(clockViewModel)+ }+ entry<Route.AlarmSettings> {+ AlarmSettingsPage(backStack, ds)+ }+ entry<Route.SelectTimeZonesDialog>(metadata = DialogPage()) {+ SelectTimeZonesDialog(backStack, ds, clockViewModel)+ }+ entry<Route.NewTimerDialog>(metadata = DialogPage()) { key ->+ NewTimerDialog(backStack, clockViewModel, key.lengthSeconds, key.message)+ }+ entry<Route.NewAlarmDialog>(metadata = DialogPage()) { key ->+ NewAlarmDialog(+ backStack = backStack,+ clockViewModel = clockViewModel,+ initialHour = key.hour,+ initialMinutes = key.minutes,+ initialMessage = key.message,+ initialDays = key.days,+ )+ }+ entry<Route.AlarmSetTimeDialog>(metadata = DialogPage()) {+ TimePickerDialogContent(backStack, "alarm_set_time_${it.id}", it.time)+ } } } }
clock/src/main/java/com/vayunmathur/clock/ui/WorldClockPage.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockPage.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockPage.ktnew file mode 100644index 0000000000..8cdda8a34e--- /dev/null+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockPage.kt@@ -0,0 +1,52 @@+package com.vayunmathur.clock.ui++import android.text.format.DateFormat+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.ui.platform.LocalContext+import com.vayunmathur.clock.Route+import com.vayunmathur.clock.platform.ClockUiState+import com.vayunmathur.clock.platform.ClockViewModel+import com.vayunmathur.clock.platform.WorldClock+import com.vayunmathur.clock.platform.WorldClockCities+import com.vayunmathur.library.ui.rememberClock+import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.library.util.NavBackStack+import kotlinx.coroutines.launch+import kotlinx.datetime.TimeZone+import kotlin.time.Instant++/** Binds [ClockViewModel] to the stateless [WorldClockScreen]. */+@Composable+fun WorldClockPage(+ backStack: NavBackStack<Route>,+ ds: DataStoreUtils,+ clockViewModel: ClockViewModel,+) {+ val context = LocalContext.current+ val scope = rememberCoroutineScope()+ // World-clock rows show minutes, ticking once a second via the shared+ // clock getter (see ClockPage).+ val clock = rememberClock()+ val now = remember(clock) { { Instant.fromEpochMilliseconds(clock()) } }+ val cities by clockViewModel.cities.collectAsState()+ val selectedCities by WorldClockCities.flow(ds).collectAsState(listOf())++ WorldClockScreen(+ backStack = backStack,+ state =+ ClockUiState(+ now = now,+ zone = TimeZone.currentSystemDefault(),+ is24Hour = DateFormat.is24HourFormat(context),+ worldClocks =+ selectedCities.mapNotNull { city ->+ cities?.get(city)?.let { WorldClock(city, TimeZone.of(it)) }+ },+ ),+ onReorder = { reordered -> scope.launch { WorldClockCities.set(ds, reordered) } },+ )+}
clock/src/main/java/com/vayunmathur/clock/ui/WorldClockScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockScreen.ktnew file mode 100644index 0000000000..ad22a8c455--- /dev/null+++ b/clock/src/main/java/com/vayunmathur/clock/ui/WorldClockScreen.kt@@ -0,0 +1,135 @@+package com.vayunmathur.clock.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.lazy.itemsIndexed+import androidx.compose.foundation.lazy.rememberLazyListState+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.shadow+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.hapticfeedback.HapticFeedbackType+import androidx.compose.ui.platform.LocalHapticFeedback+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.clock.R+import com.vayunmathur.clock.Route+import com.vayunmathur.clock.platform.ClockUiState+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.DateString+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.FloatingActionButton+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconDragHandle+import com.vayunmathur.library.ui.LazyListScaffold+import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.ListItemDefaults+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.ReorderableItem+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.animatedDp+import com.vayunmathur.library.ui.draggableHandle+import com.vayunmathur.library.ui.rememberReorderableLazyListState+import com.vayunmathur.library.util.NavBackStack+import kotlinx.datetime.toLocalDateTime++/**+ * The world-clock list, with no dependency on the ViewModel so it can be rendered from a+ * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun WorldClockScreen(+ backStack: NavBackStack<Route>,+ state: ClockUiState,+ onReorder: (List<String>) -> Unit = {},+) {+ val haptics = LocalHapticFeedback.current+ val listState = rememberLazyListState()+ var localClocks by remember { mutableStateOf(state.worldClocks) }+ var hasDragged by remember { mutableStateOf(false) }++ val reorderState =+ rememberReorderableLazyListState(listState) { from, to ->+ if (from.index in localClocks.indices && to.index in localClocks.indices) {+ localClocks = localClocks.toMutableList().apply { add(to.index, removeAt(from.index)) }+ hasDragged = true+ haptics.performHapticFeedback(HapticFeedbackType.SegmentFrequentTick)+ }+ }++ LaunchedEffect(state.worldClocks) {+ if (!reorderState.isAnyItemDragging) localClocks = state.worldClocks+ }+ LaunchedEffect(reorderState.isAnyItemDragging) {+ if (!reorderState.isAnyItemDragging && hasDragged) {+ onReorder(localClocks.map { it.city })+ hasDragged = false+ }+ }++ LazyListScaffold(floatingActionButton = {+ FloatingActionButton({+ backStack.add(Route.SelectTimeZonesDialog)+ }) { IconAdd() }+ }, state = listState, verticalArrangement = Arrangement.spacedBy(4.dp)) {+ itemsIndexed(localClocks, key = { _, worldClock -> worldClock.city }) { index, worldClock ->+ val timeHere = state.now().toLocalDateTime(worldClock.zone)+ val is24h = state.is24Hour+ val amPm =+ if (is24h) {+ ""+ } else if (timeHere.time.hour >=+ 12+ ) {+ stringResource(R.string.time_pm)+ } else {+ stringResource(R.string.time_am)+ }+ ReorderableItem(+ reorderState,+ key = worldClock.city,+ modifier = Modifier.fillParentMaxWidth().animateItem(),+ ) { isDragging ->+ val elevation = animatedDp(if (isDragging) 6.dp else 0.dp)+ Card(Modifier.fillMaxWidth().shadow(elevation, MaterialTheme.shapes.medium)) {+ ListItem({ Text(worldClock.city) }, trailingContent = {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Text(DateString.timeNumeric(timeHere.time, is24h) + amPm)+ if (localClocks.size > 1) {+ // Drag handle demoted from IconButton: not a+ // button — draggableHandle owns the gesture.+ Box(+ modifier =+ Modifier.size(48.dp).draggableHandle(+ reorderState,+ key = worldClock.city,+ index = index,+ onDragStarted = {+ haptics.performHapticFeedback(+ HapticFeedbackType.GestureThresholdActivate,+ )+ },+ onDragStopped = {+ haptics.performHapticFeedback(HapticFeedbackType.GestureEnd)+ },+ ),+ contentAlignment = Alignment.Center,+ ) { IconDragHandle(tint = MaterialTheme.colorScheme.onSurfaceVariant) }+ }+ }+ }, colors = ListItemDefaults.colors(containerColor = Color.Transparent))+ }+ }+ }+ }+}
clock/src/main/res/values/strings.xml
diff --git a/clock/src/main/res/values/strings.xml b/clock/src/main/res/values/strings.xmlindex 6738b8cb46..632f6a3a9c 100644--- a/clock/src/main/res/values/strings.xml+++ b/clock/src/main/res/values/strings.xml@@ -7,6 +7,8 @@ <string name="label_alarm">Alarm</string> <!-- Bottom nav + TopAppBar title for Timer screen. Noun. Also fallback timer name --> <string name="label_timer">Timer</string>+ <!-- Bottom nav + TopAppBar title for World clock screen. Noun. -->+ <string name="label_world_clock">World clock</string> <!-- AlarmPage: empty state --> <!-- Empty state CTA button to create first alarm. Verb. -->
clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt
diff --git a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.ktindex cd26cc1bd6..b21172caee 100644--- a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt+++ b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt@@ -22,6 +22,7 @@ import com.vayunmathur.clock.ui.dialogs.SelectTimeZonesDialogContent import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.dialog.TimePickerDialogContent import com.vayunmathur.library.ui.IconAccessTime+import com.vayunmathur.library.ui.IconGlobe import com.vayunmathur.library.ui.IconAlarm import com.vayunmathur.library.ui.IconHourglass import com.vayunmathur.library.ui.IconTimer@@ -57,7 +58,8 @@ private val MORNING = Instant.parse("2026-02-13T17:41:09Z") * Store listing images for `:clock`, rendered from Compose previews instead of from an * instrumented test on a device. See `common-conventions-preview-metadata`. *- * One image per bottom-nav tab, in tab order. Each preview needs @PreviewTest as well as+ * One image per bottom-nav tab, in tab order (clock face, world clock,+ * alarms, timer, stopwatch). Each preview needs @PreviewTest as well as * @Preview (@Preview alone renders in Studio but is not collected as a screenshot test), * previews must be members of a class rather than top-level functions, and listing order * comes from the function names — `Preview1…`, `Preview2…`. All three failure modes@@ -67,7 +69,7 @@ private val MORNING = Instant.parse("2026-02-13T17:41:09Z") * app's real tabs — not bare screens, so the bottom bar users see is in the shot. * Only the selected tab is literal. *- * Coverage beyond the four tabs: `AlarmSettings` from its stateless+ * Coverage beyond the five tabs: `AlarmSettings` from its stateless * [AlarmSettingsContent] slice, and the four dialog routes * (`SelectTimeZonesDialog`, `NewTimerDialog`, `NewAlarmDialog`, * `AlarmSetTimeDialog`) from their stateless dialog contents, all on phone.@@ -77,37 +79,44 @@ private val MORNING = Instant.parse("2026-02-13T17:41:09Z") class MetadataPreviews { @PreviewTest- @Preview(name = "1-alarm", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "1-clock", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview1Alarm() {+ fun Preview1Clock() { ChromePreview(selectedTab = 0) } @PreviewTest- @Preview(name = "2-clock", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "2-world-clock", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview2Clock() {+ fun Preview2WorldClock() { ChromePreview(selectedTab = 1) } @PreviewTest- @Preview(name = "3-timer", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "3-alarm", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview3Timer() {+ fun Preview3Alarm() { ChromePreview(selectedTab = 2) } @PreviewTest- @Preview(name = "4-stopwatch", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "4-timer", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview4Stopwatch() {+ fun Preview4Timer() { ChromePreview(selectedTab = 3) } @PreviewTest- @Preview(name = "5-alarm-settings", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "5-stopwatch", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview5AlarmSettings() {+ fun Preview5Stopwatch() {+ ChromePreview(selectedTab = 4)+ }++ @PreviewTest+ @Preview(name = "6-alarm-settings", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview6AlarmSettings() { DynamicTheme(darkTheme = true) { AlarmSettingsContent( ringtoneUri = null,@@ -124,9 +133,9 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "6-select-time-zones-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "7-select-time-zones-dialog", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview6SelectTimeZonesDialog() {+ fun Preview7SelectTimeZonesDialog() { DynamicTheme(darkTheme = true) { SelectTimeZonesDialogContent( options = listOf(@@ -147,9 +156,9 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "7-new-timer-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "8-new-timer-dialog", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview7NewTimerDialog() {+ fun Preview8NewTimerDialog() { DynamicTheme(darkTheme = true) { NewTimerDialogContent( initialName = "Tea",@@ -161,9 +170,9 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "8-new-alarm-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "9-new-alarm-dialog", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview8NewAlarmDialog() {+ fun Preview9NewAlarmDialog() { DynamicTheme(darkTheme = true) { NewAlarmDialogContent( initialHour = 7,@@ -177,9 +186,9 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "9-alarm-set-time-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "10-alarm-set-time-dialog", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview9AlarmSetTimeDialog() {+ fun Preview10AlarmSetTimeDialog() { DynamicTheme(darkTheme = true) { // The shared time picker dispatches through LocalNavResultRegistry, // so hand it a throwaway one like AlarmContent — no preview confirms.@@ -218,7 +227,17 @@ private fun AlarmContent() { @Composable private fun ClockContent() { ClockScreen(- backStack = rememberNavBackStack<Route>(Route.Clock),+ state = ClockUiState(+ now = { MORNING },+ zone = TimeZone.of("America/Los_Angeles"),+ ),+ )+}++@Composable+private fun WorldClockContent() {+ WorldClockScreen(+ backStack = rememberNavBackStack<Route>(Route.WorldClock), state = ClockUiState( now = { MORNING }, zone = TimeZone.of("America/Los_Angeles"),@@ -264,7 +283,7 @@ private fun StopwatchContent() { /** * The app's real tab chrome around preview screen content: the same * [TabbedPagerScaffold] in [TabStyle.BottomNav] that `ClockTabs` uses, with the- * same four tabs in the same order — the pager starts on [selectedTab], so the+ * same five tabs in the same order — the pager starts on [selectedTab], so the * bar highlights the shown screen. Labels/icons are the app's own. */ @Composable@@ -273,8 +292,9 @@ private fun ChromePreview(selectedTab: Int) { // TabbedPagerScaffold hosts a HorizontalPager (no NavDisplay), so no // dispatcher owner is needed — unlike MainNavigation-based chrome. val tabs = listOf(- PagerTab("Alarm", { IconAlarm() }) { AlarmContent() }, PagerTab("Clock", { IconAccessTime() }) { ClockContent() },+ PagerTab("World clock", { IconGlobe() }) { WorldClockContent() },+ PagerTab("Alarm", { IconAlarm() }) { AlarmContent() }, PagerTab("Timer", { IconHourglass() }) { TimerContent() }, PagerTab("Stopwatch", { IconTimer() }) { StopwatchContent() }, )
clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDeepTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDeepTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDeepTest.ktindex 5dbb784a92..bb2cfaface 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDeepTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDeepTest.kt@@ -26,7 +26,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -/** ClockPage with real selected cities, and its add-city navigation. */+/** WorldClockPage with real selected cities, and its add-city navigation. */ @RunWith(AndroidJUnit4::class) class ClockPageDeepTest { @Before fun setUp() = FakeAndroidKeyStore.install()@@ -37,7 +37,7 @@ class ClockPageDeepTest { private fun vm() = ClockViewModel(ctx as Application, ClockRepository.get(ctx)) private fun ds() = DataStoreUtils.getInstance(ctx) - @Test fun clockPageShowsSelectedWorldClocksAndAddNavigates() {+ @Test fun worldClockPageShowsSelectedWorldClocksAndAddNavigates() { val vm = vm() // Terminal signal: the cities StateFlow emits its asset-parsed map. awaitValueBlocking(vm.cities) { it != null }@@ -47,7 +47,7 @@ class ClockPageDeepTest { runBlocking { WorldClockCities.set(ds(), picked) } val backStack = NavBackStack(arrayOf<Route>(Route.Alarm))- rule.setContent { ClockPage(backStack, ds(), vm) }+ rule.setContent { WorldClockPage(backStack, ds(), vm) } rule.waitForIdle() for (city in picked) rule.onNodeWithText(city).assertExists()
clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDragTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDragTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDragTest.ktindex f1f60ee264..265f4ea4e7 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDragTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPageDragTest.kt@@ -30,7 +30,7 @@ import kotlin.test.Test import kotlin.test.assertEquals /**- * ClockPage's reorder wiring: dragging a city in the bound page persists the+ * WorldClockPage's reorder wiring: dragging a city in the bound page persists the * new order through WorldClockCities (the stateless screen's own drag is * covered in ScreensDirectTest; this is the page-level DataStore half). */@@ -61,7 +61,7 @@ class ClockPageDragTest { runBlocking { WorldClockCities.set(ds, listOf("Tokyo", "London")) } val vm = ClockViewModel(ctx, ClockRepository.get(ctx)) val stack = NavBackStack(arrayOf<Route>(Route.Alarm))- rule.setContent { ClockPage(stack, ds, vm) }+ rule.setContent { WorldClockPage(stack, ds, vm) } // Cities load from the VM's asset parse; wait for both rows to compose. rule.awaitSemantics("both world-clock rows composed") { rule.onAllNodesWithContentDescription("Reorder").fetchSemanticsNodes().size == 2
clock/src/test/java/com/vayunmathur/clock/ui/ClockPagesUiTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPagesUiTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPagesUiTest.ktindex b391a1b173..adfe8931d8 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ClockPagesUiTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ClockPagesUiTest.kt@@ -17,6 +17,7 @@ import com.vayunmathur.clock.platform.AlarmActivity import com.vayunmathur.clock.platform.ClockViewModel import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.navigateToSiblingOffset import kotlinx.serialization.json.Json import org.junit.Before import org.junit.Rule@@ -43,7 +44,7 @@ class ClockPagesUiTest { @Test fun routeSerializationRoundTrips() { val routes: List<Route> = listOf(- Route.Alarm, Route.Clock, Route.Timer, Route.Stopwatch,+ Route.Alarm, Route.Clock, Route.WorldClock, Route.Timer, Route.Stopwatch, Route.AlarmSettings, Route.SelectTimeZonesDialog, Route.NewTimerDialog(300, "tea"), Route.NewAlarmDialog(7, 30, "wake", arrayListOf(1, 3), false), )@@ -62,8 +63,9 @@ class ClockPagesUiTest { val backStack = NavBackStack(arrayOf<Route>(Route.Stopwatch)) rule.setContent { ClockTabs(backStack, ds(), vm()) } rule.waitForIdle()- // Bottom navigation labels for the four tabs are composed.+ // Bottom navigation labels for the five tabs are composed. rule.onNodeWithText("Alarm").assertExists()+ rule.onNodeWithText("World clock").assertExists() assertEquals(listOf(Route.Stopwatch), backStack.backStack) } @@ -97,11 +99,36 @@ class ClockPagesUiTest { @Test fun clockPageBindsViewModel() {- val backStack = NavBackStack(arrayOf<Route>(Route.Alarm))- rule.setContent { ClockPage(backStack, ds(), vm()) }+ rule.setContent { ClockPage() } rule.waitForIdle() } + @Test+ fun worldClockPageBindsViewModel() {+ val backStack = NavBackStack(arrayOf<Route>(Route.WorldClock))+ rule.setContent { WorldClockPage(backStack, ds(), vm()) }+ rule.waitForIdle()+ }++ @Test+ fun swipePagesReplaceWithinTrioOnly() {+ // The swipe group is exactly the clock face, world clock and alarms,+ // in that order: stepping replaces the top (never pushes), stops at+ // either end, and does not move off Timer/Stopwatch.+ val stack = NavBackStack(arrayOf<Route>(Route.Clock))+ stack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, 1)+ assertEquals(listOf(Route.WorldClock), stack.backStack)+ stack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, 1)+ assertEquals(listOf(Route.Alarm), stack.backStack)+ stack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, 1)+ assertEquals(listOf(Route.Alarm), stack.backStack)+ stack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, -1)+ assertEquals(listOf(Route.WorldClock), stack.backStack)+ val timerStack = NavBackStack(arrayOf<Route>(Route.Timer))+ timerStack.navigateToSiblingOffset(CLOCK_SWIPE_PAGES, 1)+ assertEquals(listOf(Route.Timer), timerStack.backStack)+ }+ @Test fun mainActivityLaunches() { val controller = Robolectric.buildActivity(MainActivity::class.java, Intent(Intent.ACTION_MAIN)).create().start().resume()
clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.ktindex 1847aa791a..553ed22050 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt@@ -125,13 +125,13 @@ class ClockScreensUiTest { // --- ClockScreen --- @Test- fun clockScreenShowsTimeAndCities() {+ fun worldClockScreenShowsCities() { val now = Clock.System.now() val state = ClockUiState( now = { now }, zone = TimeZone.UTC, is24Hour = true, worldClocks = listOf(WorldClock("Tokyo", TimeZone.of("Asia/Tokyo")), WorldClock("London", TimeZone.of("Europe/London"))), )- rule.setContent { ClockScreen(backStack(), state) }+ rule.setContent { WorldClockScreen(backStack(), state) } rule.onNodeWithText("Tokyo").assertIsDisplayed() rule.onNodeWithText("London").assertIsDisplayed() }@@ -141,7 +141,7 @@ class ClockScreensUiTest { // 2024-01-01 15:00 UTC val now = kotlin.time.Instant.fromEpochMilliseconds(1704121200000L) val state = ClockUiState(now = { now }, zone = TimeZone.UTC, is24Hour = false)- rule.setContent { ClockScreen(backStack(), state) }+ rule.setContent { ClockScreen(state) } rule.onAllNodesWithText("PM", substring = true).onFirst().assertIsDisplayed() }
clock/src/test/java/com/vayunmathur/clock/ui/ScreensDirectTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ScreensDirectTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ScreensDirectTest.ktindex 42b85b1443..8e15bf92c9 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ScreensDirectTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ScreensDirectTest.kt@@ -167,7 +167,7 @@ class ScreensDirectTest { assertTrue(stack.backStack.last() is Route.AlarmSettings, stack.backStack.toString()) } - @Test fun clockScreenRowsAndAddRoute() {+ @Test fun worldClockScreenRowsAndAddRoute() { val stack = NavBackStack(arrayOf<Route>(Route.Alarm)) val now = Clock.System.now() val state = ClockUiState(@@ -178,7 +178,7 @@ class ScreensDirectTest { WorldClock("London", TimeZone.of("Europe/London")), ), )- rule.setContent { ClockScreen(stack, state) }+ rule.setContent { WorldClockScreen(stack, state) } rule.waitForIdle() rule.onNodeWithText("Tokyo").assertExists() rule.onNodeWithText("London").assertExists()@@ -186,7 +186,7 @@ class ScreensDirectTest { assertTrue(stack.backStack.last() is Route.SelectTimeZonesDialog, stack.backStack.toString()) } - @Test fun clockScreenDragReordersCities() {+ @Test fun worldClockScreenDragReordersCities() { val stack = NavBackStack(arrayOf<Route>(Route.Alarm)) val now = Clock.System.now() var reordered: List<String>? = null@@ -198,7 +198,7 @@ class ScreensDirectTest { WorldClock("London", TimeZone.of("Europe/London")), ), )- rule.setContent { ClockScreen(stack, state) { reordered = it } }+ rule.setContent { WorldClockScreen(stack, state) { reordered = it } } rule.waitForIdle() // Long-press the first city's drag handle and pull it below the second. val handles = rule.onAllNodesWithContentDescription("Reorder").fetchSemanticsNodes()
metadata_data/photos/clock/phone/1.png
diff --git a/metadata_data/photos/clock/phone/1.png b/metadata_data/photos/clock/phone/1.pngindex 40331ed631..b033b25512 100644Binary files a/metadata_data/photos/clock/phone/1.png and b/metadata_data/photos/clock/phone/1.png differ
metadata_data/photos/clock/phone/10.png
diff --git a/metadata_data/photos/clock/phone/10.png b/metadata_data/photos/clock/phone/10.pngnew file mode 100644index 0000000000..5425ba908dBinary files /dev/null and b/metadata_data/photos/clock/phone/10.png differ
metadata_data/photos/clock/phone/2.png
diff --git a/metadata_data/photos/clock/phone/2.png b/metadata_data/photos/clock/phone/2.pngindex f535786992..006be74d8f 100644Binary files a/metadata_data/photos/clock/phone/2.png and b/metadata_data/photos/clock/phone/2.png differ
metadata_data/photos/clock/phone/3.png
diff --git a/metadata_data/photos/clock/phone/3.png b/metadata_data/photos/clock/phone/3.pngindex d35ec218b0..dc7b01e764 100644Binary files a/metadata_data/photos/clock/phone/3.png and b/metadata_data/photos/clock/phone/3.png differ
metadata_data/photos/clock/phone/4.png
diff --git a/metadata_data/photos/clock/phone/4.png b/metadata_data/photos/clock/phone/4.pngindex e7f1867b0c..62db5e7a85 100644Binary files a/metadata_data/photos/clock/phone/4.png and b/metadata_data/photos/clock/phone/4.png differ
metadata_data/photos/clock/phone/5.png
diff --git a/metadata_data/photos/clock/phone/5.png b/metadata_data/photos/clock/phone/5.pngnew file mode 100644index 0000000000..69e21c9d8bBinary files /dev/null and b/metadata_data/photos/clock/phone/5.png differ
metadata_data/photos/clock/phone/6.png
diff --git a/metadata_data/photos/clock/phone/6.png b/metadata_data/photos/clock/phone/6.pngnew file mode 100644index 0000000000..7f7b16943fBinary files /dev/null and b/metadata_data/photos/clock/phone/6.png differ
metadata_data/photos/clock/phone/7.png
diff --git a/metadata_data/photos/clock/phone/7.png b/metadata_data/photos/clock/phone/7.pngnew file mode 100644index 0000000000..19c4786c83Binary files /dev/null and b/metadata_data/photos/clock/phone/7.png differ
metadata_data/photos/clock/phone/8.png
diff --git a/metadata_data/photos/clock/phone/8.png b/metadata_data/photos/clock/phone/8.pngnew file mode 100644index 0000000000..510bc505fcBinary files /dev/null and b/metadata_data/photos/clock/phone/8.png differ
metadata_data/photos/clock/phone/9.png
diff --git a/metadata_data/photos/clock/phone/9.png b/metadata_data/photos/clock/phone/9.pngnew file mode 100644index 0000000000..aca1ebd736Binary files /dev/null and b/metadata_data/photos/clock/phone/9.png differ
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 c3d8bbed68..ffe2b8a2be 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 568750582e..40e9daccf2 100644Binary files a/metadata_data/photos/clock/wear/2.png and b/metadata_data/photos/clock/wear/2.png differ