Allow user to re-order accounts in the settings view #164

Closed
opened 2026-07-02 21:10:20 +00:00 by JMR-dev · 0 comments
JMR-dev commented 2026-07-02 21:10:20 +00:00 (Migrated from github.com)

Context

Accounts have no user-controlled order today: AccountDao (data/local/dao/AccountDao.kt)
queries SELECT * FROM accounts ORDER BY email for both observeAll() and getAll(), and
AccountEntity (data/local/entity/AccountEntity.kt) has no ordering column. Every place that
lists multiple accounts consumes that same alphabetical order: the drawer's account switcher
(AccountSwitcher in ui/mailbox/FolderDrawer.kt), the unified-inbox account chips
(AccountFilterRow in ui/mailbox/MailboxScreen.kt, "the sliding buttons in the message
selection/home view" per the ticket), and SettingsScreen.kt's account list. This ticket adds an
explicit, user-editable order that all of these follow.

Scope

  • Add a sortOrder: Int column to AccountEntity, with a Room migration
    (MIGRATION_17_18, following the established pattern in data/local/Migrations.kt — e.g.
    MIGRATION_16_17/MIGRATION_14_15: a nullable-or-defaulted column added via ALTER TABLE,
    with the fresh-install schema in AccountDatabase.kt matching exactly so migrated and clean
    installs validate identically). Export the updated schema under app/schemas and add a
    migration test.
  • Assign sortOrder on account creation (append to the end — e.g. current max + 1) and change
    AccountDao.observeAll() / getAll() to ORDER BY sortOrder.
  • Add a DAO method to persist a new order (e.g. a batch update given an ordered list of ids).
  • Add drag-to-reorder UI for the account list in SettingsScreen.kt (no existing
    reorderable-list component or dependency in this codebase — this is new UI work; a
    long-press-and-drag LazyColumn reorder is the common Compose pattern, implemented with
    pointerInput/Modifier.offset rather than pulling in a new library, consistent with this
    repo's preference for no unnecessary dependencies).
  • Confirm the new order propagates, with no additional per-surface logic needed, to:
    • The drawer's AccountSwitcher dropdown (FolderDrawer.kt) — consumes accounts: List<Account>
      from the same repository query.
    • The unified-inbox AccountFilterRow chips (MailboxScreen.kt) — same.
    • SettingsScreen.kt's own account list.

Acceptance criteria

  • Reordering accounts in Settings persists across app restarts.
  • The new order is reflected, without further per-screen changes, in the drawer's account
    switcher and the unified-inbox account filter chips.
  • A Room migration test covers MIGRATION_17_18; existing accounts get a stable initial order
    (e.g. their current alphabetical order) on upgrade rather than an undefined one.

Relevant files

  • data/local/entity/AccountEntity.kt, data/local/dao/AccountDao.kt,
    data/local/Migrations.kt, data/local/AccountDatabase.kt, app/schemas,
    ui/settings/SettingsScreen.kt, ui/mailbox/FolderDrawer.kt, ui/mailbox/MailboxScreen.kt.

Dependencies

Related to #163 (default account) — see that ticket's note on whether "default" and "first in
this order" should be linked or independent concepts.

## Context Accounts have no user-controlled order today: `AccountDao` (`data/local/dao/AccountDao.kt`) queries `SELECT * FROM accounts ORDER BY email` for both `observeAll()` and `getAll()`, and `AccountEntity` (`data/local/entity/AccountEntity.kt`) has no ordering column. Every place that lists multiple accounts consumes that same alphabetical order: the drawer's account switcher (`AccountSwitcher` in `ui/mailbox/FolderDrawer.kt`), the unified-inbox account chips (`AccountFilterRow` in `ui/mailbox/MailboxScreen.kt`, "the sliding buttons in the message selection/home view" per the ticket), and `SettingsScreen.kt`'s account list. This ticket adds an explicit, user-editable order that all of these follow. ## Scope - [ ] Add a `sortOrder: Int` column to `AccountEntity`, with a Room migration (`MIGRATION_17_18`, following the established pattern in `data/local/Migrations.kt` — e.g. `MIGRATION_16_17`/`MIGRATION_14_15`: a nullable-or-defaulted column added via `ALTER TABLE`, with the fresh-install schema in `AccountDatabase.kt` matching exactly so migrated and clean installs validate identically). Export the updated schema under `app/schemas` and add a migration test. - [ ] Assign `sortOrder` on account creation (append to the end — e.g. current max + 1) and change `AccountDao.observeAll()` / `getAll()` to `ORDER BY sortOrder`. - [ ] Add a DAO method to persist a new order (e.g. a batch update given an ordered list of ids). - [ ] Add drag-to-reorder UI for the account list in `SettingsScreen.kt` (no existing reorderable-list component or dependency in this codebase — this is new UI work; a long-press-and-drag `LazyColumn` reorder is the common Compose pattern, implemented with `pointerInput`/`Modifier.offset` rather than pulling in a new library, consistent with this repo's preference for no unnecessary dependencies). - [ ] Confirm the new order propagates, with no additional per-surface logic needed, to: - The drawer's `AccountSwitcher` dropdown (`FolderDrawer.kt`) — consumes `accounts: List<Account>` from the same repository query. - The unified-inbox `AccountFilterRow` chips (`MailboxScreen.kt`) — same. - `SettingsScreen.kt`'s own account list. ## Acceptance criteria - Reordering accounts in Settings persists across app restarts. - The new order is reflected, without further per-screen changes, in the drawer's account switcher and the unified-inbox account filter chips. - A Room migration test covers `MIGRATION_17_18`; existing accounts get a stable initial order (e.g. their current alphabetical order) on upgrade rather than an undefined one. ## Relevant files - `data/local/entity/AccountEntity.kt`, `data/local/dao/AccountDao.kt`, `data/local/Migrations.kt`, `data/local/AccountDatabase.kt`, `app/schemas`, `ui/settings/SettingsScreen.kt`, `ui/mailbox/FolderDrawer.kt`, `ui/mailbox/MailboxScreen.kt`. ## Dependencies Related to #163 (default account) — see that ticket's note on whether "default" and "first in this order" should be linked or independent concepts.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: JMR-dev/LibreMail#164