Update to the 1.4/1.6 releases of android.wear.{protolayout,tiles}#1367
Conversation
Update androidx-wear-tiles to 1.6.0 and protolayout to 1.4.0. Migrate MessagingTileService to Material3TileService and use tileResponse. Remove Horologist dependency. Use basicImage in Layout.kt. Clean up associate syntax. Rename Service.kt to MessagingTileService.kt. Exclude Golden Tiles from this commit to reduce diff size.
Add implementation(libs.horologist.tiles) back to app/build.gradle.kts to support the unchanged Golden Tiles on this branch, as they still depend on it.
There was a problem hiding this comment.
Code Review
This pull request migrates the messaging tile to Material3TileService and updates several dependencies, including Wear Tiles and ProtoLayout. Key changes include refactoring the layout to use MaterialScope and basicImage, and implementing asynchronous image loading with Coil. Feedback highlights a missing resourcesResponse implementation for resource-based avatars, the accidental removal of necessary Kotlin compiler options and opt-ins, and the presence of redundant Compose UI dependencies. Additionally, it is recommended to move the Coil configuration to the application level, provide a resourcesVersion for cache invalidation, and revert the Kotlin version downgrade.
- Set resourcesVersion in tileResponse in MessagingTileService.kt. - Remove redundant ui-tooling dependency from app/build.gradle.kts. - Upgrade Kotlin back to 2.3.20 in libs.versions.toml. - Remove invalid resourcesResponse override from MessagingTileService.kt as Material3TileService handles resources automatically via ProtoLayoutScope and basicImage.
Add a short comment to MessagingTileService.kt explaining why Coil is configured in the service instead of an Application class, as requested by reviewer.
Remove unused import and fix line wrapping for Tile.Builder in MessagingTileService.kt to resolve spotless violations.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Wear Tiles sample to utilize Material3TileService and the latest Protolayout APIs, while removing unnecessary Compose dependencies. Key feedback includes the critical omission of the tileResourcesResponse override in the new service, which is necessary for displaying images, and the lack of a resource provider in the tile previews. Other suggestions involve correcting a potential file extension error in the mock data, using more idiomatic Kotlin for collection checks, and improving the resource versioning strategy to handle caching more effectively.
- Update TilePreviewData in Layout.kt to provide resources provider via onTileResourceRequest, so images render in Android Studio previews. - Use idiomatic row2.isNotEmpty() in Layout.kt. - Add comment in MessagingTileService.kt explaining that images could be cached because version is tied to contact IDs.
Use createMaterialScope instead of materialScope in socialPreviewN to provide the protoLayoutScope from the request. This fixes the IllegalArgumentException caused by accessing protoLayoutScope in basicImage.
Replace restricted createMaterialScope with public materialScopeWithResources in socialPreviewN in Layout.kt. This avoids using LIBRARY_GROUP_PREFIX restricted APIs while still providing the necessary ProtoLayoutScope for automatic resource registration.
Remove unused import and fix line wrapping in Layout.kt to resolve spotless violations introduced in previous commits.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the Wear Tiles sample to use Material3TileService and the latest versions of the Wear Tiles and ProtoLayout libraries. Key changes include removing Compose dependencies, refactoring layout functions to use materialScopeWithResources, and implementing asynchronous image loading with Coil. Feedback suggests moving the SingletonImageLoader configuration from the service's onCreate to the Application level to prevent redundant re-configurations.
|
FYI @NedaTop |
Apply suggestions from NedaTop on PR android#1367: - Use direct import for ColorScheme in Layout.kt. - Remove onTileResourceRequest from TilePreviewData as it is ignored when using materialScopeWithResources. - Add explicit type to imageResources map for readability. - Remove manual resourcesVersion setting and related comment as the system handles it automatically. - Refactor contactButton to use ?.let and Elvis operator.
|
@NedaTop Thanks! I've made the changes you suggested with the exception of #1367 (comment) (which I think is okay as is). Can you take another pass? |
|
LGTM, thank you! |
* Migrate to alpha * Migrations * Fix preview * Update Wear Tiles to 1.6.0-beta01 and ProtoLayout to 1.4.0-beta01 Also updates: - Compose to 1.10.3 - Android Gradle Plugin to 8.13.2 * Switch MessagingTileService to Material3TileService - Refactor MessagingTileService to inherit from Material3TileService - Move resource loading and tile construction into tileResponse - Refactor tileLayout to be an extension on MaterialScope - Remove dependency on Horologist's SuspendingTileService for this component * Migrate MessagingTileService to automated resource management - Use MaterialScope.image with ProtoLayoutScope for automatic resource registration - Simplify tileResponse to leverage the new automated system in Material3TileService - Fix Ali's avatar URL extension (.png -> .jpg) to resolve 404 error - Ensure contacts without avatars correctly fallback to themed initials * Upgrade Gradle, AGP, and Kotlin in WearTilesKotlin - Update Gradle to 9.3.1 - Update Android Gradle Plugin to 9.1.0 - Update Kotlin to 2.2.10 - Add recommended build features and compatibility flags to gradle.properties * build(deps): update wear tiles and protolayout Update androidx-wear-tiles to 1.6.0 and androidx-wear-protolayout to 1.4.0. These represent the final stable releases for these libraries. The update was verified with a clean build and manual deployment to an API 36 Wear OS emulator. Visual inspection confirmed that the tile correctly adopts Material 3 dynamic colors and displays the required branding header icon. * build: resolve conflicts and update versions Resolve merge conflicts with upstream/main in libs.versions.toml, gradle-wrapper.properties, and gradle-daemon-jvm.properties. - Update ktlint to 1.4.0 and Kotlin to 2.3.20 in libs.versions.toml. - Update Gradle wrapper to 9.4.1. - Revert gradle-daemon-jvm.properties to upstream version. - Fix build errors in app/build.gradle.kts by migrating kotlinOptions to compilerOptions DSL. * refactor: remove horologist and update previews Remove leftover Horologist dependencies and update the messaging tile screenshots to reflect the recent migration to Material3TileService. - Removed `horologist-tiles` from `WearTilesKotlin/app` dependencies and the associated experimental compiler flag. - Updated `tile_messaging.png` in resources and README screenshots to show the new Material 3 Dynamic Colors and branding header. - Replaced `?attr/colorControlNormal` in vector drawables with white to fix resource linking errors caused by the dependency removal. - Removed Horologist mentions from the README. * build: fix build and apply formatting - Add ratchetFrom = "origin/main" to spotless configuration. - Increase max line length to 120 in .editorconfig. - Fix build errors in app/build.gradle.kts by adding compose runtime and migrating to compilerOptions DSL. - Fix lint errors (suppressions, imports, file renaming). - Revert Kotlin version to 2.2.10 in libs.versions.toml to fix compose compiler error. - Apply formatting to files modified in this branch. * build: remove horologist dependency Remove implementation(libs.horologist.tiles) from app/build.gradle.kts as it was accidentally re-added and the branch has migrated to use Material3TileService directly. * build: remove compose compiler plugin Remove org.jetbrains.kotlin.plugin.compose and buildFeatures.compose from app/build.gradle.kts as it is not needed for Tile layouts and causes compilation errors in release builds with newer Kotlin versions. Also remove the explicitly added compose runtime dependency. * fix: address PR feedback - Fix non-existent setImageResource call in Layout.kt by using setResourceId. - Remove unnecessary type arguments in associate in Layout.kt. - Fix hardcoded image resource in Calendar.kt by updating Event data class to use @DrawableRes Int and updating call sites. - Add missing DrawableRes import in Calendar.kt. * fix: use basicImage in Layout.kt to fix warning Replace deprecated setResourceId and custom image builder with protoLayoutScope.basicImage in contactButton in Layout.kt. This uses the modern API introduced in 1.4 and removes the deprecation warning. * style: fix formatting violations reported by CI Run spotlessApply to fix formatting violations in Calendar.kt and Layout.kt as reported by CI. This includes line wrapping and import sorting. * build: migrate messaging tile and remove horologist Update androidx-wear-tiles to 1.6.0 and protolayout to 1.4.0. Migrate MessagingTileService to Material3TileService and use tileResponse. Remove Horologist dependency. Use basicImage in Layout.kt. Clean up associate syntax. Rename Service.kt to MessagingTileService.kt. Exclude Golden Tiles from this commit to reduce diff size. * build: restore horologist for golden tiles Add implementation(libs.horologist.tiles) back to app/build.gradle.kts to support the unchanged Golden Tiles on this branch, as they still depend on it. * fix: address PR feedback on minimal branch - Set resourcesVersion in tileResponse in MessagingTileService.kt. - Remove redundant ui-tooling dependency from app/build.gradle.kts. - Upgrade Kotlin back to 2.3.20 in libs.versions.toml. - Remove invalid resourcesResponse override from MessagingTileService.kt as Material3TileService handles resources automatically via ProtoLayoutScope and basicImage. * chore: add comment explaining Coil config rationale Add a short comment to MessagingTileService.kt explaining why Coil is configured in the service instead of an Application class, as requested by reviewer. * style: fix formatting in MessagingTileService Remove unused import and fix line wrapping for Tile.Builder in MessagingTileService.kt to resolve spotless violations. * fix: address PR feedback on previews and caching - Update TilePreviewData in Layout.kt to provide resources provider via onTileResourceRequest, so images render in Android Studio previews. - Use idiomatic row2.isNotEmpty() in Layout.kt. - Add comment in MessagingTileService.kt explaining that images could be cached because version is tied to contact IDs. * fix: fix preview crash in Layout.kt Use createMaterialScope instead of materialScope in socialPreviewN to provide the protoLayoutScope from the request. This fixes the IllegalArgumentException caused by accessing protoLayoutScope in basicImage. * fix: avoid restricted API in Layout.kt Replace restricted createMaterialScope with public materialScopeWithResources in socialPreviewN in Layout.kt. This avoids using LIBRARY_GROUP_PREFIX restricted APIs while still providing the necessary ProtoLayoutScope for automatic resource registration. * style: fix formatting violations in Layout.kt Remove unused import and fix line wrapping in Layout.kt to resolve spotless violations introduced in previous commits. * refactor(messaging): apply review suggestions Apply suggestions from NedaTop on PR #1367: - Use direct import for ColorScheme in Layout.kt. - Remove onTileResourceRequest from TilePreviewData as it is ignored when using materialScopeWithResources. - Add explicit type to imageResources map for readability. - Remove manual resourcesVersion setting and related comment as the system handles it automatically. - Refactor contactButton to use ?.let and Elvis operator. * refactor: cleanup golden tiles and horologist Remove the unused BaseTileService.kt file and the horologist dependency from build files, completing the migration specified in issue #1368. References: #1368 * fix: apply PR feedback and align Kotlin version Apply PR feedback for Hike.kt: simplify preview, remove named parameter, and fix return type of onTileRequest. Also revert Kotlin version in libs.versions.toml to 2.3.20 to match main. References: #1368 * Upgrade versions * fix(build): resolve AGP 9.0 deprecations in build script Suppress deprecation warning for 'android' block and migrate jvmTarget configuration to tasks.withType using compilerOptions to fix clean build failures with AGP 9.0. * refactor: use library ProtoLayout helpers Remove custom helpers from Extensions.kt and use library-provided ones in golden tiles and messaging sample. This improves readability and aligns with standard library practices. - Remove pre-existing row, column, box helpers from Extensions.kt. - Remove unused image helpers and Int.toImageResource() extension. - Use library's vararg-based row, column, box helpers. - Use library's tile helper.
Summary / Goal
Update Wear OS Jetpack library dependencies to their final stable releases and migrate the main messaging tile to the modern API, while deferring changes to the reference layouts (Golden Tiles) to keep the PR focused.
Motivation
The project was previously using beta/RC versions of the
androidx.wear.tilesandandroidx.wear.protolayoutlibraries. With these libraries now stable, we can finalize the versions. The main sample has been migrated toMaterial3TileServicenatively to align with the latest best practices.Proposed Changes
androidx-wear-tilesto1.6.0andandroidx-wear-protolayoutto1.4.0in the version catalog.MessagingTileServiceto extendMaterial3TileServiceand use thetileResponsemethod. UpdatedLayout.ktto usebasicImageto avoid deprecation warnings associated withsetResourceId.com.example.wear.tiles.goldenhave been intentionally excluded from this PR to simplify the review process. They still use theBaseTileServicewrapper and rely on the Horologist dependency, which has been retained for now to support them. Issue to migrate: Modernize and Unify Golden Tiles Architecture and Visuals #1368Rationale & Safety
This cleanup aligns the core sample with the intended stable usage of the APIs. Golden tiles remain functional on the old APIs and will be updated in a follow-up issue.
Verification
./gradlew clean build) successfully.