Support for auto play video in FrontendScreen#6806
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for the “Autoplay video” preference in the Compose-based FrontendScreen by exposing it as a Flow from PrefsRepository and applying it to the hosted WebView, including reacting to preference changes at runtime.
Changes:
- Add
PrefsRepository.autoPlayVideoFlow()(with implementation + tests) and refactor preference-change observation into a shared helper. - Extend
FrontendViewState.ContentandFrontendViewModelto carry and updateautoPlayVideoEnabledfrom the preference flow. - Apply
mediaPlaybackRequiresUserGesturebased on the setting and reload theWebViewwhen the preference changes (with ViewModel tests added).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepository.kt | Adds the new autoPlayVideoFlow() API with documentation |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImpl.kt | Implements autoPlayVideoFlow() and refactors preference observation via observeChanges(...) helper |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImplTest.kt | Adds unit tests for autoPlayVideoFlow() behavior (initial + change emissions) |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewState.kt | Extends FrontendViewState.Content with autoPlayVideoEnabled |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModel.kt | Collects autoPlayVideoFlow() to update Content, and seeds initial Content with isAutoPlayVideoEnabled() |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModelTest.kt | Adds ViewModel tests verifying autoplay propagation and updates |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendScreen.kt | Applies the autoplay preference to WebView settings and reloads on changes |
| private suspend fun <T> observeChanges(vararg keys: String, mapper: suspend () -> T): Flow<T> { | ||
| val localStorage = localStorage() | ||
| // Seed an initial emission so collectors read the current value immediately | ||
| return (keys.map { localStorage.observeChanges(it) } + flowOf("")) | ||
| .merge() | ||
| .map { mapper() } | ||
| } |
There was a problem hiding this comment.
Why is this specific to this repository and not part of the LocalStorage interface?
There was a problem hiding this comment.
You're right it make more sense.
There was a problem hiding this comment.
Actually I've moved only the vararg part I'm not sure to want the merge and mapper within the localStorage.
There was a problem hiding this comment.
Why not have merge/mapper within the localStorage? I can see this pattern being useful in other repositories and at that point I don't want to duplicate it.
There was a problem hiding this comment.
I didn't like having the mapper logic in the base class it felt too specific but I'll move it and see how it behaves in the future usage 👍🏻
…d/FrontendViewModel.kt Co-authored-by: Joris Pelgröm <jpelgrom@users.noreply.github.com>
Summary
This Pr add support for auto play in
FrontendScreen. It exposes the settings as a flow too to react without having to check the value again when the screen is already loaded.I've used
reloadinstead of re-creating the activity.Checklist
Any other notes
I took the opportunity to mutualize a bit the logic of observing changes in the pref repo.