auto: screenshot previews from scratch with stateless splits
- Commit
7018d18d07573b660a3f5abac05a4d9bf6cdc251- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-25 23:32 UTC (1 month ago)
- Parents
7aac61c
Diff
auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt b/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.ktindex 3594e7da6f..bc91ce58df 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/AutoScreen.kt@@ -66,6 +66,21 @@ fun AutoScreen(viewModel: AutoViewModel, onPairing: () -> Unit, onPinnedApps: () inputDropped = viewModel.inputDropped.collectAsStateWithLifecycle().value, musicBytesCaptured = viewModel.musicBytesCaptured.collectAsStateWithLifecycle().value, )+ AutoScreen(state = state, session = session, onPairing = onPairing, onPinnedApps = onPinnedApps)+}++/**+ * Stateless status screen: connection row, pin-picker entry, session stats and+ * consent cards. The ViewModel overload collects the flows and delegates here;+ * metadata previews render this directly with literals.+ */+@Composable+fun AutoScreen(+ state: AutoConnectionState,+ session: SessionSnapshot,+ onPairing: () -> Unit,+ onPinnedApps: () -> Unit,+) { val scrollBehavior = appBarScrollBehavior() AppScaffold( title = stringResource(R.string.app_name),
auto/src/main/java/com/vayunmathur/auto/ui/PairingScreen.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/PairingScreen.kt b/auto/src/main/java/com/vayunmathur/auto/ui/PairingScreen.ktindex ab7b0da0a2..c7bd4632b9 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/PairingScreen.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/PairingScreen.kt@@ -75,6 +75,36 @@ fun PairingScreen(viewModel: PairingViewModel, onNavigateBack: () -> Unit) { if (granted) WifiDirectConnector.start(context) }, )+ PairingScreen(+ usbState = usbState,+ usbLabel = usbLabel,+ wirelessState = wirelessState,+ roleHeld = roleHeld,+ selected = selected,+ onNavigateBack = onNavigateBack,+ onUsbRetry = remember(context) { { UsbConnector.retryPermission(context) } },+ onWirelessSearch = requestNearby,+ onWirelessCancel = remember { { WifiDirectConnector.cancel() } },+ )+}++/**+ * Stateless pairing screen: USB + wireless rows, transport and role rows. The+ * ViewModel overload collects the flows and wires the connector calls, then+ * delegates here; metadata previews render this directly with literals.+ */+@Composable+fun PairingScreen(+ usbState: UsbSessionState,+ usbLabel: String?,+ wirelessState: WirelessSessionState,+ roleHeld: Boolean,+ selected: TransportKind?,+ onNavigateBack: () -> Unit,+ onUsbRetry: () -> Unit,+ onWirelessSearch: () -> Unit,+ onWirelessCancel: () -> Unit,+) { val scrollBehavior = appBarScrollBehavior() AppScaffold( title = stringResource(R.string.pairing_title),@@ -90,13 +120,13 @@ fun PairingScreen(viewModel: PairingViewModel, onNavigateBack: () -> Unit) { UsbRow( state = usbState, label = usbLabel,- onRetry = remember(context) { { UsbConnector.retryPermission(context) } },+ onRetry = onUsbRetry, modifier = Modifier.padding(top = 16.dp), ) WirelessRow( state = wirelessState,- onSearch = requestNearby,- onCancel = remember { { WifiDirectConnector.cancel() } },+ onSearch = onWirelessSearch,+ onCancel = onWirelessCancel, modifier = Modifier.padding(top = 16.dp), ) TransportRow(selected = selected, modifier = Modifier.padding(top = 16.dp))
auto/src/main/java/com/vayunmathur/auto/ui/PinnedAppsScreen.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/PinnedAppsScreen.kt b/auto/src/main/java/com/vayunmathur/auto/ui/PinnedAppsScreen.ktindex 2af938bec0..1cefeae0fe 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/PinnedAppsScreen.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/PinnedAppsScreen.kt@@ -54,6 +54,29 @@ fun PinnedAppsScreen( viewModel.consumeRejected() } }+ PinnedAppsScreen(+ onNavigateBack = onNavigateBack,+ rows = rows,+ onToggle = { viewModel.toggle(it) },+ onMoveUp = { viewModel.moveUp(it) },+ onMoveDown = { viewModel.moveDown(it) },+ )+}++/**+ * Stateless pin picker: every row with a check plus up/down reorder. The+ * ViewModel overload collects the flows and reports dock-full rejections on+ * the shared snackbar host, then delegates here; metadata previews render+ * this directly with literals.+ */+@Composable+fun PinnedAppsScreen(+ onNavigateBack: () -> Unit,+ rows: List<PinnedAppRow>,+ onToggle: (String) -> Unit,+ onMoveUp: (String) -> Unit,+ onMoveDown: (String) -> Unit,+) { val scrollBehavior = appBarScrollBehavior() AppScaffold( title = stringResource(R.string.pinned_apps_title),@@ -74,9 +97,9 @@ fun PinnedAppsScreen( items(rows, key = { it.app.id }) { row -> PinnedAppRowCard( row = row,- onToggle = { viewModel.toggle(row.app.id) },- onMoveUp = { viewModel.moveUp(row.app.id) },- onMoveDown = { viewModel.moveDown(row.app.id) },+ onToggle = { onToggle(row.app.id) },+ onMoveUp = { onMoveUp(row.app.id) },+ onMoveDown = { onMoveDown(row.app.id) }, ) } }
auto/src/screenshotTest/kotlin/com/vayunmathur/auto/ui/MetadataPreviews.kt
diff --git a/auto/src/screenshotTest/kotlin/com/vayunmathur/auto/ui/MetadataPreviews.kt b/auto/src/screenshotTest/kotlin/com/vayunmathur/auto/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..eef6faca49--- /dev/null+++ b/auto/src/screenshotTest/kotlin/com/vayunmathur/auto/ui/MetadataPreviews.kt@@ -0,0 +1,183 @@+package com.vayunmathur.auto.ui++import android.content.ComponentName+import androidx.compose.runtime.Composable+import androidx.compose.ui.tooling.preview.Preview+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.auto.domain.PinnedAppRow+import com.vayunmathur.auto.platform.AudioSinkState+import com.vayunmathur.auto.platform.AudioSinkStatus+import com.vayunmathur.auto.platform.AutoConnectionState+import com.vayunmathur.auto.platform.DiscoveredApp+import com.vayunmathur.auto.platform.NowPlayingInfo+import com.vayunmathur.auto.platform.VideoInfo+import com.vayunmathur.auto.protocol.AudioGain+import com.vayunmathur.auto.protocol.AudioSinkRole+import com.vayunmathur.auto.protocol.TransportKind+import com.vayunmathur.auto.protocol.UsbSessionState+import com.vayunmathur.auto.protocol.VideoFocus+import com.vayunmathur.auto.protocol.WirelessSessionState+import com.vayunmathur.auto.protocol.gal.AudioFocusState+import com.vayunmathur.library.ui.DynamicTheme++/** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */+private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"++/**+ * Store-listing images for `:auto`, rendered from Compose previews instead of an+ * instrumented test on a device (projection needs a car or the Desktop Head Unit+ * loopback and cannot run here).+ *+ * `./gradlew :auto:metadata` renders these and copies the PNGs into+ * `metadata_data/photos/auto/`, where `release.sh` picks them up.+ *+ * Each preview must carry @PreviewTest as well as @Preview and be a member of a class+ * (not a top-level function) or the screenshot engine silently skips it. Everything is+ * a literal so the output is reproducible from a clean checkout. The car templates+ * (AppScreen/LauncherRoot) are out of scope: their geometry comes from the head unit.+ */+class MetadataPreviews {++ private val session = SessionSnapshot(+ video = VideoInfo(width = 1280, height = 720, frameRate = 60, configIndex = 0),+ focusMode = "VIDEO_FOCUS_PROJECTED",+ videoFocus = VideoFocus.PROJECTED,+ audioFocus = AudioFocusState.AUDIO_FOCUS_STATE_GAIN,+ inputAllowed = true,+ framesSent = 12_480L,+ acksSeen = 12_475L,+ ackMismatches = 0L,+ encodedFps = 59.8,+ ackFps = 59.7,+ // Null so the live-age rows render their dash placeholder instead of a+ // wall-clock-dependent value; keeps the render deterministic.+ lastAckAt = null,+ lastAckSeq = 214L,+ avgEncodeLatencyUs = 8_400L,+ encoderDrains = 312L,+ surfaceValid = true,+ credentialDaysLeft = 320L,+ sessionStartedAt = null,+ nowPlaying = NowPlayingInfo(+ title = "Midnight Drive",+ artist = "Night Signals",+ playing = true,+ positionMs = 95_000L,+ durationMs = 214_000L,+ ),+ threadsPosted = 3L,+ messagesPosted = 11L,+ repliesReceived = 2L,+ sinkStatus = mapOf(+ AudioSinkRole.SYSTEM to AudioSinkStatus(+ role = AudioSinkRole.SYSTEM,+ state = AudioSinkState.STARTED,+ gain = AudioGain.FULL,+ ),+ AudioSinkRole.MEDIA to AudioSinkStatus(+ role = AudioSinkRole.MEDIA,+ state = AudioSinkState.STARTED,+ gain = AudioGain.DUCKED,+ ),+ ),+ audioBytesSent = 4_194_304L,+ micTurns = 5L,+ micAcks = 5L,+ ttsSpoken = 3L,+ touchesInjected = 42L,+ keysInjected = 7L,+ scrollsInjected = 12L,+ inputDropped = 0L,+ musicBytesCaptured = 2_097_152L,+ )++ private val pinnedRows = listOf(+ PinnedAppRow(+ app = DiscoveredApp(+ component = ComponentName(+ "com.vayunmathur.maps",+ "com.vayunmathur.maps.service.car.MapsCarAppService",+ ),+ label = "Maps",+ icon = null,+ categories = emptySet(),+ ),+ rank = 0,+ ),+ PinnedAppRow(+ app = DiscoveredApp(+ component = ComponentName(+ "com.vayunmathur.music",+ "com.vayunmathur.music.service.car.MusicCarAppService",+ ),+ label = "Music",+ icon = null,+ categories = emptySet(),+ ),+ rank = 1,+ ),+ PinnedAppRow(+ app = DiscoveredApp(+ component = ComponentName(+ "com.vayunmathur.communicate",+ "com.vayunmathur.communicate.service.car.CommunicateCarAppService",+ ),+ label = "Communicate",+ icon = null,+ categories = emptySet(),+ ),+ rank = null,+ ),+ )++ @PreviewTest+ @Preview(name = "1-status", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview1Status() {+ DynamicTheme(darkTheme = true) {+ AutoScreen(+ state = AutoConnectionState.Projecting(+ carName = "Demo Head Unit",+ videoFocus = VideoFocus.PROJECTED,+ ),+ session = session,+ onPairing = {},+ onPinnedApps = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "2-pairing", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview2Pairing() {+ DynamicTheme(darkTheme = true) {+ PairingScreen(+ usbState = UsbSessionState.CONNECTED,+ usbLabel = "Demo Head Unit",+ wirelessState = WirelessSessionState.CONNECTED,+ roleHeld = true,+ selected = TransportKind.USB,+ onNavigateBack = {},+ onUsbRetry = {},+ onWirelessSearch = {},+ onWirelessCancel = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "3-pinned-apps", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview3PinnedApps() {+ DynamicTheme(darkTheme = true) {+ PinnedAppsScreen(+ onNavigateBack = {},+ rows = pinnedRows,+ onToggle = {},+ onMoveUp = {},+ onMoveDown = {},+ )+ }+ }+}
metadata_data/photos/auto/phone/1.png
diff --git a/metadata_data/photos/auto/phone/1.png b/metadata_data/photos/auto/phone/1.pngnew file mode 100644index 0000000000..9e05da5ec1Binary files /dev/null and b/metadata_data/photos/auto/phone/1.png differ
metadata_data/photos/auto/phone/2.png
diff --git a/metadata_data/photos/auto/phone/2.png b/metadata_data/photos/auto/phone/2.pngnew file mode 100644index 0000000000..5d0b256739Binary files /dev/null and b/metadata_data/photos/auto/phone/2.png differ
metadata_data/photos/auto/phone/3.png
diff --git a/metadata_data/photos/auto/phone/3.png b/metadata_data/photos/auto/phone/3.pngnew file mode 100644index 0000000000..bd5fe80b06Binary files /dev/null and b/metadata_data/photos/auto/phone/3.png differ