Introduce screen orientation lock feature to FrontendScreen#6869
Introduce screen orientation lock feature to FrontendScreen#6869TimoPtr wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed screen-orientation preference (via a new ScreenOrientation enum) and wires it through preferences, presenters, and the Compose FrontendScreen so the dashboard can apply and react to the user’s selected orientation consistently across both the legacy WebViewActivity and the newer Compose-based frontend.
Changes:
- Add
ScreenOrientationenum + typed get/save APIs and a dedicatedscreenOrientationFlow()inPrefsRepository. - Apply the preference in Compose via
ScreenOrientationEffect(with restoration on dispose) and expose it fromFrontendViewModel. - Update legacy
WebViewActivity+ settings presenter integration, and add unit/UI tests for the new behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepository.kt | Introduces ScreenOrientation enum and typed preference APIs/flow |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImpl.kt | Implements typed read/write + screenOrientationFlow() |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImplTest.kt | Adds unit tests for typed orientation read/write and flow emissions |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModel.kt | Exposes screenOrientation as a StateFlow sourced from prefs |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendScreen.kt | Applies orientation to the hosting Activity via a composable effect |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModelTest.kt | Tests that screenOrientation StateFlow reflects pref flow updates |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendScreenTest.kt | UI tests verifying orientation application + restoration on dispose |
| app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewPresenter.kt | Updates presenter API to return typed ScreenOrientation |
| app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt | Adapts presenter implementation to typed API |
| app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt | Simplifies requestedOrientation mapping using ScreenOrientation.activityInfo |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/SettingsPresenterImpl.kt | Bridges PreferenceDataStore string values to typed enum and back |
jpelgrom
left a comment
There was a problem hiding this comment.
It works, but I really wish you had split the refactor into an enum off into a smaller standalone PR.
| SYSTEM("system", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED), | ||
| PORTRAIT("portrait", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT), | ||
| LANDSCAPE("landscape", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE), |
There was a problem hiding this comment.
Is it worth using the string reference here instead of a raw string, so if we ever change it in the xml the setting adjusts accordingly?
@dshokouhi double checking: do you know if the preference value was ever accidentally translated and this might reset it for non-English users? (It currently isn't included in the translatable strings for Dutch, but I cannot easily check every language, and know Lokalise doesn't automatically delete old values.)
There was a problem hiding this comment.
If we use the reference here I need to unwrap the reference for the storage and I need to add a context to the PrefRepositoryImpl (it's possible but annoying).
Another reason to migrate away from the XML pref would allow us better translations for this.
Summary
Add the fixed screen orientation to the FrontendScreen, exposes the settings with an enum and adjust the old code to use the new enum from the preference.
Checklist
Any other notes
I know the string are in xml still but I prefer to duplicate it in one place and avoid using string everywhere and favor strong types. I suspect that we might drop the preference settings at some point in favor of something custom that would drop the duplication and only rely on the enum.