jarad2's picture
Add Android Bench sample: tasks and runs (part 14)
89995d3 verified
|
Raw History Blame Contribute Delete
4.24 kB

Reference solution: design notes

The reference moves the overview's rendering to Compose and its screen state into the existing BaseNoteModel, and leaves the navigation, the drawer, the main top bar, the create buttons, the editors and the dialogs as they are.

Architecture

  • Screens stay fragments, their content is Compose. NotallyFragment (Notes, label, Unlabeled, Archived, Deleted), RemindersFragment and SearchFragment keep their places in the navigation graph, so destinations, the drawer and the back stack behave as before; each returns a ComposeView drawing one Overview(). Subclasses only add what differs: filter chips, the loading indicator, how notes are arranged.
  • One list composable. NotesList draws headers and cards in a LazyColumn (list view) or a two-column LazyVerticalStaggeredGrid (grid view) with headers spanning both columns. It also draws the empty state. NoteCard renders text notes and lists, items, labels, images, reminders and the creation date under the same overview settings the view holder read (text size, title, line and item limits, date format, hidden labels and images, note colour).
  • Ordering is plain functions. The adapter's sort callbacks became comparators in NoteOrdering.kt: the user's sort preference with pinned notes first, the three reminder filters each with their own order and no headers, and sectioned() inserting the Pinned/Others/Archived headers.
  • Selection bar. SelectionBar replaces the toolbar shown in action mode, in the same place in activity_main.xml. SelectionActions lists, per folder, the same actions as the old menus, each as an icon or in the "More options" overflow, and runs them with the same confirmations and Undo snackbars; it replaces ModelFolderObserver.
  • Picker. PickNoteActivity and ConfigureWidgetActivity reuse NotesList and NoteCard, so the picker cards match the overview.

State and process death

BaseNoteModel (the screen's existing AndroidViewModel) now takes a SavedStateHandle and keeps the search text and the selected note ids in it. ActionMode publishes the selection as LiveData, remembers the anchor of a range selection and reports every change, so the saved ids stay current. After process death the ids are restored once the notes they refer to are listed again, which brings the selection bar back. The reminder filter and the search folder are saved in the fragments' instance state; scroll positions use Compose's saveable list and grid states per destination; the destination itself comes back through the navigation graph.

Behaviour that needed care

  • Range selection: long-pressing another note while notes are selected selects every note in between in the order shown, not in database order.
  • Search: matches are highlighted in titles, bodies and list items with the same snippet logic (HighlightableTextView now exposes it to Compose), and opening a result passes the search text to the editor.
  • A note created from a label view still gets the label; the picker still leaves out the note being edited; Delete all in Deleted still asks first.
  • Accessibility stays as it was: icon actions are labelled with their titles (Select All, Pin, Delete), the overflow button with More options (the old toolbar's label), the close icon with "Close" as on the old toolbar (now from a new @string/close), selected cards report their selected state, and the search field is an editable text field.

Trade-offs

  • The fragments and the navigation graph are kept rather than moving to a single Compose screen: the drawer, the top bar, the editors and the dialogs stay out of scope, and the change stays reviewable.
  • State lives in the existing BaseNoteModel instead of a new per-screen ViewModel, because the activity, the selection bar and all destinations already share it.
  • The old layouts for cards and headers, the adapter, the view holders and the sort callbacks are deleted; the Labels screen keeps its own layout, as the instruction allows.