Repository navigation
Conversation
SunlightActivity held ten Compose state fields, the routine, the debug clock, the tick loop, DataStore access, both pickers, the camera permission flow and window control, with TooManyFunctions suppressed. Because the session lived in Activity fields, rotation or process death discarded an in-progress routine, and a one-shot settings read in onCreate could overwrite a wake-up time saved before it finished. - SunlightViewModel owns the RoutineSession and one StateFlow of SunlightScreenState. Phase is derived from MorningRoutine (SETUP means no session) and the session is mirrored into SavedStateHandle after each change, so it survives configuration changes and process death. - RoutineSession fixes a RoutineClock (wall or DebugRoutineClock over DebugClock) at start; debug tests ignore camera frames. - SettingsRepository wraps the existing DataStore keys and validation and exposes a Flow, removing the load race. - The Activity is a thin host: native pickers (NativePickers.kt), display mode driven by state (FocusDisplay.kt), camera permission and binding. runClock() runs under repeatOnLifecycle(RESUMED), so time still advances only while the preview is resumed. - Camera luminance is computed off the main thread. No new dependencies. Recorded in ADR-003.
onCameraEvent(PERMISSION_MISSING) always published state with a new display time. The Activity reports it from its state collector, so each report caused the next without suspending. On an Android 17 emulator this ran about 256,000 times over 9 seconds on the main thread and held up the permission prompt. onLightReading ran the full update for every frame, saving the session and recomposing many times a second even though the state only changes when the phase does. - A permission condition already in state is no longer republished. - Frames publish only when they change the phase. The announced phase is tracked separately so the bright-light notice still appears.
Starting a routine now returns early for any active session, so a real start can no longer replace a running countdown. The debug path already had this check. An out-of-range duration is ignored by the ViewModel instead of being coerced to the default, which would have overwritten a valid saved value. The repository's duplicate coercion and its misleading test are removed, and ADR-003's dependency note is corrected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.