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

Reference solution: design notes

The goal of the reference is the instruction's "for the people using the app, nothing changes": five screens are redrawn by Compose, every visible detail and stored value stays as it was. Where Compose offered a "better" default that would show (other paddings, other selection colors, actions moved to a menu), the old look wins.

How the work is split

Screen Host Composables State
Settings SettingsActivity (setContent) compose/settings/SettingsScreen, ManageVisibleTabsAlertDialog SettingsUiState is rebuilt from config on every change; the activity keeps the toggles that need a confirmation or a password first
Manage favorites FavoritesActivity compose/favorites/ManageFavoritesScreen the favorites set in config, mirrored in one mutableStateOf
Text editor ReadTextActivity compose/editor/ReadTextScreen, EditorSearchBar, SaveAsAlertDialog ReadTextViewModel: text, cursor, open search; the unsaved text also goes into the saved instance state (process death)
Archive viewer DecompressActivity compose/decompress/DecompressScreen DecompressViewModel: the parsed listing; the browsed folder and the password in its SavedStateHandle
Files tab ItemsFragment (a View in the main screen's pager) hosting a ComposeView compose/files/* FilesTabState: items, selection, breadcrumbs, search placeholders, scroll position per folder
  • The activities stay the entry points and keep talking to the rest of the app (intents, SAF and root dialogs, password prompts). The composables are stateless where they can be: they get state and callbacks, so the Robolectric tests drive them without an activity.
  • The Files tab cannot become a Compose screen of its own: the main screen's pager, its toolbar and the other tabs stay View based. ItemsFragment keeps loading folders, searching and running the actions; it only hosts Compose. The selection bar (FilesActionModeBar) is a second ComposeView on top of the activity content, so that it covers the main toolbar like the old action mode did.
  • The actions on a selection are shared with the View based lists that remain (Recents, Storage, mime types), so both run the same code: helpers/FileItemActions (whole selection: rename, share, copy, move, delete, …), with FirstItemActions (first selected item: shortcut, copy path, set as, open with/as) and ArchiveItemActions (compress, decompress). The helpers preserve the same action semantics as ItemsAdapter.

Behaviour preservation

  • Settings keys and values. Every switch reads and writes the same config property as before; nothing is renamed or migrated, so an update from today's build keeps every choice. Rows only shown in some situations (English language before Android 13, root access, the language picker from Android 13) keep their conditions.
  • Action placement. Top bar and selection bar actions keep the showAsAction of the old menus: "always" items are icons, "never" items are in the overflow menu, "ifRoom" items follow AppCompat's ActionBarPolicy for the screen width (maxToolbarActionIcons), so on a phone in portrait Share and Select all stay in the menu as before.
  • Selection look. List rows use the selector's highlight (Material You aware), grid cells the translucent foreground, and only folders show the check mark in the grid, as the old adapter did.
  • Dimensions. Paddings come from SimpleTheme.dimens.padding, and sizes from the same Fossify dimension resources the XML layouts used (file_picker_icon_size, selection_check_size, breadcrumbs_layout_height, …), so the screens line up pixel for pixel. The only literal sizes are the fast scroller's, which came from the RecyclerViewFastScroller library, not from Fossify.
  • Editor. Text, cursor and an open search survive rotation through the ViewModel (not the bundle, so large files do not hit the binder limit); unsaved edits still survive the app being killed, through the saved instance state as today. Searching never edits the text.
  • Archive viewer. The folder you are in survives rotation (as required by the instruction); the password prompt and extraction to the picked folder are unchanged.

Trade-offs

  • ItemsFragment keeps @Suppress("TooManyFunctions"). The start-state detekt baseline covers the finding under the class signature that includes the breadcrumbs view's listener. The instruction keeps the baselines as they are, and the functions the pager fragment base class and ItemOperationsListener require are already at the rule's threshold. Splitting the fragment further would only move those overrides into delegates. The other suppressions sit on shared action code with the same findings covered by the ItemsAdapter baseline.
  • Text sizes. The file list follows the user's font size setting (FileItemStyle, computed like the adapters did); fixed texts keep the XML's sp values.
  • Dependencies. Compose and kotlinx-collections-immutable are declared directly, at versions that leave every library already on the start commit's release classpath at its version; the test libraries are test-only.