Skip to content

feat(android): add "System" reading-theme option - #395

Merged
github-actions[bot] merged 1 commit into
devfrom
feat/android-reading-theme-system-370
Aug 21, 2026
Merged

github-actions[bot] merged 1 commit into
devfrom
feat/android-reading-theme-system-370

Conversation

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Summary

Android half of #349, tracked as #370 (iOS half — #371 — already merged via #374/#390). Adds a SYSTEM case that follows the OS-level light/dark appearance setting, mirroring iOS's ReadingTheme/ConcreteReadingTheme split (#374) so the compiler enforces resolving SYSTEM before it reaches anything that needs a concrete color.

Approach

  • ReadingTheme (core:ui) and AppReadingTheme (core:domain) both gain a SYSTEM case.
  • New core:ui ConcreteReadingTheme (DARK/LIGHT/SEPIA) + ReadingTheme.resolved(systemInDarkTheme: Boolean) — the single place the System→Dark/Light policy lives. Sepia is never a resolution target (not one of the OS's two choices), same call as iOS.
  • Every exhaustive when (ReadingTheme) this issue's scope note flagged as a landmine now takes ConcreteReadingTheme instead, resolved at the nearest @Composable call site via isSystemInDarkTheme():
    • LibravaultTheme's color-scheme selection
    • mermaidThemeName (Mermaid diagram theming)
    • toEpubPreferences() / toVaultEpubPreferences() (EpubReaderScreen, VaultEpubReaderScreen)
  • LaunchedEffect keys include the resolved theme (not just the raw enum) at all three of those call sites, so a live OS appearance change re-applies while System is selected — the "updates live" acceptance criterion, for both the reader chrome and Mermaid diagrams.
  • MainActivity maps the new AppReadingTheme.SYSTEM case through to ReadingTheme.SYSTEM.
  • Both settings sheets (ReaderSettingsSheet, VaultReaderSettingsSheet) and SettingsScreen already iterate .entries generically, so the 4th "System" chip needed no changes there.
  • Default stays DARK for both app-wide and per-session settings — matches the iOS decision (feat(ios): add "System" reading-theme option #374), System is an available choice, not the default. Per-session reader settings still reset to DARK each time a reader opens, same pre-existing gap feat(ios): add "System" reading-theme option #374 documented as out-of-scope on iOS.

Bug found while wiring this up

LibravaultTheme's old color-scheme when only special-cased SEPIA and otherwise fell straight through to the ambient darkTheme (system) value — an explicit DARK or LIGHT pick had no actual effect; only the system's own light/dark setting mattered. Resolving readingTheme against darkTheme up front (required to support SYSTEM at all) fixes this as a side effect: DARK/LIGHT/SEPIA now always win regardless of the system setting, and SYSTEM is the only case that still follows it. Two new regression tests in LibravaultThemeTest cover this directly (explicit Dark winning over an ambient-light system, and explicit Light winning over an ambient-dark system).

Tests

  • ReadingThemeResolutionTest (new): resolved() logic, all four ReadingTheme cases.
  • LibravaultThemeTest: System follows system light/dark, plus the two bug-fix regression tests above.
  • MermaidThemeTest: updated to ConcreteReadingTheme's 3 cases.
  • ReaderViewModelTest / VaultReaderViewModelTest: onThemeChanged(SYSTEM) round-trips through UI state.
  • SettingsViewModelTest: onReadingThemeChanged(SYSTEM) persists.
  • VaultReaderSettingsSheetUiTest: System renders as a 4th chip and can be shown selected.
  • UserPreferencesRepositoryTest's existing AppReadingTheme.values() loop already covers System's persistence round-trip with no changes needed (additive enum value, no migration).

All new/changed logic was mutation-checked locally (deliberately broke resolved()'s SYSTEM branch and reverted LibravaultTheme's fix back to the old buggy form; both were caught by the new tests, then reverted back).

Ran :core:ui, :core:domain, :feature:reader, :feature:vault, :feature:settings unit tests locally — all green.

Not touched, deliberately

  • Roborazzi screenshot baselines (ThemeScreenshotTest) — deliberately kept to 3 images per that file's own doc; System is covered by non-screenshot tests instead. Screenshot baselines are also a sensitive path per .github/agent-policy.yml.
  • No new Compose UI test file for feature:reader's ReaderSettingsSheet — no such file existed before this PR (unlike feature:vault's VaultReaderSettingsSheetUiTest, extended here); the underlying .entries.forEach mechanism is identical and already covered on the vault side plus the resolution-logic tests.

Closes #370

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

Android half of #349, mirroring iOS's ConcreteReadingTheme split (#374)
so the compiler enforces resolving SYSTEM before it reaches anything
that needs a concrete color.

## Changes

- ReadingTheme/AppReadingTheme both gain a SYSTEM case.
- New core:ui ConcreteReadingTheme (DARK/LIGHT/SEPIA) + ReadingTheme.resolved(
  systemInDarkTheme) — the single place the SYSTEM→Dark/Light policy lives.
  Sepia is never a resolution target, same call as iOS.
- Every exhaustive `when (ReadingTheme)` #370 flagged as a landmine now takes
  ConcreteReadingTheme instead, resolved at the nearest @composable call site
  via isSystemInDarkTheme(): LibravaultTheme's color-scheme selection,
  mermaidThemeName, and both toEpubPreferences()/toVaultEpubPreferences()
  helpers (EpubReaderScreen, VaultEpubReaderScreen). LaunchedEffect keys
  include the resolved theme (not just the raw enum) so a live OS appearance
  change re-applies while SYSTEM is selected, matching the "updates live"
  acceptance criterion for both the reader chrome and Mermaid diagrams.
- MainActivity maps the new AppReadingTheme.SYSTEM case through.
- Both settings sheets (ReaderSettingsSheet, VaultReaderSettingsSheet) and
  SettingsScreen already iterate ReadingTheme/AppReadingTheme.entries
  generically, so the 4th "System" chip needed no changes there.
- Default stays DARK for both app-wide and per-session settings, matching
  the iOS decision (#374) — System is an available choice, not the default.
  Per-session settings still reset to DARK each reader open, same
  pre-existing (out-of-scope) gap #374 found on iOS.

## Bug found while wiring this up

LibravaultTheme's old color-scheme `when` only special-cased SEPIA and
otherwise fell straight through to the ambient `darkTheme` (system) value —
an explicit DARK or LIGHT pick was silently overridden by whatever the
system's own light/dark setting happened to be. Resolving readingTheme
against darkTheme up front (required to support SYSTEM at all) fixes this
as a side effect: DARK/LIGHT/SEPIA now always win regardless of the system
setting, and SYSTEM is the only case that still follows it. Covered by two
new regression tests in LibravaultThemeTest.

## Tests

- ReadingThemeResolutionTest (new): resolved() logic, all four cases.
- LibravaultThemeTest: SYSTEM follows system light/dark + the DARK/LIGHT-
  wins-over-ambient-system regression above.
- MermaidThemeTest: updated to ConcreteReadingTheme's 3 cases.
- ReaderViewModelTest / VaultReaderViewModelTest: onThemeChanged(SYSTEM)
  round-trips through UI state.
- SettingsViewModelTest: onReadingThemeChanged(SYSTEM) persists.
- VaultReaderSettingsSheetUiTest: System renders as a 4th chip and can be
  selected.
- UserPreferencesRepositoryTest's existing `AppReadingTheme.values()` loop
  covers SYSTEM's persistence round-trip with no changes needed.

All new/changed tests mutation-checked (deliberately broke resolved()'s
SYSTEM branch and LibravaultTheme's pre-fix logic; both caught by the new
tests, then reverted).

Closes #370

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk:low Principal review classified this PR as low risk label Aug 21, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-qa PR open, awaiting qa-agent verification label Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was opened outside the automated pipeline (author isn't libravault-pipeline-bot[bot]), so dev-agent.yml's own end-of-run classification step never ran for it — it would otherwise have sat with no risk/status label and nothing downstream would pick it up (see issue #223's actual history). This deterministic backstop (pr-intake.yml) classified its risk and applied status:needs-qa to route it into the normal pipeline from here.

@libravault-xyz libravault-xyz added enhancement New feature or request android labels Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📱 iOS Build Status: PASSED

✅ iOS Simulator Build & Unit Tests - success
✅ Android Core Modules - success

iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those.

View run details

@libravault-xyz

Copy link
Copy Markdown
Collaborator Author

QA verification — PR #395 vs issue #370

Verified against origin/feat/android-reading-theme-system-370 (single commit c5c1008, based cleanly on current origin/dev) in a scratch worktree, not the PR body's claims.

Acceptance criteria (issue #370)

  • User can select "System" in Reading settings (both sheets) — PASS. ReadingTheme.entries/AppReadingTheme.entries are iterated generically in ReaderSettingsSheet, VaultReaderSettingsSheet, and SettingsScreen; new VaultReaderSettingsSheetUiTest ("System appears as a 4th theme chip and can be shown selected") asserts the rendered chip text directly via Robolectric Compose test — real assertion, not mocked.
  • System resolves via isSystemInDarkTheme(), matches OS setting, updates live (chrome, Mermaid, EPUB) — PASS. Single resolution point ReadingTheme.resolved(systemInDarkTheme: Boolean): ConcreteReadingTheme in core/ui/theme/Theme.kt, called from LibravaultTheme (isSystemInDarkTheme()/darkTheme param), MermaidDiagramView (isSystemInDarkTheme(), keyed into LaunchedEffect(pageReady, source, resolvedTheme) so live OS changes re-render), and EpubReaderScreen/VaultEpubReaderScreen (isSystemInDarkTheme() read once per composition, keyed into their settings-hot-reload LaunchedEffects). All three "live update" call sites key on the resolved value, not the raw enum, so a mid-session OS appearance flip actually re-applies.
  • Sepia is never a resolution target — PASS. resolved()'s SYSTEM branch is a hard if (systemInDarkTheme) DARK else LIGHT — structurally cannot produce SEPIA. Covered explicitly by ReadingThemeResolutionTest's "SYSTEM never resolves to SEPIA".
  • No migration/crash risk for existing stored DARK/LIGHT/SEPIA — PASS. AppReadingTheme persists by name (UserPreferencesRepository: AppReadingTheme.valueOf(prefs.getString(...))), not ordinal, and SYSTEM is appended last — existing stored strings are untouched and still valid. UserPreferencesRepositoryTest's existing AppReadingTheme.values() round-trip loop now covers SYSTEM for free, no changes needed (confirmed by reading the test, still passing).
  • 4th chip in settings sheets — PASS, see above.
  • Tests: enum resolution logic, persistence round-trip, coverage per convention — PASS. ReadingThemeResolutionTest (new, 5 cases, real function calls, no mocks), LibravaultThemeTest (+4 tests, real Robolectric Compose rendering asserting actual WindowCompat status-bar-icon state), MermaidThemeTest (updated to ConcreteReadingTheme), ReaderViewModelTest/VaultReaderViewModelTest/SettingsViewModelTest (SYSTEM round-trips through UI state / persistence), VaultReaderSettingsSheetUiTest (4th chip). No screenshot-baseline test was touched (ThemeScreenshotTest stays at 3 explicit cases, doesn't iterate .entries, still compiles) — reasonable, explicitly called out and not required by the AC's "Compose preview coverage," which the new UI test satisfies instead.

Bug fix found + verified as a real regression guard

The PR also fixes a latent bug it found while wiring SYSTEM: LibravaultTheme's old when only special-cased SEPIA and otherwise fell straight through to the ambient darkTheme value, so an explicit DARK/LIGHT pick had no actual effect — only the OS setting mattered. Confirmed by reading the diff directly:

-        readingTheme == ReadingTheme.SEPIA -> { isLightBackground = true; SepiaColorScheme }
-        darkTheme -> DarkColorScheme
-        else      -> { isLightBackground = true; LightColorScheme }

With darkTheme=false + readingTheme=DARK, this falls to else → Light. The new regression test an explicit DARK pick wins over an ambient light system setting sets exactly that combination and asserts isLightStatusBarIcons() is false — this would fail on the pre-fix code (traced through the logic above; I did not have Edit access to literally revert-and-run since that's out of scope for QA, but the trace is deterministic and unambiguous). Same for the LIGHT/dark-system mirror test. Real regression coverage, not vacuous.

Test run (real, not trusted from PR body)

Ran directly in the worktree (./gradlew ... --continue), fresh Android SDK on this box:

:core:ui:testDebugUnitTest
:core:domain:testDebugUnitTest
:feature:reader:testDebugUnitTest
:feature:vault:testDebugUnitTest
:feature:settings:testFdroidDebugUnitTest

BUILD SUCCESSFUL. Checked all 43 generated JUnit XML result files across these 5 modules directly: 0 failures, 0 errors across all suites (not just the new tests — this covers the full existing suites too, so no regressions surfaced). Spot-checked the new/changed suites individually:

  • ReadingThemeResolutionTest: 5/5 pass
  • LibravaultThemeTest: 7/7 pass (includes the 4 new SYSTEM/regression tests)
  • VaultReaderSettingsSheetUiTest: 5/5 pass

Regressions / related-area check

  • MermaidMarkdownComponents.kt (not touched by this PR) just forwards ReadingTheme as a parameter type to MermaidDiagramView, which does the resolving — no exhaustive when there, no compile risk.
  • ThemeScreenshotTest (Roborazzi baselines) untouched, still compiles (uses 3 explicit ReadingTheme values, not .entries) — consistent with the PR's "not touched, deliberately" note and not a regression.
  • Default reading theme (ReaderSettings.theme, VaultReaderSettings.theme) confirmed still ReadingTheme.DARK — unaffected.

Conventions (AGENTS.md)

  • Branch name feat/android-reading-theme-system-370 — follows convention.
  • Single well-organized commit, descriptive message, Closes #370.
  • No dependency/version changes in this diff — nothing to check against the version catalog.
  • Non-trivial change has tests per the new-behaviour bar (branch coverage for SYSTEM's success path + the found regression's failure path).

No blockers found. No status:blocked label present on the PR or issue #370.

QA verdict: PASS

@claude

claude Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #395 vs issue #370

Scope: Android "System" reading-theme option (ReadingTheme/AppReadingTheme gain a SYSTEM case, resolved to Dark/Light at render time).

Acceptance criteria

  • ✅ User can select "System" in Reading settings, both sheets. ReaderSettingsSheet and VaultReaderSettingsSheet both iterate ReadingTheme.entries generically, so the 4th chip needs no sheet-level changes; theme.name.lowercase().replaceFirstChar{it.uppercase()} renders it as "System". Verified with a new VaultReaderSettingsSheetUiTest case (System appears as a 4th theme chip and can be shown selected) — ran green.
  • ✅ System selected → theme matches OS light/dark, incl. Mermaid, and updates live. ReadingTheme.resolved(systemInDarkTheme) is the single resolution point; every consumer (LibravaultTheme, mermaidThemeName, toEpubPreferences/toVaultEpubPreferences) now takes ConcreteReadingTheme instead of the raw enum — an exhaustive when in resolved() means the build itself would fail to compile if any call site were missed, and I confirmed via grep that all 5 places that switch on ReadingTheme/AppReadingTheme are the ones the PR touched. Live updates are wired via LaunchedEffect keyed on the resolved theme (not the raw enum) at all three affected call sites — the right idiom, since isSystemInDarkTheme() recomposes on its own when the OS setting changes.
  • ✅ Existing Dark/Light/Sepia selections unaffected; no crash/migration issue. Additive enum value, no migration needed. UserPreferencesRepositoryTest's existing AppReadingTheme.values() loop (feature/settings) already covers SYSTEM's persistence round-trip with zero changes — confirmed by grep and by re-running that test class directly (green).
  • ✅ Tests: resolution logic, persistence round-trip, "preview" coverage. No @Preview-annotated composables exist anywhere in feature/ in this repo (checked) — the closest repo convention for this kind of coverage is a Robolectric Compose UI test (createComposeRule), which the PR added for the vault sheet. Reasonable given there's no actual preview convention to match.

What I ran

  • ./gradlew testDebugUnitTest --continue (full suite) → BUILD SUCCESSFUL, 438 actionable tasks.
  • feature/settings has fdroid/play product flavors, so it has no plain testDebugUnitTest task and the aggregate command above silently skips it (pre-existing repo/CI gap, not something introduced by this PR — worth a separate issue, not a blocker here). Ran it explicitly: ./gradlew :feature:settings:testFdroidDebugUnitTest :feature:settings:testPlayDebugUnitTest → BUILD SUCCESSFUL both flavors, SettingsViewModelTest 22/22 passing including the new reading theme change persists SYSTEM case.
  • Spot-checked every touched/new test file's XML results directly: ReadingThemeResolutionTest 5/5, LibravaultThemeTest 7/7 (incl. 4 new), MermaidThemeTest 2/2, ReaderViewModelTest 33/33, VaultReaderViewModelTest 24/24, VaultReaderSettingsSheetUiTest 5/5, UserPreferencesRepositoryTest — all 0 failures/errors/skips.

Mutation check (independent of the PR's own claimed mutation testing)

Manually reverted LibravaultTheme's color-scheme when in Theme.kt back to the pre-fix buggy form (darkTheme -> DarkColorScheme instead of resolvedTheme == ConcreteReadingTheme.DARK -> DarkColorScheme) and reran LibravaultThemeTest: the two new regression tests (an explicit DARK pick wins over an ambient light system setting, an explicit LIGHT pick wins over an ambient dark system setting) failed as expected, confirming they actually catch the bug rather than passing vacuously. Restored the file afterward; git status is clean and the full test re-ran green again.

Regression / convention check

  • No other when over ReadingTheme/AppReadingTheme exists outside the 5 call sites the PR updated (grep-confirmed).
  • Commit is a single Conventional-Commits-formatted commit (feat(android): ...) bundling the feature with a closely-coupled bug fix that resolution-logic itself required and documents clearly — reasonable given AGENTS.md's "integral" carve-out, not a blocking issue.
  • Branch name, PR→dev base, and Closes #370 linkage are all correct.

No gaps found against the issue's acceptance criteria or this repo's testing conventions.

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 21, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Principal review — PR #395

Verdict: auto-merge (risk:low confirmed, no CONFIRMED findings)

Risk classification sanity check

Re-ran classify_pr_risk.py origin/dev HEAD locally against the current head commit (c5c1008, the only commit on this branch — label wasn't stale): risk:low, 346 changed lines, no sensitive_paths match. Matches the applied label.

Verified, not just read

  • Tests actually run and pass, independent of CI's own claim: ran :core:ui:testDebugUnitTest --tests "*Theme*", :feature:reader:testDebugUnitTest --tests "*ReaderViewModelTest*|*MermaidThemeTest*", :feature:vault:testDebugUnitTest --tests "*VaultReaderViewModelTest*|*VaultReaderSettingsSheetUiTest*", :feature:settings:testFdroidDebugUnitTest --tests "*SettingsViewModelTest*|*UserPreferencesRepositoryTest*" locally — all green, and confirmed via the JUnit XML reports that each run actually executed non-zero tests (not a silent no-op match).
  • CI is green on the current head: Build & Test iOS, Build Android App, Unit & Integration Tests (JVM), and intake all pass.
  • No sensitive path touched: diffed file list against .github/agent-policy.yml's sensitive_paths — no match (no workflows, no crypto/vault modules, no screenshot baselines, no versions.toml).
  • No new networking dependency/call introduced anywhere in the diff.
  • The "4 chips need no sheet changes" claim checks out: ReaderSettingsSheet and VaultReaderSettingsSheet both iterate ReadingTheme.entries/AppReadingTheme.entries generically (confirmed by reading both files directly), so the new SYSTEM case really does surface with zero changes there, as claimed.
  • Exhaustiveness swept: grepped every file referencing ReadingTheme/AppReadingTheme for un-updated when blocks. MainActivity, Theme.kt, MermaidTheme.kt, toEpubPreferences()/toVaultEpubPreferences() are all exhaustive over the 4-case enum or the new ConcreteReadingTheme; nothing was missed.
  • The disclosed pre-existing bug fix is real and correctly scoped: read LibravaultTheme's old when — it's true that an explicit DARK/LIGHT pick previously fell through to the ambient darkTheme value with no effect. The new resolution-first structure fixes this as a documented side effect, and the two new regression tests (LibravaultThemeTest) genuinely exercise the fixed cases (explicit Dark under an ambient-light system and vice versa) rather than just re-asserting the old behavior.
  • "Updates live" acceptance criterion: LaunchedEffect keys were checked at all three call sites (EpubReaderScreen, VaultEpubReaderScreen, MermaidDiagramView) — each is keyed on the resolved theme, not the raw enum, so a live OS appearance flip while SYSTEM is selected actually re-triggers re-application, not just re-reads a stale value.

Minor nit (non-blocking)

EpubReaderScreen.kt and VaultEpubReaderScreen.kt reference ConcreteReadingTheme via its fully-qualified name inline (xyz.libravault.core.ui.theme.ConcreteReadingTheme.DARK, etc.) instead of importing it, while resolved is imported in the same files. Cosmetic only, no functional impact — not worth blocking on.

No CONFIRMED-severity findings, so no issue filed.

@github-actions github-actions Bot added status:approved-auto-merge Principal review passed, risk:low — will auto-merge and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 21, 2026
@github-actions
github-actions Bot merged commit 4084336 into dev Aug 21, 2026
25 checks passed
@libravault-xyz
libravault-xyz deleted the feat/android-reading-theme-system-370 branch August 21, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android enhancement New feature or request risk:low Principal review classified this PR as low risk status:approved-auto-merge Principal review passed, risk:low — will auto-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: add "System" reading-theme option (enum, resolution, settings UI)

1 participant