Add keep screen on feature to FrontendScreen#6868
Conversation
There was a problem hiding this comment.
Pull request overview
This PR wires the existing “Keep screen on” preference into the new Compose-based frontend by exposing it as a reactive Flow from PrefsRepository, surfacing it as a StateFlow in FrontendViewModel, and applying it in FrontendScreen by toggling View.keepScreenOn while the screen is in composition.
Changes:
- Added
PrefsRepository.keepScreenOnFlow()and implemented it viaLocalStorage.observeChanges(...)with immediate initial emission - Exposed
keepScreenOnEnabled: StateFlow<Boolean>onFrontendViewModeldriven by the preference flow - Applied the preference in
FrontendScreenvia aDisposableEffectthat sets/clearsView.keepScreenOn, plus unit tests for the new flows/state
Reviewed changes
Copilot reviewed 6 out of 6 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 public keepScreenOnFlow() API with KDoc describing emission semantics |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImpl.kt | Implements keepScreenOnFlow() using LocalStorage.observeChanges |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImplTest.kt | Adds unit test verifying keepScreenOnFlow() emits initial + updated values on key changes |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModel.kt | Adds keepScreenOnEnabled StateFlow for UI consumption |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModelTest.kt | Adds tests ensuring the ViewModel reflects changes and respects seeded values |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendScreen.kt | Collects keepScreenOnEnabled and applies it via KeepScreenOnEffect (View.keepScreenOn) |
|
I would like to link #6829 to close it after merging, even if it takes a time to land in prod, agreed? By using the flow observing the setting you fix the issue. |
jpelgrom
left a comment
There was a problem hiding this comment.
Nice and simple, and works good. (Tests remain quite verbose, artificially inflating lines changed...)
Also confirmed this fixes #6829 by testing - if you agree we can consider this as fix (see previous comment) please link before merging.
Pull request was closed
Summary
Add keep screen on feature to
FrontendScreenby exposing a flow from the preference to react on changes.Checklist