Add long-press artifact multi-select with bulk copy and share

Long-pressing any artifact — a gallery tile in the run summary or a row in
the stage pane's per-visit list — now enters artifact selection: the pressed
item is selected with the app's selected treatment and further taps toggle
items instead of opening them. A contextual bar replaces the surface's top
bar while selecting, showing the count plus Copy links, Share and a close;
it carries the same pane safe-area insets as the bar it replaces, uses 48dp
IconButtons and leaves selection mode on Back before the surface's own Back
runs. Selection applies only to artifacts, never the runs or pipelines lists.

The selection is one shared host: ArtifactSelectionScaffold owns the
remembered ArtifactSelection, the resolvedSelection lookup, the bulk
copy/share actions, the SnackbarHostState and the pane-scoped BackHandler,
and both RunDetailScreen (summary grid) and StageDetailPane (per-visit list)
go through it, so neither screen owns its own SnackbarHostState or
BackHandler. The immutable ArtifactSelection (enter/toggle/selectAll/clear)
treats selection mode as "one or more urls selected", so it can never
restore half-applied; rememberArtifactSelection saves it via a listSaver and
reseeds per run/visit.

Copy links resolves every selected url against the configured server through
the existing resolvedArtifactUrl (no hardcoded host), writes one absolute
link per line through the new single Clipboard.copyText path (now also used
by the code blocks, pipeline source, artifact row and viewer), and confirms
the number of lines actually produced in a Snackbar. Share fetches every
selected artifact through the existing client, reuses the single-item
writeSharedArtifact (same bounded cache, FileProvider and prune), and sends
one ACTION_SEND_MULTIPLE typed by bulkShareMimeType (the common type, else
the wildcard) with the count in the chooser title; when any fetch fails the
whole set degrades in the same action to its resolved links shared as text.

Pure helpers and tests: ArtifactSelectionTest covers enter, toggle,
deselect-last, select-all/clear, the restored state, the one-per-line link
formatting and the labels; ArtifactSharingTest gains shareTargets and
bulkShareMimeType cases. Unit tests plus assembleDebug pass (168 tests,
21 classes, 0 failures). android/README.md documents the model, action bar
and the bulk share flow, and the doc-accuracy pass records that the bulk
copy writes links in gallery (candidate) order.

