Skip to content

Add keep screen on feature to FrontendScreen#6868

Merged
TimoPtr merged 3 commits into
mainfrom
feature/alwayson
May 26, 2026
Merged

Add keep screen on feature to FrontendScreen#6868
TimoPtr merged 3 commits into
mainfrom
feature/alwayson

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented May 20, 2026

Summary

Add keep screen on feature to FrontendScreen by exposing a flow from the preference to react on changes.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Copilot AI review requested due to automatic review settings May 20, 2026 07:06
@TimoPtr TimoPtr added the WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav. label May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via LocalStorage.observeChanges(...) with immediate initial emission
  • Exposed keepScreenOnEnabled: StateFlow<Boolean> on FrontendViewModel driven by the preference flow
  • Applied the preference in FrontendScreen via a DisposableEffect that sets/clears View.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)

@jpelgrom
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TimoPtr TimoPtr enabled auto-merge (squash) May 26, 2026 12:02
@TimoPtr TimoPtr closed this May 26, 2026
auto-merge was automatically disabled May 26, 2026 13:25

Pull request was closed

@TimoPtr TimoPtr reopened this May 26, 2026
@TimoPtr TimoPtr enabled auto-merge (squash) May 26, 2026 13:25
@TimoPtr TimoPtr merged commit 694481b into main May 26, 2026
20 checks passed
@TimoPtr TimoPtr deleted the feature/alwayson branch May 26, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants