todo: add Wear Tile for open tasks
- Commit
430253415386743f81889c4afb065f062236c92b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 05:42 UTC (9 hours ago)
- Parents
e3f2428
TodoTileService (service/, on the shared :library:weartiles MaTileService seam) renders the default view's open count and its top open task from WearTodoStore's conduit catalog/pages, so the tile works fully offline from the cached snapshot. Tap opens WearMainActivity. WearTodoStore requests a tile update on catalog and page changes; 15-minute freshness otherwise. The catalog+tasks mapping is pure and covered by TodoTileServiceTest with a ProtoLayout proto assertion. Verified: :todo:testDevUnitTest, :todo:lint and :todo:lintVitalRelease green.
Diff
todo/AGENTS.md
diff --git a/todo/AGENTS.md b/todo/AGENTS.mdindex b421f081b4..828bade888 100644--- a/todo/AGENTS.md+++ b/todo/AGENTS.md@@ -81,3 +81,4 @@ watch, and `notifications/BootReceiver` early-returns there. ./gradlew :todo:metadata # regenerate listing screenshots after UI changes ``` Relay changes: also `./gradlew :everysync:testDevUnitTest`.+- Wear Tile: `service/TodoTileService` (a `MaTileService` in `:library:weartiles`) renders the default view's open count and top open task from `WearTodoStore`; the store requests a tile update on catalog/page changes, plus 15-minute freshness. Tap opens `WearMainActivity`.
todo/build.gradle.kts
diff --git a/todo/build.gradle.kts b/todo/build.gradle.ktsindex a0f12686ab..5766922a2e 100644--- a/todo/build.gradle.kts+++ b/todo/build.gradle.kts@@ -34,6 +34,7 @@ dependencies { // sync/WearTodoSync publishes the phone catalog/pages, sync/WearLinkBridge // receives them on a watch. FormFactor picks the side at runtime. implementation(project(":library:wearlink"))+ implementation(project(":library:weartiles")) // Watch experience (ui/Wear*): Wear Compose + the repo log facade the // watch data/sync code writes through. implementation(libs.androidx.wear.compose.material)
todo/src/main/AndroidManifest.xml
diff --git a/todo/src/main/AndroidManifest.xml b/todo/src/main/AndroidManifest.xmlindex d4552c06df..b160b5be2d 100644--- a/todo/src/main/AndroidManifest.xml+++ b/todo/src/main/AndroidManifest.xml@@ -194,6 +194,20 @@ <action android:name="com.vayunmathur.watch.action.SYNC_TRIGGER" /> </intent-filter> </receiver>++ <!-- Wear OS Tile (watch-home card): renders from the wear snapshot store. -->+ <service+ android:name=".service.TodoTileService"+ android:exported="true"+ android:icon="@mipmap/ic_launcher"+ android:label="Todo">+ <intent-filter>+ <action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER" />+ </intent-filter>+ <meta-data+ android:name="androidx.wear.tiles.PREVIEW"+ android:resource="@mipmap/ic_launcher" />+ </service> </application> </manifest>
todo/src/main/java/com/vayunmathur/todo/data/WearTodoStore.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/data/WearTodoStore.kt b/todo/src/main/java/com/vayunmathur/todo/data/WearTodoStore.ktindex 0860ea705e..2327287de4 100644--- a/todo/src/main/java/com/vayunmathur/todo/data/WearTodoStore.kt+++ b/todo/src/main/java/com/vayunmathur/todo/data/WearTodoStore.kt@@ -2,6 +2,8 @@ package com.vayunmathur.todo.data import android.content.Context import com.vayunmathur.library.log.Log+import com.vayunmathur.library.weartiles.MaTileService+import com.vayunmathur.todo.service.TodoTileService import com.vayunmathur.library.wearlink.todo.WearTodoCatalog import com.vayunmathur.library.wearlink.todo.WearTodoOp import com.vayunmathur.library.wearlink.todo.WearTodoOpKind@@ -64,6 +66,7 @@ class WearTodoStore private constructor(private val context: Context) { fun setCatalog(catalog: WearTodoCatalog) { if (catalog.generatedAtMillis < _catalog.value.generatedAtMillis) return _catalog.value = catalog+ MaTileService.requestUpdate(context, TodoTileService::class.java) persist(catalogFile, WearTodoProtocol.json.encodeToString(catalog)) com.vayunmathur.todo.sync.WearLinkBridge.publishWatchState(context) }@@ -73,6 +76,7 @@ class WearTodoStore private constructor(private val context: Context) { val existing = _pages.value[key] if (existing != null && page.generatedAtMillis < existing.generatedAtMillis) return _pages.value = _pages.value + (key to page)+ MaTileService.requestUpdate(context, TodoTileService::class.java) persist(pagesFile, WearTodoProtocol.json.encodeToString(_pages.value)) dropReflected(page) com.vayunmathur.todo.sync.WearLinkBridge.publishWatchState(context)
todo/src/main/java/com/vayunmathur/todo/service/TodoTileService.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/service/TodoTileService.kt b/todo/src/main/java/com/vayunmathur/todo/service/TodoTileService.ktnew file mode 100644index 0000000000..e2337cdce2--- /dev/null+++ b/todo/src/main/java/com/vayunmathur/todo/service/TodoTileService.kt@@ -0,0 +1,32 @@+package com.vayunmathur.todo.service++import android.content.Context+import com.vayunmathur.library.weartiles.MaTileService+import com.vayunmathur.library.weartiles.TileSnapshot+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.todo.data.WearTodoStore++/** Wear Tile for Todo: open count for the default view plus its top open task. */+class TodoTileService : MaTileService() {+ override val launchActivityName: String = "com.vayunmathur.todo.ui.WearMainActivity"++ override fun loadSnapshot(context: Context): TileSnapshot {+ val store = WearTodoStore.get(context)+ val catalog = store.catalog.value+ val tasks = store.pagesFor(catalog.defaultViewKey).flatMap { it.tasks }+ return todoTileSnapshot(catalog, tasks)+ }++ override fun previewSnapshot(): TileSnapshot =+ TileSnapshot(appName = "Todo", primary = "3 open", secondary = "Buy milk")+}++/** Pure catalog+tasks mapping for the tile. */+fun todoTileSnapshot(catalog: WearTodoCatalog, tasks: List<WearTodoTask>): TileSnapshot {+ val view = catalog.views.firstOrNull { it.key == catalog.defaultViewKey } ?: catalog.views.firstOrNull()+ val open = view?.openCount ?: tasks.count { !it.done }+ if (open == 0) return TileSnapshot(appName = "Todo", primary = "All done", secondary = view?.title ?: "")+ val top = tasks.firstOrNull { !it.done }?.title ?: view?.title ?: ""+ return TileSnapshot(appName = "Todo", primary = "$open open", secondary = top)+}
todo/src/test/java/com/vayunmathur/todo/service/TodoTileServiceTest.kt
diff --git a/todo/src/test/java/com/vayunmathur/todo/service/TodoTileServiceTest.kt b/todo/src/test/java/com/vayunmathur/todo/service/TodoTileServiceTest.ktnew file mode 100644index 0000000000..525d8bb95d--- /dev/null+++ b/todo/src/test/java/com/vayunmathur/todo/service/TodoTileServiceTest.kt@@ -0,0 +1,33 @@+package com.vayunmathur.todo.service++import com.vayunmathur.library.weartiles.TileLayout+import com.vayunmathur.library.wearlink.todo.WearTodoCatalog+import com.vayunmathur.library.wearlink.todo.WearTodoTask+import com.vayunmathur.library.wearlink.todo.WearTodoViewEntry+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++class TodoTileServiceTest {+ @Test+ fun openCountAndTopTaskRender() {+ val catalog = WearTodoCatalog(+ generatedAtMillis = 1L, defaultViewKey = "today",+ views = listOf(WearTodoViewEntry(key = "today", title = "Today", openCount = 3, totalCount = 5)),+ )+ val tasks = listOf(+ WearTodoTask(syncId = "a", title = "Done one", done = true),+ WearTodoTask(syncId = "b", title = "Buy milk", done = false),+ )+ val tile = todoTileSnapshot(catalog, tasks)+ assertEquals("3 open", tile.primary)+ assertEquals("Buy milk", tile.secondary)+ assertTrue(TileLayout.build(tile, "com.vayunmathur.todo", "X").toString().contains("Buy milk"))+ }++ @Test+ fun zeroOpenIsAllDone() {+ val catalog = WearTodoCatalog(views = listOf(WearTodoViewEntry(key = "today", title = "Today", openCount = 0)))+ assertEquals("All done", todoTileSnapshot(catalog, emptyList()).primary)+ }+}