Add options to hide system bars and turn screen on#54
Add options to hide system bars and turn screen on#54xvello wants to merge 2 commits intobrownard:masterfrom
Conversation
a779be0 to
b12e11b
Compare
|
This looks like a nice addition.
Ideally yes, but I think the switch entity handling might need a bit of a rework first. Currently they are created in the VoiceSatellite constructor, which is not only getting a bit unwieldly, but means the VoiceSatellite would need a dependency on the new settings which would otherwise be unnecessary. Instead all the entities should probably be passed into the VoiceSatellite constructor as an externally built list as none of them are referenced by the satellite directly. You can either leave the switches for now and I'll rework it later, or if you want to refactor similar to the above then give it a go. |
| fun WakeScreenOnInteraction(viewModel: ServiceViewModel = hiltViewModel()) { | ||
| val timers by viewModel.voiceTimers.collectAsStateWithLifecycle(emptyList()) | ||
| val currentState by viewModel.satelliteState.collectAsStateWithLifecycle(null) | ||
| val wakingStates = setOf(Listening, Processing, Responding) | ||
|
|
||
| if (wakingStates.contains(currentState) || timers.any({ it !is VoiceTimer.Paused })) { | ||
| val window = LocalActivity.current?.window | ||
| if (window != null) { | ||
| DisposableEffect("WakeScreenOnInteraction") { | ||
| window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) | ||
|
|
||
| onDispose { | ||
| window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
If you collect the timers and state (and potentially the current window) in the caller and pass them in directly as parameters instead of the view model then you can make this a stateless composable which should avoid it being called altogether until those values change and save a few cycles (see state hoisting). As it stands I think the if check is called every frame.
There was a problem hiding this comment.
@brownard sorry for the delay. I rebased and moved the state up, although I didn't go full stateless because I don't think it's worth it here. Happy to do it though if you think it's better.
There was a problem hiding this comment.
Edit: I updated my S9 to this lineage 23 ROM and WakeScreenOnInteraction is non functional. I am investigating why and will post here.
Seems like using a Composable for this won't work, because composition can be paused when the screen is off, leading to our logic never being executed.
|
@xvello i see you mentioned an Echo Show. Have you had success running the app? I have a rooted echo show 8 (running lineageos/android 11) and am unable to get the device to connect to my HASS instance. I submitted an issue here: #63 Just curious if you had any issues? Sorry for highjacking this PR. Edit: Scratch that.....I had a static IP reservation for this device and somehow it got overridden by some other client. Removed the reservation on my router and things are connecting just fine now. |
|
Would be cool if the background shows a colour matching current state. In case I'm yelling at it from far away and cannot read the text :) |
|
Closing in favour of #65, I'd rather pay 4$/device than figure out how to make that work on several Android versions. Anyone can feel free to reuse this branch and bring it forward, I'm kind of done with Android documentation. @Mugl3 I plan on implementing a better visual feedback for the satellite state (probably with a microphone icon that changes colors when listening/thinking/error...). It will take the left half of the screen in landscape mode, timers will take the right half. But it's not happening on this branch. |
For use in a small-screen kiosk device such as the Echo Show, add two options:
hideSystemBarsto increase available screen spacewakeScreento allow the screen to dim on inactivity, then go bright during voice interactions and timer countdownThey intentionnaly only apply to the
HomeScreen, so that they don't apply if the app is not in the foregroud (instead of using a screen WakeLock).Do you want these exposed as esphome switches too??