No new dependency (icons come from the declared material-icons-extended).
This commit is contained in:
2026-10-16 08:51:03 +01:00
parent 1195535852
commit 0b74903a00
12 changed files with 1039 additions and 83 deletions
+191
View File
@@ -1820,3 +1820,194 @@ Not verified in this pass: receiving the shared file inside a third-party app (t
chooser was observed, not an app's import); the 24 h / 64 MiB prune bound was not
reached on the emulator (only two small files were written).
## Multi-select artifacts: bulk copy and share (16 Oct 2026)
A long-press on any artifact in a gallery now enters artifact selection: that item
becomes selected with the app's tonal selected treatment, further taps toggle
items instead of opening them, and a contextual action bar offers **Copy links**,
**Share** and a close. It lives in both artifact surfaces — the run-summary grid
(`RunSummaryTab` → `ArtifactGallery`) and the stage pane's per-visit artifacts
list (`ArtifactsSection`) — and nowhere else (runs/pipelines lists are untouched).
- **Model.** New `ui/graph/ArtifactSelection.kt`: an immutable `ArtifactSelection`
keyed by the artifact url (`enter`, `toggle`, `selectAll`, `clear`, `contains`);
selection mode is exactly "one or more urls selected", so it can never restore
half-applied. `ArtifactSelectionSaver` (a `listSaver`) + `rememberArtifactSelection`
save/restore it across configuration and reseed per run/visit.
- **Action bar.** `ArtifactSelectionBar` is the pane's `TopAppBar` (it replaces the
normal bar while selecting): title `N selected`, a close, a copy and a share, all
Material 3 `IconButton`s (the measured 117x117 px = **48dp** targets) with accurate
descriptions ("Exit selection", "Copy selected links", "Share selected artifacts").
It applies the same `paneSafeArea()` top/horizontal insets as the bar it replaces,
so it stays inside the status bar/cutout and above — never over — the items.
- **Copy links.** `artifactSelectionLinks` resolves each selected url against the
configured server through the existing `resolvedArtifactUrl` (no hardcoded host),
joins one resolved absolute link per line, and copies it through the new one-line
`components/Clipboard.copyText` (the single copy path, now also used by the code
blocks, the pipeline source, the artifact row and the viewer). A `Snackbar`
confirms `Copied N links`. Back leaves selection mode first (a pane-scoped
`BackHandler`), only then runs the pane's own Back.
- **Bulk share.** `shareArtifacts` fetches every selected artifact through the
existing `AppViewModel.fetchArtifactBytes` and reuses the single-item
`writeSharedArtifact` (same bounded cache, same `FileProvider`, same
`pruneSharedArtifacts`) before one `Intent.ACTION_SEND_MULTIPLE` carrying every
uri. Its type is the new pure `bulkShareMimeType` (the common type, else the
wildcard) and its count is the chooser title. If **any** fetch fails the whole set
degrades in the same action to the resolved links as `text/plain`
(`shareLinks`). No parallel share path and no new dependency (icons come from the
declared `material-icons-extended`).
- **Pure helpers / tests.** `ArtifactSelectionTest` (enter, toggle, deselect-last,
select-all + clear, restored state, the one-per-line link formatting, the labels)
and two new `ArtifactSharingTest` cases (`shareTargets` resolution/drop,
`bulkShareMimeType` common-type vs wildcard).
Evidence (macOS, JDK 17 Homebrew `openjdk@17`, Gradle 8.11.1 from the wrapper
cache, `ANDROID_HOME=~/Library/Android/sdk`):
- `gradle :app:testDebugUnitTest :app:assembleDebug --console=plain` →
`BUILD SUCCESSFUL`; the result XMLs aggregate to **168 tests across 21 classes,
0 failures, 0 errors, 0 skipped** (up from 157: the new `ArtifactSelectionTest`
plus the two bulk-share cases). `app-debug.apk` is 17,913,089 bytes; the current
tree's sha256 and the APK publish are recorded in the section below.
- `gradle :app:lintDebug` → the same **2 pre-existing** `windowLightNavigationBar`
NewApi errors (`values/themes.xml`, `values-night/themes.xml`) and 39 warnings;
the only warning attributed to a touched file is the pre-existing
"Modifier parameter should be the first optional parameter" on `StageDetailPane`.
- On `emulator-5554` (never the physical Pixel, never `emulator-5556`; 2076x2152,
density 390) against the live server, run 94's summary and per-visit list were
driven. Every capture is in `captures/selection/` (git-ignored) and was validated
by `scripts/capture_png.sh -s emulator-5554`:
- `01_longpress_selection.png` — long-press on `grid_cell_share.png` entered the
mode: the action bar reads `1 selected` and the cell shows the tonal ring +
check badge (its per-item share button hidden).
- `02_several_toggled.png` — three cells then a non-image row toggled on:
`4 selected`; the row wears the `secondaryContainer`/`onSecondaryContainer`
treatment.
- `03_bulk_copy_confirmation.png` — **Copy links** showed the `Copied 4 links`
Snackbar; pasting the clipboard into the Pipelines search field
(`06_clipboard_pasted_links.png`) yielded exactly the four resolved absolute
links, one per line, against the configured server
(`http://10.0.2.2:8080/artifacts/94/1/grid_cell_share.png` … `/94/2/lint-results-debug.txt`),
in the gallery's (candidate) order.
- `04_bulk_share_intent.png` — sharing the mixed 4 selected ran the **file path**:
`ActivityTaskManager: START … action.CHOOSER … clip={*/* hasLabel(11) 4 items:
{U(content)} x4}`, chooser titled "Sharing 4 files" (mixed types → wildcard).
- `05_bulk_share_images_png.png` — the 3 image cells alone resolved to a concrete
type: `clip={image/png hasLabel(11) 3 items: …}`, chooser "Sharing 3 images".
- `08_bulk_share_fallback_links.png` — with `cmd connectivity airplane-mode
enable` (10.0.2.2 unreachable) the same Share **fell back** in one action to
`text/plain`: `action.SEND`, chooser "Sharing text" showing the three resolved
links newline-joined. Airplane mode was then disabled.
- `07_per_visit_selection.png` — the stage pane's per-visit list enters the same
mode (`3 selected`) with the action bar in the pane's safe area.
- `09_rotation_restored.png` — after `user_rotation 1` (2152x2076) the `2 selected`
selection restored fully, not half-applied.
- Back in selection mode exited the mode and left run 94 open (0 "Exit selection"
nodes afterwards, the normal app bar returned); closing the stage pane by
tapping the run peek and reopening the same visit showed no selection,
confirming the pane-close clear.
- `adb -s emulator-5554 logcat -d` held 0 `FATAL EXCEPTION` / 0 `E AndroidRuntime`.
- **APK publish.** `app-debug.apk` copied to
`~/.local/share/pipelines/data/artifacts/97/1/pipelines-debug-wip-1195535.apk`
(`1195535` = `git rev-parse --short HEAD`); `curl -I/-o` against
`http://10.0.0.249:8080/artifacts/97/1/pipelines-debug-wip-1195535.apk` (and
`10.0.0.75`) returned `HTTP 200`, `Content-Type:
application/vnd.android.package-archive`, 17,913,089 bytes.
Not verified in this pass: a narrow-window layout of the selection bar (the
emulator is the 851dp-wide inner display); receiving the bulk share in a
third-party app (the chooser was observed, not an import).
## Artifact selection: one shared host (16 Oct 2026)
The first pass left the run-summary and stage-pane selection wiring copy-pasted,
and the refactor that removed the duplication had outrun this README. The final
tree keeps one shared host: both `RunDetailScreen` (the run-summary grid) and
`StageDetailPane` (the per-visit list) call `ArtifactSelectionScaffold`, which
owns the remembered `ArtifactSelection`, the `resolvedSelection` lookup, the
single `artifactSelectionActions` copy/share implementation, the `SnackbarHostState`
and the pane-scoped `BackHandler`, and renders the contextual
`ArtifactSelectionBar` in place of the surface's own top bar while selecting.
Neither screen owns a `SnackbarHostState` or a `BackHandler` of its own.
`artifactSelectionActions` resolves every selected url through
`resolvedArtifactUrl` (never a hardcoded host), copies the resolved links one per
line through the one `ClipboardManager.copyText`, and shares every selected
artifact through the single-item `writeSharedArtifact`/`shareArtifacts` path.
`artifactSelectionLinks` resolves each selected url; `artifactSelectionActions`
confirms the number of lines it actually produced (`text.lines().size`) rather
than the raw selection size, so an absolute url plus an unresolvable relative one
under no configured server reports the true count. `writeSharedArtifact` captures a
non-null `fileBytes` from the `shareDelivery` check instead of asserting
`bytes!!`. `ArtifactSelection.selectAll` is kept: it is the task's explicit
select-all test surface even though no UI calls it.
Evidence, re-run on the same environment (`JAVA_HOME=/opt/homebrew/opt/openjdk@17`,
Gradle 8.11.1 from `~/.gradle/wrapper/dists`, `ANDROID_HOME=~/Library/Android/sdk`,
`emulator-5554` only):
- `gradle :app:testDebugUnitTest :app:assembleDebug --rerun-tasks --console=plain`
→ `BUILD SUCCESSFUL`; the result XMLs aggregate to **168 tests across 21 classes,
0 failures, 0 errors, 0 skipped** (`ArtifactSelectionTest` grew to 9 with
`resolvedSelectionKeepsOnlyTheCandidatesStillSelected`). `app-debug.apk` is
17,913,089 bytes; its current sha256 and publish are in the doc-accuracy note
below.
- Rebuilt APK reinstalled on `emulator-5554` (2076x2152, density 390); each frame
validated by `scripts/capture_png.sh -s emulator-5554` and kept in
`captures/selection-run100-final/` and
`~/.local/share/pipelines/data/artifacts/100/1/`:
- `01_longpress_selection.png` — long-press on `grid_cell_share.png` entered the
mode: bar reads `1 selected`, the cell wears the tonal ring + check, and every
per-item `Share`/`Open`/`Copy link` node is gone from the `uiautomator` dump.
- `02_several_toggled.png` — three cells then the `lint-results-debug.txt` row
toggled on → the action bar reads `4 selected`; the two action-bar
`IconButton`s measure **117x117 px = 48dp** with the descriptions
"Copy selected links" / "Share selected artifacts" ("Exit selection" for the
close).
- `03_bulk_copy_confirmation.png` — **Copy links** showed the `Copied 4 links`
Snackbar, and the system clipboard preview under the share bar showed the
resolved absolute link (`http://10.0.2.2:8080/artifacts/94/1/grid_cell_share.png…`).
- `04_bulk_share_intent.png` — **Share** of the mixed 4 ran the **file path**
(`dumpsys activity activities`: `Intent { act=android.intent.action.CHOOSER …
clip={*/* hasLabel(11) 4 items: {U(content)} x4} (has extras) }`), i.e. one
`ACTION_SEND_MULTIPLE` carrying 4 fetched files, typed by the mixed-set
wildcard. The file path ran because the configured server (`10.0.2.2:8080`)
was reachable, so every fetch returned bytes; the unchanged `shareLinks`
fallback (unit-covered by `shareDeliveryIsAFileOnlyWhenTheFetchReturnedBytes`)
is the branch a failed fetch would take in the same action.
- `05_per_visit_selection.png` — the stage pane's per-visit list enters the same
mode (`1 selected`) with the bar inside the pane safe area.
- Back exited selection mode first and left Run 94 open (0 "Exit selection" nodes
afterwards, `Run 94` still present); `adb -s emulator-5554 logcat -d` held 0
`FATAL EXCEPTION` / 0 `E AndroidRuntime`.
- **APK publish.** `app-debug.apk` copied to
`~/.local/share/pipelines/data/artifacts/100/1/pipelines-debug-wip-1195535.apk`
(`1195535` = `git rev-parse --short HEAD`); `curl` against
`http://10.0.0.249:8080/artifacts/100/1/pipelines-debug-wip-1195535.apk` (and
`10.0.0.75`) returned `HTTP 200`, `Content-Type:
application/vnd.android.package-archive`, 17,913,089 bytes.
- **Doc-accuracy pass (16 Oct 2026).** The `ArtifactSelection.kt` doc comment and
this README's "in selection order" claim said the bulk copy preserves selection
order; it actually writes one resolved link per line in gallery (candidate)
order, because `resolvedSelection` filters the surface's own candidates. Both now
state candidate order; no runtime behavior changed. Re-verified on the same
environment: `gradle :app:testDebugUnitTest :app:assembleDebug --rerun-tasks
--console=plain` → `BUILD SUCCESSFUL`, the result XMLs aggregate to **168 tests
across 21 classes, 0 failures, 0 errors, 0 skipped**; `app-debug.apk` is
17,913,089 bytes, sha256
`a6d5caeb0c1e69da879aabfcc7df2eec09e4a44c85000adba3444558a1d3d82b`. The sha is
not a stable tree fingerprint — it moves with any source edit, because the debug
APK embeds Kotlin source info (a comment-only edit to `ArtifactSelection.kt` left
only `classes6.dex` different) — so run 100's build read `763806783f…`. The APK
was published to
`~/.local/share/pipelines/data/artifacts/100/3/pipelines-debug-wip-1195535.apk`;
`curl` against
`http://10.0.0.75:8080/artifacts/100/3/pipelines-debug-wip-1195535.apk` (and
`10.0.0.249`) returned `HTTP 200`, `Content-Type:
application/vnd.android.package-archive`, 17,913,089 bytes.
Not verified in this pass: the link fallback on-device (the reachable server ran
the file path); a narrow-window layout of the selection bar; receiving the bulk
share in a third-party app (the chooser was observed, not an import).