screenshot tests: tablet + wear captures in their correct folders
- Commit
9ba6b2d55393206ed006d164737fb0b8872ba3cf- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-25 17:37 UTC (10 days ago)
- Parents
f7ddda5
Extends the repo's preview-metadata harness to three form factors, goldens committed under metadata_data/photos/<app>/ as phone/, large-tablet/, and wear/ (wear modules carry their own): news gains phone + 1280x800 tablet captures of feed/story (new stateless Content composables with literal fixtures; camera tablet is controls-only with a documented replace-with-hand-capture warning since Layoutlib has no camera); clock/music/weather wear pilots get round 454x454 (+336 square) captures via the same harness with stateless content extractions. All five pilots' metadata + validate tasks green; calculator metadata proves no regression to the existing path. Rollout recipe documented per module (conventions plugin + Content split + MetadataPreviews.kt).
Diff
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex e859e316ee..1c119d748e 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -649,13 +649,19 @@ providers.environmentVariable("SOURCE_DATE_EPOCH").orNull?.let { // Shared deterministic test-await helper: AGP's variant API adds the // shared Kotlin dir to every variant's unit-test component (the AGP 9-// replacement for Android/Kotlin source-set wiring).+// replacement for Android/Kotlin source-set wiring). Unit tests only: the+// screenshotTest host component (Compose preview renders) shares the hostTests+// map but not the unit-test classpath (no compose-ui-test-junit4, no+// Robolectric), so adding the helper there breaks every preview-metadata+// module's `compile*ScreenshotTestKotlin`. extensions.configure<com.android.build.api.variant.ApplicationAndroidComponentsExtension> { onVariants { variant ->- variant.hostTests.values.forEach { hostTest ->- hostTest.sources.kotlin?.addStaticSourceDirectory(- rootDir.resolve("build-logic/shared-test/java").absolutePath,- )+ variant.hostTests.forEach { (name, hostTest) ->+ if (name == "unitTest") {+ hostTest.sources.kotlin?.addStaticSourceDirectory(+ rootDir.resolve("build-logic/shared-test/java").absolutePath,+ )+ } } } }
build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts b/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.ktsindex d5f42e0009..e4148ae705 100644--- a/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts@@ -82,11 +82,19 @@ val previewSourcesDir = File(projectDir, "src/screenshotTest") // task just depended on; `reference/` accumulates across runs (and across plugin versions, // whose filename hashes differ), so it is only a fallback. Reading reference first would // publish stale duplicates alongside the fresh renders.-val referenceDir = File(projectDir, "src/screenshotTestDev/reference")+// The screenshot plugin names its source set, reference dir and output tree after the+// module's test build type (`dev` for apps via common-conventions-app, `debug` — the+// AGP default — for wear modules via common-conventions-wear). Read it here, after the+// module's convention plugin has run, instead of hardcoding `dev`, so the same script+// collects renders for both families.+val screenshotVariant = the<ApplicationExtension>().testBuildType+val screenshotVariantCap = screenshotVariant.replaceFirstChar { it.uppercase() }++val referenceDir = File(projectDir, "src/screenshotTest$screenshotVariantCap/reference") // Lazily derived from the build directory provider: no .get() at // configuration time, so merely configuring the project creates no tasks. val renderedDir = layout.buildDirectory.map {- it.asFile.resolve("outputs/screenshotTest-results/preview/dev/rendered")+ it.asFile.resolve("outputs/screenshotTest-results/preview/$screenshotVariant/rendered") } /**@@ -108,6 +116,9 @@ abstract class CollectPreviewScreenshots : DefaultTask() { @get:Internal abstract val label: Property<String> + /** Bucket for previews that declare no `group` (wear modules default to `wear/`). */+ @get:Internal abstract val defaultBucket: Property<String>+ @TaskAction fun run() { val source = sourceDirs.get().firstOrNull { it.isDirectory && it.walkTopDown().any { f -> f.extension == "png" } }@@ -137,20 +148,24 @@ abstract class CollectPreviewScreenshots : DefaultTask() { val groups = readPreviewGroups(previewSources.get(), label.get()) val dest = destination.get()- dest.deleteRecursively() val valid = buckets.get().toSet()- images.groupBy { png -> groups[functionNameOf(png)] ?: "phone" }.forEach { (bucket, bucketImages) ->+ images.groupBy { png -> groups[functionNameOf(png)] ?: defaultBucket.get() }.forEach { (bucket, bucketImages) -> require(bucket in valid) { "Unknown screenshot bucket \"$bucket\" for ${label.get()} — expected one of ${valid.sorted().joinToString(", ")}" } val bucketDir = File(dest, bucket)+ // Only the buckets this run rendered are replaced. A bucket with no+ // previews this run (e.g. `camera`'s hand-captured `phone/` shots, which+ // no preview can reproduce) is left untouched instead of being wiped+ // along with the destination.+ bucketDir.deleteRecursively() bucketDir.mkdirs() bucketImages.sortedBy { it.name }.forEachIndexed { index, png -> png.copyTo(File(bucketDir, "${index + 1}.png"), overwrite = true) } } logger.lifecycle("Metadata screenshots: ${images.size} image(s) -> $dest")- images.forEach { f -> logger.lifecycle(" ${groups[functionNameOf(f)] ?: "phone"}/${f.name}") }+ images.forEach { f -> logger.lifecycle(" ${groups[functionNameOf(f)] ?: defaultBucket.get()}/${f.name}") } } /** Rendered filenames look like `Preview1Keypad_1-keypad_<hash>_0.png` — the leading segment is the function name. */@@ -208,6 +223,9 @@ tasks.register<CollectPreviewScreenshots>("metadata") { destination.set(screenshotsOut) previewSources.set(previewSourcesDir) buckets.set(screenshotBuckets)+ // Wear modules file their captures under their own module key's `wear/` bucket+ // (metadata_data/photos/<wear-module-key>/wear/), never the phone app's folder.+ defaultBucket.set(if (path.contains("wear")) "wear" else "phone") label.set(path) // Cheap, and the whole point is to refresh the images on demand. outputs.upToDateWhen { false }
build-logic/src/main/kotlin/common-conventions-wear.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts b/build-logic/src/main/kotlin/common-conventions-wear.gradle.ktsindex 675a3984af..4a3994582f 100644--- a/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts@@ -131,6 +131,14 @@ configure<com.android.build.api.dsl.ApplicationExtension> { initWith(getByName("release")) isMinifyEnabled = false isShrinkResources = false+ // Debuggable parity with common-conventions-app's `dev`: the Compose+ // screenshot-test plugin (com.android.compose.screenshot, applied by+ // common-conventions-preview-metadata) only registers its render tasks+ // for a debuggable variant. Wear's test build type stays `debug` (the+ // AGP default, debuggable already), so today's screenshot tasks are the+ // `*DebugScreenshotTest` ones; this keeps `dev` equally capable if the+ // test build type ever moves to it, and `dev` never ships.+ isDebuggable = true matchingFallbacks += listOf("release") } }
camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex 69d02de65f..a4e5802c1f 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -9,7 +9,7 @@ _Install: ./install camera (dev by default)._ - Entry files: MainActivity.kt (no Route.kt — `Route` is inline, single-screen app) - Deps: :library:ml - Metadata: metadata_data/camera.md (present)-- Rust: yes / screenshotTest: hand-committed+- Rust: yes / screenshotTest: hybrid (phone hand-captured; wide controls preview-rendered) ## Overview **Purpose:** The most featureful open-source camera app — usable as the system camera and from the lockscreen. 100% offline.
camera/build.gradle.kts
diff --git a/camera/build.gradle.kts b/camera/build.gradle.ktsindex e79eb1e4e4..5548719c61 100644--- a/camera/build.gradle.kts+++ b/camera/build.gradle.kts@@ -1,10 +1,13 @@ plugins { id("common-conventions-app")- // No metadata convention. The viewfinder is the screen, and Layoutlib cannot open a- // camera, so there is nothing a Compose preview could capture — with no SurfaceRequest- // the preview falls back to a black Box. The listing images are hand-captured and- // committed under metadata_data/photos/camera/phone/, which the release build- // picks up into graphics/phone-screenshots.+ // Listing images are hybrid. The viewfinder is the screen, and Layoutlib cannot+ // open a camera, so the phone images are hand-captured on a real device and+ // committed under metadata_data/photos/camera/phone/ (the release build picks+ // them up into graphics/phone-screenshots). The wide *controls* layout is real+ // preview-renderable UI, so src/screenshotTest captures it at expanded width+ // into the large-tablet bucket; the collect task only replaces buckets a run+ // rendered, so the hand-captured phone bucket survives `:camera:metadata`.+ id("common-conventions-preview-metadata") } launcherIcon {
camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt
diff --git a/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..d64c13bfbd--- /dev/null+++ b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt@@ -0,0 +1,94 @@+package com.vayunmathur.camera.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.tooling.preview.Preview+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.camera.platform.CameraMode+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"++/** Desktop-wide (1280dp >= 840dp): the wide controls layout (shutter beside modes). */+private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240"++/**+ * Listing-image renders for `:camera`'s *wide* layout, from Compose previews.+ *+ * Camera stays a hybrid: Layoutlib cannot open a camera, so the live viewfinder can+ * never be preview-rendered (with no SurfaceRequest it is a black box). The phone+ * listing images are therefore still hand-captured on a real device into+ * `metadata_data/photos/camera/phone/`. What a preview *can* render honestly is the+ * part that actually changes with width — the wide controls layout+ * ([CameraWideLayout] with the real [CameraShutterPane] and [CameraModesPane]) —+ * so this file captures exactly that at expanded width, collected into+ * `metadata_data/photos/camera/large-tablet/`. The dark pane above the controls is+ * the viewfinder's placeholder, standing where the live preview sits on device;+ * replace the collected PNG with a hand capture from a real tablet before a store+ * submission, exactly as the phone images are produced.+ *+ * `./gradlew :camera:metadata` renders this preview and collects it. The collect+ * task only replaces buckets a run actually rendered, so the hand-captured `phone/`+ * bucket survives it.+ *+ * Rules (same as every other module's MetadataPreviews): order comes from the+ * function names, each preview needs `@PreviewTest` plus a `group`, and previews+ * are class members.+ */+class MetadataPreviews {++ @PreviewTest+ @Preview(name = "1-wide-controls-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)+ @Composable+ fun Preview1WideControlsExpanded() {+ DynamicTheme(darkTheme = true) {+ Column(Modifier.fillMaxSize().background(Color.Black)) {+ // Viewfinder placeholder: the live preview pane (unrenderable in+ // Layoutlib) above the wide controls.+ Box(Modifier.fillMaxWidth().weight(1f))+ CameraWideLayout(+ shutter = {+ CameraShutterPane(+ cameraMode = CameraMode.PHOTO,+ isRecording = false,+ isCapturing = false,+ recordingPaused = false,+ videoSnapshotSupported = false,+ galleryBitmap = null,+ onCaptureResult = null,+ onBurstStart = {},+ onBurstStop = {},+ onCapture = {},+ onPauseResume = {},+ onSnapshot = {},+ onFlipCamera = {},+ onGallery = {},+ iconRotation = 0f,+ )+ },+ modes = {+ CameraModesPane(+ cameraMode = CameraMode.PHOTO,+ isPhotoType = true,+ sloMoSupported = true,+ captureForResult = false,+ onModeSelected = {},+ iconRotation = 0f,+ onPickerChanged = {},+ onSettingsClick = {},+ )+ },+ modifier = Modifier.fillMaxWidth(),+ sideBySide = true,+ )+ }+ }+ }+}
clock-wear/build.gradle.kts
diff --git a/clock-wear/build.gradle.kts b/clock-wear/build.gradle.ktsindex e134ae5656..6fb770e2f6 100644--- a/clock-wear/build.gradle.kts+++ b/clock-wear/build.gradle.kts@@ -1,5 +1,9 @@ plugins { id("common-conventions-wear")+ // Listing screenshots come from Compose previews (src/screenshotTest), not from an+ // instrumented test on a device. Renders land in this module's own+ // metadata_data/photos/<wear-module-key>/wear/ bucket.+ id("common-conventions-preview-metadata") } launcherIcon {
clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.ktindex 8d6c9f1ac7..6aee39f229 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearAlarmsScreen.kt@@ -39,6 +39,28 @@ fun WearAlarmsScreen(store: WearClockStore, onBack: () -> Unit, onOpenAlarm: (Lo val context = LocalContext.current val scope = rememberCoroutineScope() val nowMillis = remember(persisted) { System.currentTimeMillis() }+ WearAlarmsContent(+ persisted = persisted,+ nowMillis = nowMillis,+ onRequestSync = { scope.launch { WearLinkBridge.requestSync(context) } },+ onBack = onBack,+ onOpenAlarm = onOpenAlarm,+ )+}++/**+ * Stateless alarms body behind [WearAlarmsScreen]: snapshot and instant are+ * parameters, so Compose previews (src/screenshotTest) render literal fixtures+ * at a fixed time with no store or phone.+ */+@Composable+internal fun WearAlarmsContent(+ persisted: com.vayunmathur.clock.wear.data.WearClockPersisted,+ nowMillis: Long,+ onRequestSync: () -> Unit,+ onBack: () -> Unit,+ onOpenAlarm: (Long) -> Unit,+) { ScalingLazyColumn { item { Text(@@ -70,7 +92,7 @@ fun WearAlarmsScreen(store: WearClockStore, onBack: () -> Unit, onOpenAlarm: (Lo } item { Chip(- onClick = { scope.launch { WearLinkBridge.requestSync(context) } },+ onClick = onRequestSync, label = { Text(stringResource(R.string.wear_request_sync), maxLines = 1) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),
clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearHomeScreen.kt
diff --git a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearHomeScreen.kt b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearHomeScreen.ktindex 0886389712..7eb61b0759 100644--- a/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearHomeScreen.kt+++ b/clock-wear/src/main/java/com/vayunmathur/clock/wear/ui/WearHomeScreen.kt@@ -34,6 +34,15 @@ fun WearHomeScreen(onOpen: (WearRoute) -> Unit) { delay(1_000) } }+ WearHomeContent(nowMillis = nowMillis, onOpen = onOpen)+}++/**+ * Stateless home body behind [WearHomeScreen]: the instant is a parameter, so+ * Compose previews (src/screenshotTest) render a fixed, reproducible time.+ */+@Composable+internal fun WearHomeContent(nowMillis: Long, onOpen: (WearRoute) -> Unit) { val local = remember(nowMillis) { Instant.fromEpochMilliseconds(nowMillis) .toLocalDateTime(TimeZone.currentSystemDefault())
clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt
diff --git a/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt b/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..f91ddc04f0--- /dev/null+++ b/clock-wear/src/screenshotTest/kotlin/com/vayunmathur/clock/wear/ui/MetadataPreviews.kt@@ -0,0 +1,97 @@+package com.vayunmathur.clock.wear.ui++import androidx.compose.foundation.background+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.draw.clip+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.ui.tooling.preview.Preview+import androidx.wear.compose.material.MaterialTheme+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.clock.wear.data.WearClockPersisted+import com.vayunmathur.clock.wear.domain.ArmedAlarmRecord+import com.vayunmathur.clock.wear.domain.WearClockAlarm+import com.vayunmathur.clock.wear.domain.WearClockSnapshot++/** Round watch, 454x454px class (227dp at 320dpi) — Pixel Watch / Galaxy Watch size. */+private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"++/** Small square watch, 336px class. */+private const val SQUARE = "spec:width=192dp,height=192dp,dpi=280"++/** Fixed preview instant: 2026-11-25 14:41 UTC. Times render from this, never the wall clock. */+private const val FIXED_NOW_MILLIS = 1795617660000L++/**+ * Store listing images for `:clock:wear`, rendered from Compose previews instead of+ * from an instrumented test on a device.+ *+ * `./gradlew :clock:wear:metadata` renders these and copies the PNGs into+ * `metadata_data/photos/clock-wear/wear/` — the wear module's own bucket, not the+ * phone Clock app's folder — where the release build picks them up.+ *+ * Rules (same as every other module's MetadataPreviews): order comes from the+ * function names, each preview needs `@PreviewTest` plus `group = "wear"`, previews+ * are class members, and everything is a literal fixture — the instant is fixed so+ * the clock faces never drift. Layoutlib renders a rectangular canvas, so round+ * previews clip to a circle: what is visible is what a round watch shows.+ */+class MetadataPreviews {++ @PreviewTest+ @Preview(name = "1-home-round", device = ROUND, group = "wear")+ @Composable+ fun Preview1HomeRound() {+ RoundPreview { WearHomeContent(nowMillis = FIXED_NOW_MILLIS, onOpen = {}) }+ }++ @PreviewTest+ @Preview(name = "2-alarms-round", device = ROUND, group = "wear")+ @Composable+ fun Preview2AlarmsRound() {+ RoundPreview {+ WearAlarmsContent(+ persisted = WearClockPersisted(+ snapshot = WearClockSnapshot(+ alarms = listOf(+ WearClockAlarm(alarmId = 1, label = "Wake up", hour = 7, minute = 0, daysMask = 0b0111110, enabled = true),+ WearClockAlarm(alarmId = 2, label = "Gym", hour = 17, minute = 30, daysMask = 0, enabled = true),+ WearClockAlarm(alarmId = 3, label = "Weekend", hour = 9, minute = 15, daysMask = 0b1000001, enabled = false),+ ),+ ),+ armedRecords = listOf(+ ArmedAlarmRecord(alarmId = 1, nextTriggerMillis = FIXED_NOW_MILLIS + 3_600_000L, exact = true),+ ArmedAlarmRecord(alarmId = 2, nextTriggerMillis = FIXED_NOW_MILLIS + 7_200_000L, exact = true),+ ),+ ),+ nowMillis = FIXED_NOW_MILLIS,+ onRequestSync = {},+ onBack = {},+ onOpenAlarm = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "3-home-square", device = SQUARE, group = "wear")+ @Composable+ fun Preview3HomeSquare() {+ MaterialTheme {+ Box(Modifier.fillMaxSize().background(MaterialTheme.colors.background)) {+ WearHomeContent(nowMillis = FIXED_NOW_MILLIS, onOpen = {})+ }+ }+ }+}++/** Round-watch framing: wear screens are round-safe by design; clip so the render is too. */+@Composable+private fun RoundPreview(content: @Composable () -> Unit) {+ MaterialTheme {+ Box(+ Modifier.fillMaxSize().clip(CircleShape).background(MaterialTheme.colors.background),+ ) { content() }+ }+}
metadata_data/photos/camera/large-tablet/1.png
diff --git a/metadata_data/photos/camera/large-tablet/1.png b/metadata_data/photos/camera/large-tablet/1.pngnew file mode 100644index 0000000000..018d143eadBinary files /dev/null and b/metadata_data/photos/camera/large-tablet/1.png differ
metadata_data/photos/clock-wear/wear/1.png
diff --git a/metadata_data/photos/clock-wear/wear/1.png b/metadata_data/photos/clock-wear/wear/1.pngnew file mode 100644index 0000000000..e716b843cbBinary files /dev/null and b/metadata_data/photos/clock-wear/wear/1.png differ
metadata_data/photos/clock-wear/wear/2.png
diff --git a/metadata_data/photos/clock-wear/wear/2.png b/metadata_data/photos/clock-wear/wear/2.pngnew file mode 100644index 0000000000..4fc2d5eff9Binary files /dev/null and b/metadata_data/photos/clock-wear/wear/2.png differ
metadata_data/photos/clock-wear/wear/3.png
diff --git a/metadata_data/photos/clock-wear/wear/3.png b/metadata_data/photos/clock-wear/wear/3.pngnew file mode 100644index 0000000000..f4ea0edb40Binary files /dev/null and b/metadata_data/photos/clock-wear/wear/3.png differ
metadata_data/photos/music-wear/wear/1.png
diff --git a/metadata_data/photos/music-wear/wear/1.png b/metadata_data/photos/music-wear/wear/1.pngnew file mode 100644index 0000000000..7941586df9Binary files /dev/null and b/metadata_data/photos/music-wear/wear/1.png differ
metadata_data/photos/music-wear/wear/2.png
diff --git a/metadata_data/photos/music-wear/wear/2.png b/metadata_data/photos/music-wear/wear/2.pngnew file mode 100644index 0000000000..9c362d565dBinary files /dev/null and b/metadata_data/photos/music-wear/wear/2.png differ
metadata_data/photos/news/large-tablet/1.png
diff --git a/metadata_data/photos/news/large-tablet/1.png b/metadata_data/photos/news/large-tablet/1.pngnew file mode 100644index 0000000000..7c9713f901Binary files /dev/null and b/metadata_data/photos/news/large-tablet/1.png differ
metadata_data/photos/news/large-tablet/2.png
diff --git a/metadata_data/photos/news/large-tablet/2.png b/metadata_data/photos/news/large-tablet/2.pngnew file mode 100644index 0000000000..48f518d576Binary files /dev/null and b/metadata_data/photos/news/large-tablet/2.png differ
metadata_data/photos/news/phone/1.png
diff --git a/metadata_data/photos/news/phone/1.png b/metadata_data/photos/news/phone/1.pngnew file mode 100644index 0000000000..0914643969Binary files /dev/null and b/metadata_data/photos/news/phone/1.png differ
metadata_data/photos/news/phone/2.png
diff --git a/metadata_data/photos/news/phone/2.png b/metadata_data/photos/news/phone/2.pngnew file mode 100644index 0000000000..9bfa5db700Binary files /dev/null and b/metadata_data/photos/news/phone/2.png differ
metadata_data/photos/news/phone/3.png
diff --git a/metadata_data/photos/news/phone/3.png b/metadata_data/photos/news/phone/3.pngnew file mode 100644index 0000000000..b3bab00f56Binary files /dev/null and b/metadata_data/photos/news/phone/3.png differ
metadata_data/photos/weather-wear/wear/1.png
diff --git a/metadata_data/photos/weather-wear/wear/1.png b/metadata_data/photos/weather-wear/wear/1.pngnew file mode 100644index 0000000000..70df0e4a38Binary files /dev/null and b/metadata_data/photos/weather-wear/wear/1.png differ
music-wear/build.gradle.kts
diff --git a/music-wear/build.gradle.kts b/music-wear/build.gradle.ktsindex 1e06c2f6a5..dbedc7a9d2 100644--- a/music-wear/build.gradle.kts+++ b/music-wear/build.gradle.kts@@ -1,5 +1,9 @@ plugins { id("common-conventions-wear")+ // Listing screenshots come from Compose previews (src/screenshotTest), not from an+ // instrumented test on a device. Renders land in this module's own+ // metadata_data/photos/<wear-module-key>/wear/ bucket.+ id("common-conventions-preview-metadata") } launcherIcon {
music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.ktindex 3217b8c393..eef8e378b8 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt+++ b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt@@ -69,7 +69,28 @@ fun WearHomeScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { WearPageLoader(store, page) val pages by store.pages.collectAsState() val playback by store.playback.collectAsState()- val snapshot = pages[page]+ WearHomeContent(+ page = page,+ snapshot = pages[page],+ playback = playback,+ onEnqueueOp = store::enqueueOp,+ onRoute = onRoute,+ )+}++/**+ * Stateless home body behind [WearHomeScreen]: page snapshot and playback state are+ * parameters, so Compose previews (src/screenshotTest) render literal fixtures with+ * no store or phone.+ */+@Composable+internal fun WearHomeContent(+ page: WearPageId,+ snapshot: WearPageSnapshot?,+ playback: WearPlaybackState,+ onEnqueueOp: (WearMusicOp) -> Unit,+ onRoute: (WearRoute) -> Unit,+) { // Hoisted: ScalingLazyColumn's scope lambda is not a @Composable context. val appName = stringResource(R.string.app_name) val nowPlayingLabel = stringResource(R.string.wear_now_playing)@@ -88,7 +109,7 @@ fun WearHomeScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { wearNavItem(searchLabel, WearRoute.Search, onRoute) wearNavItem(settingsLabel, WearRoute.Settings, onRoute) item { WearTitle(songsLabel) }- wearTrackItems(store, page, snapshot, playback, onRoute)+ wearTrackItems(onEnqueueOp, page, snapshot, playback, onRoute) } } @@ -158,7 +179,7 @@ internal fun ScalingLazyListScope.wearBackItem(onBack: () -> Unit) { * note (never a blank list); an empty one is the synced-empty note. */ internal fun ScalingLazyListScope.wearTrackItems(- store: WearMusicStore,+ onEnqueueOp: (WearMusicOp) -> Unit, page: WearPageId, snapshot: WearPageSnapshot?, playback: WearPlaybackState,@@ -178,7 +199,7 @@ internal fun ScalingLazyListScope.wearTrackItems( label = { Text((if (track.id == playback.trackId) "▶ " else "") + track.title, maxLines = 1) }, secondaryLabel = { Text(track.artist, maxLines = 1) }, onClick = {- store.enqueueOp(+ onEnqueueOp( WearMusicOp( WearOpKind.PLAY_TRACKS, trackIds = snapshot.tracks.map { it.id },
music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.ktindex b4756c068d..c583492f7e 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt+++ b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt@@ -24,6 +24,20 @@ import com.vayunmathur.music.wear.domain.WearOpKind @Composable fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { val playback by store.playback.collectAsState()+ WearNowPlayingContent(playback = playback, onOp = store::enqueueOp, onRoute = onRoute)+}++/**+ * Stateless now-playing body behind [WearNowPlayingScreen]: playback state and the+ * op sink are parameters, so Compose previews (src/screenshotTest) render a literal+ * fixture with no store or phone.+ */+@Composable+internal fun WearNowPlayingContent(+ playback: com.vayunmathur.music.wear.domain.WearPlaybackState,+ onOp: (WearMusicOp) -> Unit,+ onRoute: (WearRoute) -> Unit,+) { ScalingLazyColumn(state = rememberScalingLazyListState()) { item { WearTitle(stringResource(R.string.wear_now_playing)) } item {@@ -58,7 +72,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { Chip( label = { Text(stringResource(R.string.wear_seek_back), maxLines = 1) }, onClick = {- store.enqueueOp(WearMusicOp(WearOpKind.SEEK, positionMs = (playback.positionMs - 30_000L).coerceAtLeast(0L)))+ onOp(WearMusicOp(WearOpKind.SEEK, positionMs = (playback.positionMs - 30_000L).coerceAtLeast(0L))) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),@@ -68,7 +82,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { Chip( label = { Text(stringResource(R.string.wear_seek_forward), maxLines = 1) }, onClick = {- store.enqueueOp(WearMusicOp(WearOpKind.SEEK, positionMs = playback.positionMs + 30_000L))+ onOp(WearMusicOp(WearOpKind.SEEK, positionMs = playback.positionMs + 30_000L)) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),@@ -77,7 +91,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { item { Chip( label = { Text(stringResource(R.string.wear_previous), maxLines = 1) },- onClick = { store.enqueueOp(WearMusicOp(WearOpKind.SKIP_PREVIOUS)) },+ onClick = { onOp(WearMusicOp(WearOpKind.SKIP_PREVIOUS)) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )@@ -90,7 +104,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { maxLines = 1, ) },- onClick = { store.enqueueOp(WearMusicOp(WearOpKind.TOGGLE_PLAY_PAUSE)) },+ onClick = { onOp(WearMusicOp(WearOpKind.TOGGLE_PLAY_PAUSE)) }, colors = ChipDefaults.primaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )@@ -98,7 +112,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { item { Chip( label = { Text(stringResource(R.string.wear_next), maxLines = 1) },- onClick = { store.enqueueOp(WearMusicOp(WearOpKind.SKIP_NEXT)) },+ onClick = { onOp(WearMusicOp(WearOpKind.SKIP_NEXT)) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )@@ -111,7 +125,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { maxLines = 1, ) },- onClick = { store.enqueueOp(WearMusicOp(WearOpKind.TOGGLE_SHUFFLE)) },+ onClick = { onOp(WearMusicOp(WearOpKind.TOGGLE_SHUFFLE)) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )@@ -119,7 +133,7 @@ fun WearNowPlayingScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { item { Chip( label = { Text(stringResource(R.string.wear_repeat), maxLines = 1) },- onClick = { store.enqueueOp(WearMusicOp(WearOpKind.CYCLE_REPEAT)) },+ onClick = { onOp(WearMusicOp(WearOpKind.CYCLE_REPEAT)) }, colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )
music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.ktindex d4bd6c0b66..2f90911e10 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt+++ b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt@@ -49,7 +49,7 @@ fun WearSearchScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) { if (query.length < 2) { item { WearNote(stringResource(R.string.wear_search)) } } else {- wearTrackItems(store, page, pages[page], playback, onRoute)+ wearTrackItems(store::enqueueOp, page, pages[page], playback, onRoute) } wearBackItem { onRoute(WearRoute.Home) } }
music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.ktindex ef660c5d5e..683123d5be 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt+++ b/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt@@ -22,7 +22,7 @@ fun WearTrackListScreen( val playback by store.playback.collectAsState() ScalingLazyColumn(state = rememberScalingLazyListState()) { item { WearTitle(title) }- wearTrackItems(store, page, pages[page], playback, onRoute)+ wearTrackItems(store::enqueueOp, page, pages[page], playback, onRoute) wearBackItem(onBack) } }
music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.kt
diff --git a/music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.kt b/music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..754437f7f0--- /dev/null+++ b/music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.kt@@ -0,0 +1,94 @@+package com.vayunmathur.music.wear.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.tooling.preview.Preview+import androidx.wear.compose.material.MaterialTheme+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.music.wear.domain.WearPageId+import com.vayunmathur.music.wear.domain.WearPageKey+import com.vayunmathur.music.wear.domain.WearPageSnapshot+import com.vayunmathur.music.wear.domain.WearPlaybackState+import com.vayunmathur.music.wear.domain.WearTrack++/** Round watch, 454x454px class (227dp at 320dpi) — Pixel Watch / Galaxy Watch size. */+private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"++/**+ * Store listing images for `:music:wear`, rendered from Compose previews instead of+ * from an instrumented test on a device.+ *+ * `./gradlew :music:wear:metadata` renders these and copies the PNGs into+ * `metadata_data/photos/music-wear/wear/` — the wear module's own bucket, not the+ * phone Music app's folder — where the release build picks them up.+ *+ * Rules (same as every other module's MetadataPreviews): order comes from the+ * function names, each preview needs `@PreviewTest` plus `group = "wear"`, previews+ * are class members, and everything is a literal fixture (a fixed page snapshot and+ * playback state — no store, no phone). Layoutlib renders a rectangular canvas, so+ * round previews clip to a circle: what is visible is what a round watch shows.+ */+class MetadataPreviews {++ @PreviewTest+ @Preview(name = "1-home-round", device = ROUND, group = "wear")+ @Composable+ fun Preview1HomeRound() {+ RoundPreview {+ WearHomeContent(+ page = WearPageId(WearPageKey.HOME),+ snapshot = WearPageSnapshot(+ page = WearPageId(WearPageKey.HOME),+ tracks = listOf(+ WearTrack(id = 1, title = "Midnight Run", artist = "The Night Trains", durationMs = 214_000L),+ WearTrack(id = 2, title = "Harbour Lights", artist = "Ana Sol", durationMs = 187_000L),+ WearTrack(id = 3, title = "Static Bloom", artist = "Field Kit", durationMs = 243_000L),+ ),+ totalCount = 3,+ ),+ playback = fixturePlayback,+ onEnqueueOp = {},+ onRoute = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "2-now-playing-round", device = ROUND, group = "wear")+ @Composable+ fun Preview2NowPlayingRound() {+ RoundPreview {+ WearNowPlayingContent(playback = fixturePlayback, onOp = {}, onRoute = {})+ }+ }+}++private val fixturePlayback = WearPlaybackState(+ trackId = 1,+ title = "Midnight Run",+ artist = "The Night Trains",+ album = "Northbound",+ isPlaying = true,+ positionMs = 62_000L,+ durationMs = 214_000L,+ shuffle = false,+ repeatMode = 0,+ queue = emptyList(),+ queueIndex = 0,+ sourceName = "Library",+)++/** Round-watch framing: wear screens are round-safe by design; clip so the render is too. */+@Composable+private fun RoundPreview(content: @Composable () -> Unit) {+ MaterialTheme {+ Box(+ Modifier.fillMaxSize().clip(CircleShape).background(MaterialTheme.colors.background),+ ) { content() }+ }+}
news/AGENTS.md
diff --git a/news/AGENTS.md b/news/AGENTS.mdindex 8f07a68f21..f822c6b278 100644--- a/news/AGENTS.md+++ b/news/AGENTS.md@@ -8,7 +8,7 @@ _Install: ./install news_ - Entry files: MainActivity.kt, Route.kt, Navigation.kt - Deps: :library:network, :library:room, :library:image - Metadata: metadata_data/news.md (present)-- Rust: no / screenshotTest: no+- Rust: no / screenshotTest: yes (phone + large-tablet) ## Overview **Purpose:** News reader. Primary feed is our server's `GET /news.json`
news/build.gradle.kts
diff --git a/news/build.gradle.kts b/news/build.gradle.ktsindex 9164f39b91..223e10617e 100644--- a/news/build.gradle.kts+++ b/news/build.gradle.kts@@ -1,5 +1,8 @@ plugins { id("common-conventions-app")+ // Listing screenshots come from Compose previews (src/screenshotTest), not from an+ // instrumented test on a device. Same `:news:metadata` task name either way.+ id("common-conventions-preview-metadata") alias(libs.plugins.ksp) }
news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.ktindex 2d9a4a0a92..755b1a911f 100644--- a/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt@@ -25,9 +25,11 @@ import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.Text import com.vayunmathur.news.R+import com.vayunmathur.news.data.CachedArticle import com.vayunmathur.news.domain.FeedSort import com.vayunmathur.news.domain.NewsCategory import com.vayunmathur.news.domain.SourceCatalog+import com.vayunmathur.news.domain.Story import com.vayunmathur.news.platform.NewsViewModel /**@@ -55,6 +57,52 @@ fun FeedScreen( val localLocation by viewModel.localLocation.collectAsState() val searchQuery by viewModel.searchQuery.collectAsState() val searchStories by viewModel.searchStories.collectAsState()+ FeedContent(+ stories = stories,+ searchStories = searchStories,+ cachedByUrl = cachedByUrl,+ isRefreshing = isRefreshing,+ refreshFailed = refreshFailed,+ categoryFilter = categoryFilter,+ feedSort = feedSort,+ localLocation = localLocation,+ searchQuery = searchQuery,+ onSearchQueryChange = viewModel::setSearchQuery,+ onRefresh = viewModel::refresh,+ onFeedSortChange = viewModel::setFeedSort,+ onCategoryFilterChange = viewModel::setCategoryFilter,+ onToggleBookmark = viewModel::toggleBookmark,+ onOpenSaved = onOpenSaved,+ onOpenStory = onOpenStory,+ onOpenSettings = onOpenSettings,+ )+}++/**+ * Stateless feed body behind [FeedScreen]: every value is a parameter, so Compose+ * previews (src/screenshotTest) render the real screen from literal fixtures with+ * no ViewModel, database or network.+ */+@Composable+internal fun FeedContent(+ stories: List<Story>,+ searchStories: List<Story>,+ cachedByUrl: Map<String, CachedArticle>,+ isRefreshing: Boolean,+ refreshFailed: Boolean,+ categoryFilter: NewsCategory?,+ feedSort: FeedSort,+ localLocation: String?,+ searchQuery: String,+ onSearchQueryChange: (String) -> Unit,+ onRefresh: () -> Unit,+ onFeedSortChange: (FeedSort) -> Unit,+ onCategoryFilterChange: (NewsCategory?) -> Unit,+ onToggleBookmark: (CachedArticle) -> Unit,+ onOpenSaved: () -> Unit,+ onOpenStory: (String) -> Unit,+ onOpenSettings: () -> Unit,+) { val searching = searchQuery.isNotBlank() val shownStories = if (searching) searchStories else stories AppScaffold(@@ -64,11 +112,11 @@ fun FeedScreen( title = "", search = ScaffoldSearch( query = searchQuery,- onQueryChange = viewModel::setSearchQuery,+ onQueryChange = onSearchQueryChange, placeholder = stringResource(R.string.feed_search_placeholder), ), isRefreshing = isRefreshing,- onRefresh = viewModel::refresh,+ onRefresh = onRefresh, actions = { IconButton(onClick = onOpenSaved) { IconBookmark() } IconButton(onClick = onOpenSettings) { IconSettings() }@@ -81,14 +129,14 @@ fun FeedScreen( item { FilterChip( selected = feedSort == FeedSort.TOP,- onClick = { viewModel.setFeedSort(FeedSort.TOP) },+ onClick = { onFeedSortChange(FeedSort.TOP) }, label = { Text(stringResource(R.string.feed_sort_top)) }, ) } item { FilterChip( selected = feedSort == FeedSort.LATEST,- onClick = { viewModel.setFeedSort(FeedSort.LATEST) },+ onClick = { onFeedSortChange(FeedSort.LATEST) }, label = { Text(stringResource(R.string.feed_sort_latest)) }, modifier = Modifier.padding(start = 8.dp), )@@ -102,7 +150,7 @@ fun FeedScreen( item { FilterChip( selected = categoryFilter == null,- onClick = { viewModel.setCategoryFilter(null) },+ onClick = { onCategoryFilterChange(null) }, label = { Text(stringResource(R.string.feed_all_categories)) }, ) }@@ -118,7 +166,7 @@ fun FeedScreen( } FilterChip( selected = categoryFilter == category,- onClick = { viewModel.setCategoryFilter(category) },+ onClick = { onCategoryFilterChange(category) }, label = { Text(label) }, modifier = Modifier.padding(start = 8.dp), )@@ -153,7 +201,7 @@ fun FeedScreen( bookmarked = representativeCached?.bookmarked == true, onClick = { onOpenStory(story.id) }, onToggleBookmark = {- if (representativeCached != null) viewModel.toggleBookmark(representativeCached)+ if (representativeCached != null) onToggleBookmark(representativeCached) }, ) }@@ -167,7 +215,7 @@ fun FeedScreen( bookmarked = representativeCached?.bookmarked == true, onClick = { onOpenStory(story.id) }, onToggleBookmark = {- if (representativeCached != null) viewModel.toggleBookmark(representativeCached)+ if (representativeCached != null) onToggleBookmark(representativeCached) }, ) }
news/src/main/java/com/vayunmathur/news/ui/ReaderScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/ReaderScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/ReaderScreen.ktindex d93ca3c39e..d56753f5ac 100644--- a/news/src/main/java/com/vayunmathur/news/ui/ReaderScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/ReaderScreen.kt@@ -50,6 +50,36 @@ fun ReaderScreen(viewModel: NewsViewModel, url: String, onBack: () -> Unit) { val textSp by viewModel.readerTextSp.collectAsState() val serif by viewModel.readerSerif.collectAsState() LaunchedEffect(url) { viewModel.openArticle(url) }+ ReaderContent(+ body = body,+ error = error,+ bookmarked = bookmarked,+ textSp = textSp,+ serif = serif,+ onToggleBookmark = viewModel::toggleReaderBookmark,+ onTextSp = viewModel::setReaderTextSp,+ onSerif = viewModel::setReaderSerif,+ onBack = onBack,+ )+}++/**+ * Stateless reader body behind [ReaderScreen]: every value is a parameter, so+ * Compose previews (src/screenshotTest) render the real screen from a literal+ * [com.vayunmathur.news.domain.ExtractedArticle] fixture.+ */+@Composable+internal fun ReaderContent(+ body: com.vayunmathur.news.domain.ExtractedArticle?,+ error: Boolean,+ bookmarked: Boolean,+ textSp: Int,+ serif: Boolean,+ onToggleBookmark: () -> Unit,+ onTextSp: (Int) -> Unit,+ onSerif: (Boolean) -> Unit,+ onBack: () -> Unit,+) { AppScaffold( // No generic "Article" title: the article's own headline is in // the content, so the bar carries only back navigation (the@@ -75,8 +105,8 @@ fun ReaderScreen(viewModel: NewsViewModel, url: String, onBack: () -> Unit) { } ReaderActionRow( bookmarked = bookmarked, textSp = textSp, serif = serif,- onToggleBookmark = viewModel::toggleReaderBookmark,- onTextSp = viewModel::setReaderTextSp, onSerif = viewModel::setReaderSerif,+ onToggleBookmark = onToggleBookmark,+ onTextSp = onTextSp, onSerif = onSerif, ) when { error -> Text(stringResource(R.string.reader_loading_failed))
news/src/main/java/com/vayunmathur/news/ui/SavedScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/SavedScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/SavedScreen.ktindex 9c1a7ca42b..db441ecf8f 100644--- a/news/src/main/java/com/vayunmathur/news/ui/SavedScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/SavedScreen.kt@@ -24,6 +24,26 @@ fun SavedScreen( onBack: () -> Unit, ) { val saved by viewModel.bookmarked.collectAsState()+ SavedContent(+ saved = saved,+ onOpenArticle = onOpenArticle,+ onToggleBookmark = viewModel::toggleBookmark,+ onBack = onBack,+ )+}++/**+ * Stateless saved-articles body behind [SavedScreen]: every value is a parameter,+ * so Compose previews (src/screenshotTest) render the real screen from literal+ * fixtures with no ViewModel or database.+ */+@Composable+internal fun SavedContent(+ saved: List<com.vayunmathur.news.data.CachedArticle>,+ onOpenArticle: (String) -> Unit,+ onToggleBookmark: (com.vayunmathur.news.data.CachedArticle) -> Unit,+ onBack: () -> Unit,+) { AppScaffold( title = stringResource(R.string.saved_title), onNavigateBack = onBack,@@ -40,7 +60,7 @@ fun SavedScreen( ArticleRow( article = article, onClick = { onOpenArticle(article.url) },- onToggleBookmark = { viewModel.toggleBookmark(article) },+ onToggleBookmark = { onToggleBookmark(article) }, ) } }
news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt
diff --git a/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt b/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..7d3317f646--- /dev/null+++ b/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt@@ -0,0 +1,165 @@+package com.vayunmathur.news.ui++import androidx.compose.runtime.Composable+import androidx.compose.ui.tooling.preview.Preview+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.news.data.CachedArticle+import com.vayunmathur.news.domain.ArticleBlock+import com.vayunmathur.news.domain.ExtractedArticle+import com.vayunmathur.news.domain.FeedArticle+import com.vayunmathur.news.domain.FeedSort+import com.vayunmathur.news.domain.Story++/** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */+private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"++/** Desktop-wide (1280dp >= 840dp), so the feed's adaptive grid and capped reader measure render. */+private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240"++/**+ * Store listing images for `:news`, rendered from Compose previews instead of from an+ * instrumented test on a device.+ *+ * `./gradlew :news:metadata` renders these and copies the PNGs into per-bucket+ * `metadata_data/photos/news/<bucket>/` dirs (`phone/` and `large-tablet/`), where the+ * release build picks them up. News has no wear companion, so there is no `wear/` bucket.+ *+ * The rules that keep these honest (same as every other module's MetadataPreviews):+ * - Order comes from the function names (`Preview1…`, `Preview2…`), per bucket.+ * - Each preview needs `@PreviewTest` as well as `@Preview`, and a `group` naming the+ * form-factor bucket.+ * - Everything is a literal fixture below — no ViewModel, no database, no network —+ * which is what makes the renders reproducible. Timestamps are 0 on purpose:+ * `relativeTime` renders "" for them, so the images never drift with the date.+ * - Previews must be members of a class, not top-level functions, or the screenshot+ * engine silently discovers no tests.+ */+class MetadataPreviews {++ @PreviewTest+ @Preview(name = "1-feed", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview1Feed() {+ PreviewTheme { FeedFixture() }+ }++ @PreviewTest+ @Preview(name = "2-reader", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview2Reader() {+ PreviewTheme { ReaderFixture() }+ }++ @PreviewTest+ @Preview(name = "3-saved", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview3Saved() {+ PreviewTheme { SavedFixture() }+ }++ @PreviewTest+ @Preview(name = "4-feed-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)+ @Composable+ fun Preview4FeedExpanded() {+ PreviewTheme { FeedFixture() }+ }++ @PreviewTest+ @Preview(name = "5-reader-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)+ @Composable+ fun Preview5ReaderExpanded() {+ PreviewTheme { ReaderFixture() }+ }+}++@Composable+private fun PreviewTheme(content: @Composable () -> Unit) {+ DynamicTheme(darkTheme = true) { content() }+}++private fun fixtureStory(id: String, sourceId: String, title: String, oneLiner: String? = null): Story {+ val article = FeedArticle(+ url = "https://example.com/$id",+ sourceId = sourceId,+ title = title,+ publishedAtMillis = 0L,+ serverStoryId = id,+ storyOneLiner = oneLiner,+ )+ return Story(id = "srv:$id", representative = article, articles = listOf(article))+}++private val fixtureStories = listOf(+ fixtureStory("s1", "bbc", "City approves the new riverfront plan after a long night of debate", "Councillors backed the scheme 8-3, with construction due to start in spring."),+ fixtureStory("s2", "techcrunch", "A small chip startup says its new accelerator sips power", null),+ fixtureStory("s3", "npr", "Morning markets: what to watch before the opening bell", null),+ fixtureStory("s4", "ars", "Deep-sea survey maps a canyon no one had charted before", "The remotely operated vehicle spent nine days on the survey."),+ fixtureStory("s5", "aljazeera", "Farmers adapt as the rains arrive later each year", null),+)++private val fixtureCached: Map<String, CachedArticle> = fixtureStories.associate { story ->+ val a = story.representative+ a.url to CachedArticle(url = a.url, sourceId = a.sourceId, title = a.title, publishedAtMillis = 0L)+}++@Composable+private fun FeedFixture() {+ FeedContent(+ stories = fixtureStories,+ searchStories = emptyList(),+ cachedByUrl = fixtureCached,+ isRefreshing = false,+ refreshFailed = false,+ categoryFilter = null,+ feedSort = FeedSort.TOP,+ localLocation = null,+ searchQuery = "",+ onSearchQueryChange = {},+ onRefresh = {},+ onFeedSortChange = {},+ onCategoryFilterChange = {},+ onToggleBookmark = {},+ onOpenSaved = {},+ onOpenStory = {},+ onOpenSettings = {},+ )+}++@Composable+private fun ReaderFixture() {+ ReaderContent(+ body = ExtractedArticle(+ url = "https://example.com/s1",+ title = "City approves the new riverfront plan after a long night of debate",+ byline = "By A. Reporter",+ blocks = listOf(+ ArticleBlock.Paragraph("The council voted late on Tuesday to approve the riverfront plan, ending months of argument about flood defences, housing and the old ferry terminal."),+ ArticleBlock.Paragraph("Supporters said the scheme would open two miles of bank to the public for the first time in a generation. Critics asked who would pay for the upkeep once the initial grant runs out."),+ ArticleBlock.Heading("What happens next"),+ ArticleBlock.Paragraph("Construction is due to start in spring, beginning with the flood wall. The first section of path is expected to open the following year."),+ ),+ ),+ error = false,+ bookmarked = true,+ textSp = 18,+ serif = true,+ onToggleBookmark = {},+ onTextSp = {},+ onSerif = {},+ onBack = {},+ )+}++@Composable+private fun SavedFixture() {+ SavedContent(+ saved = fixtureStories.map { story ->+ val a = story.representative+ CachedArticle(url = a.url, sourceId = a.sourceId, title = a.title, publishedAtMillis = 0L, bookmarked = true)+ },+ onOpenArticle = {},+ onToggleBookmark = {},+ onBack = {},+ )+}
weather-wear/build.gradle.kts
diff --git a/weather-wear/build.gradle.kts b/weather-wear/build.gradle.ktsindex 81fc52d453..7abf7d7151 100644--- a/weather-wear/build.gradle.kts+++ b/weather-wear/build.gradle.kts@@ -1,4 +1,8 @@-plugins { id("common-conventions-wear") }+plugins { id("common-conventions-wear")+ // Listing screenshots come from Compose previews (src/screenshotTest), not from an+ // instrumented test on a device. Renders land in this module's own+ // metadata_data/photos/<wear-module-key>/wear/ bucket.+ id("common-conventions-preview-metadata") } launcherIcon { symbol = "partly_cloudy_day" } android { namespace = "com.vayunmathur.weather.wear"
weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt
diff --git a/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt b/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.ktindex 96d10d15fd..85c2370007 100644--- a/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt+++ b/weather-wear/src/main/java/com/vayunmathur/weather/wear/ui/WearLocationsScreen.kt@@ -20,7 +20,17 @@ import com.vayunmathur.weather.wear.data.WearWeatherStore import com.vayunmathur.weather.wear.domain.wearConditionLabel import com.vayunmathur.weather.wear.domain.wearTemp @Composable fun WearLocationsScreen(store:WearWeatherStore, onOpen:(Long)->Unit){- val s by store.snapshot.collectAsState(); val st=rememberScalingLazyListState()+ val s by store.snapshot.collectAsState()+ WearLocationsContent(snapshot=s, onOpen=onOpen)+}++/**+ * Stateless locations body behind [WearLocationsScreen]: the snapshot is a+ * parameter, so Compose previews (src/screenshotTest) render a literal fixture+ * with no store or phone.+ */+@Composable internal fun WearLocationsContent(snapshot:com.vayunmathur.weather.wear.domain.WearWeatherSnapshot, onOpen:(Long)->Unit){+ val s=snapshot; val st=rememberScalingLazyListState() ScalingLazyColumn(state=st){ item{ Text(stringResource(R.string.app_name),style=MaterialTheme.typography.title3,textAlign=TextAlign.Center,modifier=Modifier.fillMaxWidth().padding(horizontal=12.dp)) } if(s.locations.isEmpty()){ item{ Text(stringResource(R.string.wear_empty),style=MaterialTheme.typography.body2,textAlign=TextAlign.Center,modifier=Modifier.fillMaxWidth().padding(horizontal=12.dp)) } }
weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt
diff --git a/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt b/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.ktnew file mode 100644index 0000000000..2b9fa3d902--- /dev/null+++ b/weather-wear/src/screenshotTest/kotlin/com/vayunmathur/weather/wear/ui/MetadataPreviews.kt@@ -0,0 +1,72 @@+package com.vayunmathur.weather.wear.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.tooling.preview.Preview+import androidx.wear.compose.material.MaterialTheme+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.weather.wear.domain.WearWeatherCurrent+import com.vayunmathur.weather.wear.domain.WearWeatherLocation+import com.vayunmathur.weather.wear.domain.WearWeatherSnapshot++/** Round watch, 454x454px class (227dp at 320dpi) — Pixel Watch / Galaxy Watch size. */+private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"++/**+ * Store listing images for `:weather:wear`, rendered from Compose previews instead+ * of from an instrumented test on a device.+ *+ * `./gradlew :weather:wear:metadata` renders these and copies the PNGs into+ * `metadata_data/photos/weather-wear/wear/` — the wear module's own bucket, not the+ * phone Weather app's folder — where the release build picks them up.+ *+ * Rules (same as every other module's MetadataPreviews): order comes from the+ * function names, each preview needs `@PreviewTest` plus `group = "wear"`, previews+ * are class members, and everything is a literal fixture snapshot. Layoutlib renders+ * a rectangular canvas, so round previews clip to a circle.+ */+class MetadataPreviews {++ @PreviewTest+ @Preview(name = "1-locations-round", device = ROUND, group = "wear")+ @Composable+ fun Preview1LocationsRound() {+ RoundPreview {+ WearLocationsContent(+ snapshot = WearWeatherSnapshot(+ generatedAtMillis = 0L,+ locations = listOf(+ WearWeatherLocation(+ locationId = 1, name = "Berlin", country = "Germany", isPrimary = true,+ current = WearWeatherCurrent(temperatureC = 9.0, apparentTemperatureC = 7.0, humidityPercent = 71, weatherCode = 3),+ ),+ WearWeatherLocation(+ locationId = 2, name = "Lisbon", country = "Portugal",+ current = WearWeatherCurrent(temperatureC = 19.0, apparentTemperatureC = 19.0, humidityPercent = 55, weatherCode = 0),+ ),+ WearWeatherLocation(+ locationId = 3, name = "Reykjavik", country = "Iceland",+ current = WearWeatherCurrent(temperatureC = 3.0, apparentTemperatureC = 0.0, humidityPercent = 80, weatherCode = 71),+ ),+ ),+ ),+ onOpen = {},+ )+ }+ }+}++/** Round-watch framing: wear screens are round-safe by design; clip so the render is too. */+@Composable+private fun RoundPreview(content: @Composable () -> Unit) {+ MaterialTheme {+ Box(+ Modifier.fillMaxSize().clip(CircleShape).background(MaterialTheme.colors.background),+ ) { content() }+ }+}