Remember sort options for the pipelines and runs lists
Add a per-list sort control to each top bar and persist the choice in SharedPreferences so it survives restarts. - ui/screens/ListSort.kt: PipelineSort and RunSort enums plus pure comparators with explicit tie-breaks, and sortPipelines/sortRuns. ServerOrder/NewestFirst remain the defaults; a still-executing or unparseable-timestamp run sorts last. - ui/components/SortMenu.kt: the shared top-bar control, a distinct IconButton opening a Material 3 DropdownMenu of every option plus a divider and Reset, with the active choice checked. - data/SettingsRepository.kt + ui/AppViewModel.kt: store the sort key per list as a StateFlow; fromStorage falls back to the default for a stale/unknown/blank value. - ui/Format.kt: share parseInstant and durationSeconds so the printed duration and the sort key cannot disagree; PipelineLastRun.kt reuses the shared latest-run fold. - PipelineListScreen.kt/RunHistoryScreen.kt wire the control and sort; groupRunsByDay preserves the comparator's order. - ListSortTest.kt covers the comparators and storage fallback; RunGroupingTest.kt gains an explicit-order case. Verified on this tree with :app:testDebugUnitTest (167 tests, 0 failures), assembleDebug, and emulator-5556 persistence, the sort control, and Reset; captured in android/README.md.
This commit is contained in:
@@ -1435,3 +1435,126 @@ Verified on this tree (macOS, JDK 17 from Homebrew `openjdk@17`, Gradle 9.7.1,
|
||||
same `b2255066…` as the local file. The same APK was installed on the emulator
|
||||
and the pulled installed `base.apk` hashed to `b2255066…`, so the reviewed
|
||||
source is what was actually rendered.
|
||||
|
||||
## Remembered sort options for the pipelines and runs lists (16 Oct 2026)
|
||||
|
||||
Both list top bars gained a sort control that opens the choices plus a Reset, and
|
||||
the choice is remembered per list across restarts. `android/` only; nothing in
|
||||
the Pipelines server, its Go source, the Docker/compose files or the installer was
|
||||
touched, no dependency was added (the icons come from the already-declared
|
||||
`material-icons-extended`), no run was started from the app, and the attached
|
||||
Pixel 10 Pro Fold was never installed on or driven (every `adb`/emulator command
|
||||
targeted `emulator-5556`).
|
||||
|
||||
- **Pure comparators.** `ui/screens/ListSort.kt` defines the `PipelineSort`
|
||||
(`ServerOrder` default, `NameAsc`, `NameDesc`, `RecentRun`, `FewestStages`,
|
||||
`MostStages`) and `RunSort` (`NewestFirst` default, `OldestFirst`,
|
||||
`LongestDuration`, `ShortestDuration`, `PipelineName`, `Status`) enums plus one
|
||||
pure `pipelineComparator`/`runComparator` per sort and the `sortPipelines`/
|
||||
`sortRuns` helpers. Every comparator ends in an explicit tie-break, so equal
|
||||
primary keys always order the same way; a blank/unparseable timestamp and a run
|
||||
with no recorded duration (still executing) sort last regardless of direction
|
||||
instead of crashing. `ServerOrder` is a zero comparator, so the stable sort
|
||||
preserves the server's own order exactly. `RecentRun` uses the shared
|
||||
per-pipeline latest-run fold (`latestRunByPipeline`, extracted from the
|
||||
last-run badge join in `PipelineLastRun.kt`) rather than folding the history
|
||||
twice.
|
||||
- **Shared time helpers.** `ui/Format.kt` gained `parseInstant` (moved out of
|
||||
`PipelineLastRun.kt`) and `durationSeconds`; the existing `formatDuration` now
|
||||
delegates to `durationSeconds`, so the printed duration and the sort key can
|
||||
never disagree.
|
||||
- **Shared control.** `ui/components/SortMenu.kt` is the one top-bar control both
|
||||
screens use: an `IconButton` (its own glyph and content description, so it
|
||||
cannot collide with the adjacent Refresh action or a future search entry point)
|
||||
opening a `DropdownMenu` of the options — the active one carries a leading
|
||||
check glyph, not colour alone — then a divider and Reset. It has no geometry
|
||||
literals and anchors correctly at both window widths. The glyph is
|
||||
`Icons.AutoMirrored.Filled.Sort` (the RTL-aware form, so no `Icons.Default.Sort`
|
||||
deprecation warning at build time and the arrow mirrors correctly).
|
||||
- **Persistence.** `data/SettingsRepository.kt` stores each choice as its stable
|
||||
storage key (`pipeline_sort`, `run_sort`) with a `StateFlow`, exactly like the
|
||||
server URL/workspace; `AppViewModel` exposes them and their setters. The list
|
||||
screens resolve the stored string with `PipelineSort.fromStorage`/
|
||||
`RunSort.fromStorage`, which fall back to the default for a stale, unknown or
|
||||
blank value (the repository stays unaware of the UI enums).
|
||||
- **Grouping.** `groupRunsByDay` now takes the ordering comparator and preserves
|
||||
the order it produces (the default is still newest first, so the default output
|
||||
is unchanged); the run list groups by day in that order and sorts within a day
|
||||
by the same comparator.
|
||||
|
||||
Verified on this tree (macOS, Homebrew JDK 25 (`openjdk@25`), Gradle 9.7.1,
|
||||
`ANDROID_HOME=/Users/alan/Library/Android/sdk`, `--offline`):
|
||||
|
||||
- `gradle --offline :app:testDebugUnitTest --rerun-tasks` → the 21 test-result XMLs
|
||||
aggregate to **167 tests, 0 failures, 0 errors, 0 skipped** (the new
|
||||
`ListSortTest` has 13 cases covering the storage fallback for both enums, server
|
||||
order, case-insensitive name/stage sorts with their id/name tie-breaks,
|
||||
recent-run no-run-last and run-id tie-breaks, newest/oldest with unparseable
|
||||
timestamps last, duration longest/shortest with a still-executing run last and
|
||||
equal-duration tie-break, pipeline-name/status sorts, and that equal keys order
|
||||
identically whatever the input order; `RunGroupingTest` gained an explicit-order
|
||||
case). `compileDebugKotlin` emits no warnings.
|
||||
- `gradle --offline :app:assembleDebug --rerun-tasks --no-build-cache` (a full
|
||||
rebuild, so the published binary is exactly this tree) succeeded →
|
||||
`app-debug.apk` **17,879,721 bytes**, sha256
|
||||
`cb68fbb13e469e81c15837ba95314a2ab40f1f29f4769e4a615bbc0ce4636a30`.
|
||||
- On `emulator-5556` (`FoldB_API_36`, 2208x1840, density 420, dark mode) against
|
||||
the live server `ws://10.0.2.2:8080/connect`, driven with `adb shell input` and
|
||||
`uiautomator dump`; every capture below was written with
|
||||
`android/scripts/capture_png.sh -s emulator-5556` (validated PNG, named display
|
||||
id) into `…/artifacts/87/1/`. The live server's pipeline set churns while the
|
||||
maintenance workflow runs, so the concrete names differ between captures, but
|
||||
each ordering was read back from the accessibility tree:
|
||||
- Wide (2208x1840 ≈ 841dp): tapping `Sort pipelines` opened the six options plus
|
||||
`Reset` (`01_wide_pipelines_sort_open.png`); choosing `Name Z–A` reordered the
|
||||
list to descending names and stored `pipeline_sort=name_desc`
|
||||
(`02_wide_pipelines_name_za.png`). `Sort runs` opened the six run options plus
|
||||
`Reset` (`03_wide_runs_sort_open.png`); `Oldest first` showed run 1 → 2 → 3 and
|
||||
stored `run_sort=oldest_first` (`04_wide_runs_oldest_first.png`). The sort icon
|
||||
and the adjacent `Refresh` stay separate actions at both widths (the icon's own
|
||||
`Sort pipelines`/`Sort runs` content description sits left of `Refresh …`).
|
||||
- **Persistence proof.** After setting pipelines `Name Z–A` and runs
|
||||
`Oldest first`, `run-as net.awan.pipelines cat shared_prefs/pipelines_settings.xml`
|
||||
showed `pipeline_sort=name_desc`, `run_sort=oldest_first`. `am force-stop
|
||||
net.awan.pipelines` (verified `pidof` empty) then `am start` and a fresh
|
||||
`uiautomator dump` showed the pipelines list still in descending-name order
|
||||
(`05_wide_pipelines_name_za_after_relaunch.png`) and the runs list still oldest
|
||||
first, run 1 → 2 → 3 (`06_wide_runs_oldest_first_after_relaunch.png`), with no
|
||||
interaction.
|
||||
- `Reset` on the pipelines menu restored the server order (id 1 → 5 → 11 → 6 →
|
||||
4 → 9 → 3) and stored `pipeline_sort=server_order`; `Reset` on the runs menu
|
||||
restored `run_sort=newest_first` and run 87 → 86 → 85 → 84 → 83 → 82
|
||||
(`10_narrow_runs_reset_newest_first.png`).
|
||||
- Narrow (`adb shell wm size 1080x2340` ≈ 411dp; `wm size reset` afterwards):
|
||||
both `Sort pipelines` and `Sort runs` opened their menus
|
||||
(`07_narrow_runs_sort_open.png`); `Status` ordered Canceled → Failed → Failed …
|
||||
and stored `run_sort=status` (`08_narrow_runs_status_sort.png`); `Most recent
|
||||
run` ordered the rows by recency 10h → 3d → 3d → 4d → 4d → 5d and put the
|
||||
runless pipeline (`no runs recorded`) last, storing `pipeline_sort=recent_run`
|
||||
(`09_narrow_pipelines_recent_run.png`).
|
||||
- **Stale-key tolerance on device.** With `pipeline_sort` and `run_sort` set to
|
||||
`garbage_key` in `shared_prefs/pipelines_settings.xml` (verified via `run-as …
|
||||
cat`, then replaced by push + `run-as … cp`) and the app force-stopped and
|
||||
relaunched, the pipelines list came back in the server's order (id 1 → 5 → 11 →
|
||||
6 → 4 → 9 → 3, `11_narrow_pipelines_stale_key_falls_back_to_server_order.png`)
|
||||
and the runs list in newest-first (run 87 → 86 → 85), with no crash.
|
||||
- `adb -s emulator-5556 logcat -d | grep -c 'FATAL EXCEPTION'` and `… | grep -c
|
||||
'E AndroidRuntime'` each returned 0; no run was started from the app.
|
||||
- **APK publish.** `app-debug.apk` was copied to
|
||||
`~/.local/share/pipelines/data/artifacts/87/1/pipelines-debug-wip-3480461.apk`
|
||||
(`3480461` = `git rev-parse --short HEAD`); `shasum -a 256` matched. `curl -I
|
||||
http://10.0.0.249:8080/artifacts/87/1/pipelines-debug-wip-3480461.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 17879721`, and a streamed `GET | shasum -a 256` returned the
|
||||
same `cb68fbb1…` as the local file. The deterministic full-rebuild APK was
|
||||
installed on `emulator-5556` (`adb -s emulator-5556 install -r`) and the pulled
|
||||
installed `base.apk` hashed to `cb68fbb1…`, so the reviewed source is what was
|
||||
actually rendered. At 17.1 MiB it exceeds the server's 8 MiB per-file inventory
|
||||
cap, so it is served by direct URL only.
|
||||
|
||||
Not verified in this pass: `:app:lintDebug` was not run (its only reported issues
|
||||
are the two pre-existing `NewApi` errors for `android:windowLightNavigationBar`);
|
||||
a real hardware fold to the cover display was not exercised (narrow was produced
|
||||
with `wm size`); no before/after baseline build was captured, since the change is
|
||||
additive and the default orders are asserted unchanged by the `ServerOrder`/
|
||||
`NewestFirst` unit tests.
|
||||
|
||||
Reference in New Issue
Block a user