feat(settings): let the user set a default mail account #175

Merged
JMR-dev merged 5 commits from feat-163-default-account into main 2026-07-03 00:44:01 +00:00
JMR-dev commented 2026-07-02 22:28:43 +00:00 (Migrated from github.com)

Summary

  • Persists a user-chosen defaultAccountId: String? preference in SettingsRepository/AppSettings, following the existing key/field/setter pattern used for the other settings there.
  • Adds a "Default account" switch to AccountSettingsScreen.kt (per-account screen) — deliberately not SettingsScreen.kt, which was just restructured and is the target of a separate in-flight ticket (#162), to avoid merge conflicts.
  • ComposeViewModel's from-account fallback now prefers, in order: an explicit fromAccountId -> the persisted default (only if it still names an existing account) -> the previous incidental available.first() behavior.
  • Deleting the default account clears the preference (SettingsRepository.clearDefaultAccountId, wired from AccountSettingsViewModel.removeAccount), and the compose fallback independently validates the persisted id against the live account list, so a stale id (e.g. from a Backup restore onto a device that never had that account) can never crash or select a nonexistent account.

Test plan

  • assembleDebug, testDebugUnitTest, lintDebug, ktlintCheck, detekt, compileDebugAndroidTestKotlin all pass locally (JDK 21).
  • New unit tests: SettingsRepositoryTest (default-account persists/clears at the toAppSettings() mapping layer), plus four new ComposeViewModelTest cases covering default-present, stale-default, no-default, and explicit-from-account-wins-over-default.
  • Emulator E2E (left to CI).

Closes #163

🤖 Generated with Claude Code

## Summary - Persists a user-chosen `defaultAccountId: String?` preference in `SettingsRepository`/`AppSettings`, following the existing key/field/setter pattern used for the other settings there. - Adds a "Default account" switch to `AccountSettingsScreen.kt` (per-account screen) — deliberately not `SettingsScreen.kt`, which was just restructured and is the target of a separate in-flight ticket (#162), to avoid merge conflicts. - `ComposeViewModel`'s from-account fallback now prefers, in order: an explicit `fromAccountId` -> the persisted default (only if it still names an existing account) -> the previous incidental `available.first()` behavior. - Deleting the default account clears the preference (`SettingsRepository.clearDefaultAccountId`, wired from `AccountSettingsViewModel.removeAccount`), and the compose fallback independently validates the persisted id against the live account list, so a stale id (e.g. from a Backup restore onto a device that never had that account) can never crash or select a nonexistent account. ## Test plan - [x] `assembleDebug`, `testDebugUnitTest`, `lintDebug`, `ktlintCheck`, `detekt`, `compileDebugAndroidTestKotlin` all pass locally (JDK 21). - [x] New unit tests: `SettingsRepositoryTest` (default-account persists/clears at the `toAppSettings()` mapping layer), plus four new `ComposeViewModelTest` cases covering default-present, stale-default, no-default, and explicit-from-account-wins-over-default. - [ ] Emulator E2E (left to CI). Closes #163 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.