Migrate template widget configuration to Compose and Material3 - #7288
Migrate template widget configuration to Compose and Material3#7288su7ri wants to merge 6 commits into
Conversation
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
🟡 Not ready to approve
The ViewModel can leave a stale “Rendered” preview while a new render is in-flight, allowing users to save an unvalidated template/server selection before rendering completes.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Migrates the Template widget configuration flow from a legacy XML/ViewBinding Activity to a Compose + Material3 screen driven by an assisted Hilt ViewModel, aligning the widget configuration architecture with the recent entity widget migration pattern.
Changes:
- Replaced the legacy
TemplateWidgetConfigureActivityUI with a Compose screen (TemplateWidgetConfigureScreen) underHATheme. - Introduced
TemplateWidgetConfigureViewModel+ immutableTemplateWidgetConfigureState(including aTemplatePreviewsealed type) to own restore/render/save logic viaStateFlow. - Added focused unit tests for restore/render/save behavior; removed the obsolete XML layout.
File summaries
| File | Description |
|---|---|
| app/src/main/kotlin/io/homeassistant/companion/android/widgets/template/TemplateWidgetConfigureActivity.kt | Converts the Activity into a thin Compose wrapper that delegates logic to the ViewModel. |
| app/src/main/kotlin/io/homeassistant/companion/android/widgets/template/TemplateWidgetConfigureScreen.kt | New Compose UI for configuring the widget, including HTML preview rendering. |
| app/src/main/kotlin/io/homeassistant/companion/android/widgets/template/TemplateWidgetConfigureState.kt | Adds immutable UI state and a sealed preview model for rendered/empty/error states. |
| app/src/main/kotlin/io/homeassistant/companion/android/widgets/template/TemplateWidgetConfigureViewModel.kt | New assisted Hilt ViewModel handling restore/render/save and widget pin/update flows. |
| app/src/test/kotlin/io/homeassistant/companion/android/widgets/template/TemplateWidgetConfigureViewModelTest.kt | Adds unit tests for state restoration, rendering, and persistence behavior. |
| app/src/main/res/layout/widget_template_configure.xml | Removes the legacy XML configuration layout. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
jpelgrom
left a comment
There was a problem hiding this comment.
Thanks for picking this up!
Could you add a screenshot test as well? You already have a Compose preview so it shouldn't be too difficult :)
The live template preview still renders basic HTML from the server response; the HTML→AnnotatedString conversion follows the same approach already used on the Wear OS template tile screen (SettingsWearTemplateTile.kt), duplicated here rather than extracted to keep this PR focused on the widget migration. Happy to extract it to a shared util in a follow-up if maintainers prefer.
As it is only ~30 lines you can extract it into a util file in this PR instead of duplicating code.
…iew card, multi-line template field
Fixes an Android Lint (Slack compose-lints) finding: composables should only emit content from one source at their top level.
Summary
Migrates
TemplateWidgetConfigureActivityfrom a legacy XML/View Bindinglayout to Jetpack Compose with Material 3, following the same pattern
established for the entity widget in #7007 (referenced from #6307 as the
example to follow for this series of widget migrations).
TemplateWidgetConfigureActivity.ktis now a thin wrapper (~60 lines,down from ~250) around:
TemplateWidgetConfigureState: immutable UI state, including aTemplatePreviewsealed type (Empty/Rendered/Error) replacing the oldsingle TextView that mixed rendered output, error messages, and the
"blank" placeholder.
TemplateWidgetConfigureViewModel: the restore/save/render logic,moved out of the Activity into a Hilt ViewModel with
StateFlow.TemplateWidgetConfigureScreen: the Compose UI, reusing the sharedWidgetBackgroundTypeDropdown/WidgetTextColorDropdowncomposables.The live template preview still renders basic HTML from the server
response; the HTML→AnnotatedString conversion follows the same approach
already used on the Wear OS template tile screen
(
SettingsWearTemplateTile.kt), duplicated here rather than extractedto keep this PR focused on the widget migration. Happy to extract it to
a shared util in a follow-up if maintainers prefer.
Closes #6304
Checklist
Select exactly one option that describes AI usage in this contribution:
Screenshots
Any other notes
Part of the ongoing effort to migrate widget configuration screens to
Compose/Material 3 (see #6303, #6305, #6306, #6308, and others).