Skip to content

Support for auto play video in FrontendScreen#6806

Merged
jpelgrom merged 6 commits intomainfrom
feature/autoplay
May 6, 2026
Merged

Support for auto play video in FrontendScreen#6806
jpelgrom merged 6 commits intomainfrom
feature/autoplay

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented May 4, 2026

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 reload instead of re-creating the activity.

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.

Any other notes

I took the opportunity to mutualize a bit the logic of observing changes in the pref repo.

Copilot AI review requested due to automatic review settings May 4, 2026 12:34
@TimoPtr TimoPtr added the WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav. label May 4, 2026
@TimoPtr TimoPtr requested a review from jpelgrom May 4, 2026 12:37
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

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.Content and FrontendViewModel to carry and update autoPlayVideoEnabled from the preference flow.
  • Apply mediaPlaybackRequiresUserGesture based on the setting and reload the WebView when 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

Comment thread app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendScreen.kt Outdated
Comment on lines +407 to +413
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() }
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this specific to this repository and not part of the LocalStorage interface?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right it make more sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually I've moved only the vararg part I'm not sure to want the merge and mapper within the localStorage.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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>
@TimoPtr TimoPtr requested a review from jpelgrom May 5, 2026 11:58
@jpelgrom jpelgrom merged commit 7293470 into main May 6, 2026
24 checks passed
@jpelgrom jpelgrom deleted the feature/autoplay branch May 6, 2026 15:29
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