From 49f40bfe4544d21ff377de623638237f6c532b43 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 18 Oct 2026 00:50:15 +0100 Subject: [PATCH] android: move the detail and visit selectors to a bottom strip on narrow windows The two selectors that were a horizontally scrolling Material 3 tab row at the top of a surface become one deliberate treatment. On a narrow window the shared detail selector (`DetailTabs`) and the visit selector are now the shared bottom strip (`ui/components/SelectorStrip.kt`), pinned in the thumb zone above the system gesture inset with the content filling the area above; a wide window keeps the left rail for the detail selector and the pinned top row for visits. - SelectorStrip: the one bottom strip plus its pure model (`SelectorEntry`, `SelectorPlacement`, `detailSelectorPlacement`, `visitSelectorPlacement`, `selectorStripShown`, `detailSelectorEntries`, `visitSelectorKey/Label`, `visitMarker`, `visitSelectorEntries`). Each entry keeps at least the platform minimum touch target, shows its whole label, and a visit shows its recorded status/outcome as a small `RunStatusIcon` marker rather than an invented one. Selection is carried by tab semantics and container colour, not colour alone. A single entry (or none) draws no strip. - `DetailTabs` narrow branch replaced by `SelectorStrip` after the panel in a Column; the wide rail is unchanged. - `StageDetailPane`: `StageVisitStrip` is the narrow visit selector; the bodies put a `weight(1f)` scroll above it and keep the top row only on a wide window. The stage definition section still shows no strip. - `SessionExport`: `SessionExportSection` gains `visitTabs` so the narrow pane does not render the visit selector twice. - `PipelinesApp`: the strip publishes its measured height through the new `LocalBottomStripInset`/`BottomStripInset`, and the floating pill's overlay lifts by `pillBottomOffset(stripHeight) = SPACING_L + stripHeight` (pure, zero when no strip is up), so the pill never overlaps the strip. - Tests: new `SelectorStripTest` (placements, single-entry no strip, detail entries keep tab keys/titles/icons, visit labels and markers, stable visit keys) and a new `PipelinesNavTest` case pinning the pill lift. Pill/strip clearance is the brief's "pill moves clear of the strip" option, implemented once in `pillBottomOffset`. All geometry and motion come from the existing named tokens and the layout; no new dependency. Documentation checked: no packaged OpenCode skill reference (`internal/author/ skill/references/`) or packaged template (`examples/*.md`) documents the app's detail/visit selector presentation, so neither is stale and `internal/author/ install.go`'s managed inventory needs no change. The shared `android/README.md` is made stale by this change (the narrow tab-row wording at lines ~182-184, ~233-235 and ~487-488) and is recorded for the single `docs-fold` writer in the new `docs/notes/bottom-selector-strip.md` rather than edited here. --- .../net/awan/pipelines/ui/PipelinesApp.kt | 28 +- .../pipelines/ui/components/DetailTabs.kt | 28 +- .../pipelines/ui/components/SelectorStrip.kt | 246 ++++++++++++++++++ .../awan/pipelines/ui/graph/SessionExport.kt | 24 +- .../pipelines/ui/graph/StageDetailPane.kt | 227 +++++++++------- .../net/awan/pipelines/ui/PipelinesNavTest.kt | 11 + .../ui/components/SelectorStripTest.kt | 83 ++++++ docs/notes/bottom-selector-strip.md | 123 +++++++++ 8 files changed, 653 insertions(+), 117 deletions(-) create mode 100644 android/app/src/main/java/net/awan/pipelines/ui/components/SelectorStrip.kt create mode 100644 android/app/src/test/java/net/awan/pipelines/ui/components/SelectorStripTest.kt create mode 100644 docs/notes/bottom-selector-strip.md diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt index 9df80ba8..3c72bf91 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt @@ -60,7 +60,9 @@ import net.awan.pipelines.notify.alertPermissionPrompt import net.awan.pipelines.ui.chat.ChatScreen import net.awan.pipelines.ui.components.AttentionIndicator import net.awan.pipelines.ui.components.AttentionSheet +import net.awan.pipelines.ui.components.BottomStripInset import net.awan.pipelines.ui.components.ConnectionBanner +import net.awan.pipelines.ui.components.LocalBottomStripInset import net.awan.pipelines.ui.components.LocalPillBottomInset import net.awan.pipelines.ui.components.MotionStandard import net.awan.pipelines.ui.components.paneSafeArea @@ -292,9 +294,16 @@ fun PipelinesApp( // (an open conversation, see [destinationPillVisible]) that clearance is zero // so a hidden pill leaves no empty band. See [contentPillPadding]. val bannerVisible = connectionState !is ConnectionState.Connected + // The live height of any bottom selector strip the current pane is showing. The + // strip publishes it while it is shown and the pill below reads it, so the two + // never overlap: the pill is lifted clear of the strip (see [pillBottomOffset]). + val bottomStripInset = remember { BottomStripInset() } Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0)) { padding -> Box(Modifier.fillMaxSize().padding(padding)) { - CompositionLocalProvider(LocalPillBottomInset provides pillScrollInset(pillVisible)) { + CompositionLocalProvider( + LocalPillBottomInset provides pillScrollInset(pillVisible), + LocalBottomStripInset provides bottomStripInset, + ) { Column(Modifier.fillMaxSize().padding(bottom = contentPillPadding(pillVisible))) { ConnectionBanner( state = connectionState, @@ -391,11 +400,16 @@ fun PipelinesApp( // corner on a wide one. Its margin comes from the named [SPACING_L], so the // corner placement adds no new number. That rule positions the pill; the // attention chip above it keeps its own bottom-right place at every width. + // While a bottom selector strip is up, the whole overlay is lifted by that + // strip's measured height ([pillBottomOffset]), so the pill never overlaps it. Column( modifier = Modifier .fillMaxSize() .windowInsetsPadding(paneSafeArea()) - .padding(end = if (wide) SPACING_L else 0.dp, bottom = SPACING_L), + .padding( + end = if (wide) SPACING_L else 0.dp, + bottom = pillBottomOffset(bottomStripInset.height), + ), verticalArrangement = Arrangement.Bottom, horizontalAlignment = destinationPillAlignment(wide), ) { @@ -531,3 +545,13 @@ internal fun contentPillPadding(pillVisible: Boolean): Dp = 0.dp */ internal fun pillScrollInset(pillVisible: Boolean): Dp = if (pillVisible) DESTINATION_PILL_RESERVE + ATTENTION_CHIP_RESERVE else 0.dp + +/** + * How far above the window's bottom the floating pill rests: its own [SPACING_L] + * margin, lifted by exactly the height of any bottom selector strip the current pane + * is showing ([stripHeight], published by the strip and zero when none is up). The + * pill therefore never overlaps the strip — while the strip is up the two are stacked + * with the pill clear above it — and it keeps its resting margin when no strip is up. + * Pure, so the one clearance rule is unit-testable without a device. + */ +internal fun pillBottomOffset(stripHeight: Dp): Dp = SPACING_L + stripHeight diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt index 16c48ced..7dee2ded 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt @@ -23,11 +23,8 @@ import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material.icons.filled.Code import androidx.compose.material.icons.filled.Hub import androidx.compose.material.icons.filled.Info -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.PrimaryScrollableTabRow -import androidx.compose.material3.Tab import androidx.compose.material3.Text import androidx.compose.material3.VerticalDivider import androidx.compose.runtime.Composable @@ -85,9 +82,10 @@ fun clampTabIndex(index: Int, tabCount: Int): Int = if (tabCount <= 0) 0 else index.coerceIn(0, tabCount - 1) /** - * The section index + its panel. On narrow windows the index is a horizontally - * scrolling Material 3 [PrimaryScrollableTabRow]; on wide windows it is an - * always-visible selectable rail. Both stay fixed and visible while the selected + * The section index + its panel. On narrow windows the index is the shared + * [SelectorStrip] pinned to the bottom of the surface, in the thumb zone, with the + * panel filling the area above it; on wide windows it is an always-visible + * selectable rail on the left. Both stay fixed and visible while the selected * section's panel swaps in place behind a short [Crossfade]: selecting a section * is an ordinary tab change with no lateral motion and no swipe, because the * sections are not a left-to-right pager. Only navigation between levels @@ -99,7 +97,6 @@ fun clampTabIndex(index: Int, tabCount: Int): Int = * position) is keyed by its stable tab key, so returning to a section restores * where the operator left off instead of resetting it. */ -@OptIn(ExperimentalMaterial3Api::class) @Composable fun DetailTabs( tabs: List, @@ -164,16 +161,15 @@ fun DetailTabs( } } else { Column(modifier.fillMaxSize()) { - PrimaryScrollableTabRow(selectedTabIndex = selected, edgePadding = 0.dp) { - tabs.forEachIndexed { index, tab -> - Tab( - selected = index == selected, - onClick = { onSelect(index) }, - text = { Text(tab.title, maxLines = 1) }, - ) - } - } + // The content fills the area above the strip; the selector sits after it, + // pinned to the bottom where a thumb reaches, instead of scrolling away + // at the top of a tall screen. swap(Modifier.weight(1f).fillMaxWidth()) + SelectorStrip( + entries = detailSelectorEntries(tabs), + selectedIndex = selected, + onSelect = onSelect, + ) } } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/SelectorStrip.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/SelectorStrip.kt new file mode 100644 index 00000000..67abb068 --- /dev/null +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/SelectorStrip.kt @@ -0,0 +1,246 @@ +package net.awan.pipelines.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.selection.selectable +import androidx.compose.foundation.selection.selectableGroup +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.LocalMinimumInteractiveComponentSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.compositionLocalOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import net.awan.pipelines.data.protocol.RunStep +import net.awan.pipelines.ui.theme.HAIRLINE_DP +import net.awan.pipelines.ui.theme.ICON_RAIL_DP +import net.awan.pipelines.ui.theme.ICON_STATUS_DP +import net.awan.pipelines.ui.theme.SPACING_L +import net.awan.pipelines.ui.theme.SPACING_S +import net.awan.pipelines.ui.theme.SPACING_XS +import net.awan.pipelines.ui.theme.pipelinesText + +/** + * One entry of a bottom selector strip: its stable [key] (a selector's per-entry + * saved state — a section's list scroll position, say — is kept under it), the + * [label] it shows, an optional leading [icon] and an optional per-entry state + * [marker]. A [marker] is only ever set from state the model actually carries (a + * visit's recorded status or outcome); an entry whose model has no such state + * shows no marker rather than a stand-in for data that is not there. + */ +data class SelectorEntry( + val key: String, + val label: String, + val icon: ImageVector? = null, + val marker: RunState? = null, +) + +/** Where a surface's selector sits: the wide left rail, the wide pinned top row, or the narrow bottom strip. */ +enum class SelectorPlacement { Rail, TopRow, BottomStrip } + +/** + * Where the shared detail selector sits: the always-visible left rail on a wide + * window (unchanged), the bottom strip on a narrow one. Pure, so the one + * arrangement rule is unit-testable without a device. + */ +internal fun detailSelectorPlacement(wide: Boolean): SelectorPlacement = + if (wide) SelectorPlacement.Rail else SelectorPlacement.BottomStrip + +/** + * Where the visit selector sits: the pinned top row on a wide window (unchanged), + * the bottom strip on a narrow one — the same thumb-reachable treatment the detail + * selector gets, so both selectors read the same on a phone. + */ +internal fun visitSelectorPlacement(wide: Boolean): SelectorPlacement = + if (wide) SelectorPlacement.TopRow else SelectorPlacement.BottomStrip + +/** + * Whether a selector with [entryCount] entries needs a strip at all: one entry has + * nothing to select between, so a single-entry surface shows no pointless strip and + * its content fills the whole area. + */ +internal fun selectorStripShown(entryCount: Int): Boolean = entryCount > 1 + +/** + * The strip entries for a detail tab list: each tab's stable key and its own title, + * with the rail's glyph. No marker is invented — a detail tab's model carries no + * per-entry state. Keeping the tab [DetailTab.key] as the entry key is what keeps a + * section's saved state keyed the same whether the selector is the rail or the strip. + */ +internal fun detailSelectorEntries(tabs: List): List = + tabs.map { SelectorEntry(key = it.key, label = it.title, icon = it.icon) } + +/** The stable per-visit key, so a visit's saved state is keyed the same everywhere. */ +internal fun visitSelectorKey(index: Int): String = "visit-${index + 1}" + +/** The one wording a visit's entry carries, shared by the strip and the wide top row. */ +internal fun visitSelectorLabel(index: Int): String = "visit ${index + 1}" + +/** + * The marker for one visit: the state of the status (or, absent that, the outcome) + * the visit actually recorded. A visit that recorded neither shows no marker, so the + * strip never invents a state for it. + */ +internal fun visitMarker(step: RunStep): RunState? { + val word = step.status.ifBlank { step.outcome } + return if (word.isBlank()) null else runStateOf(word) +} + +/** + * The visit strip entries: `visit N` with the marker of that visit's own recorded + * state, in recorded order, so the selected visit and every other visit's state are + * both readable at a glance. + */ +internal fun visitSelectorEntries(runSteps: List): List = + runSteps.mapIndexed { index, step -> + SelectorEntry( + key = visitSelectorKey(index), + label = visitSelectorLabel(index), + marker = visitMarker(step), + ) + } + +/** + * How tall the bottom selector strip currently is in the composition it is shown in. + * The strip publishes its own measured height here while it is shown and resets it + * to zero when it goes away; the app shell reads it to lift the floating destination + * pill clear of the strip, so the two never overlap. It is a small mutable cell + * rather than a plain value because the strip measures itself and the shell reacts + * to that measurement, and it defaults to a fresh zero cell, so a strip composed + * outside the shell (a preview, a test) lifts nothing. + */ +class BottomStripInset { + var height: Dp by mutableStateOf(0.dp) +} + +/** The live bottom-strip height, published by the app shell and written by the strip. */ +internal val LocalBottomStripInset = compositionLocalOf { BottomStripInset() } + +/** + * The one bottom selector strip: a full-width bar pinned to the bottom of the + * surface, in the thumb zone the caller already placed it above the system gesture + * inset, with its entries in a single horizontally scrolling row and the content + * filling the area above it. Each entry keeps at least the platform's minimum touch + * target and shows its whole label (never squeezed); the selected entry is + * unmistakable through the tab semantics and the container colour, not colour alone. + * A single entry (or none) draws no strip at all. + */ +@Composable +internal fun SelectorStrip( + entries: List, + selectedIndex: Int, + onSelect: (Int) -> Unit, + modifier: Modifier = Modifier, +) { + if (!selectorStripShown(entries.size)) return + val selected = selectedIndex.coerceIn(0, entries.size - 1) + val inset = LocalBottomStripInset.current + val density = LocalDensity.current + Surface( + modifier = modifier + .fillMaxWidth() + .onSizeChanged { inset.height = with(density) { it.height.toDp() } }, + color = MaterialTheme.colorScheme.surfaceContainer, + ) { + Column { + HorizontalDivider( + thickness = HAIRLINE_DP, + color = MaterialTheme.colorScheme.outlineVariant, + ) + Row( + modifier = Modifier + .fillMaxWidth() + .horizontalScroll(rememberScrollState()) + .selectableGroup() + .padding(horizontal = SPACING_S, vertical = SPACING_S), + horizontalArrangement = Arrangement.spacedBy(SPACING_XS), + verticalAlignment = Alignment.CenterVertically, + ) { + entries.forEachIndexed { index, entry -> + StripTab( + entry = entry, + selected = index == selected, + onClick = { onSelect(index) }, + ) + } + } + } + } + // Leaving the strip (a section with a single entry, or the pane going away) + // withdraws the clearance, so the pill drops back to its resting place. + DisposableEffect(inset) { + onDispose { inset.height = 0.dp } + } +} + +/** + * One strip entry: its glyph (when it has one), its full label and its state marker + * (when the model carries one). It keeps at least the platform minimum touch target, + * and selection is conveyed by its tab semantics and container colour — the glyph + * and label are the same in both states, so nothing is conveyed by colour alone. + */ +@Composable +private fun StripTab(entry: SelectorEntry, selected: Boolean, onClick: () -> Unit) { + val text = pipelinesText() + val minTouch = LocalMinimumInteractiveComponentSize.current + val contentColor = if (selected) { + MaterialTheme.colorScheme.onSecondaryContainer + } else { + MaterialTheme.colorScheme.onSurfaceVariant + } + Row( + modifier = Modifier + .heightIn(min = minTouch) + .selectable(selected = selected, role = Role.Tab, onClick = onClick) + .background( + color = if (selected) MaterialTheme.colorScheme.secondaryContainer else Color.Transparent, + shape = MaterialTheme.shapes.small, + ) + .padding(horizontal = SPACING_L, vertical = SPACING_S), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(SPACING_S), + ) { + entry.icon?.let { icon -> + Icon( + imageVector = icon, + // The label names the entry, so the glyph is decorative here. + contentDescription = null, + tint = contentColor, + modifier = Modifier.size(ICON_RAIL_DP), + ) + } + Text( + text = entry.label, + style = text.cardTitle, + color = contentColor, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + entry.marker?.let { state -> + RunStatusIcon(state = state, modifier = Modifier.size(ICON_STATUS_DP)) + } + } +} diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/SessionExport.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/SessionExport.kt index dd2f89cd..90d8bbe1 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/SessionExport.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/SessionExport.kt @@ -128,8 +128,10 @@ internal fun decodeSessionFile(bytes: ByteArray, markdown: Boolean): SessionLoad * so a session of several hundred kilobytes scrolls without composing every block. * When both files were exported the section offers an "HTML view" toggle that * swaps in the html document in a WebView for fidelity, and switches back. The - * context line and the visit tabs stay pinned above the scroll, exactly as the - * other section panes keep their chrome. + * context line stays pinned above the scroll, exactly as the other section panes + * keep their chrome. On a wide window [visitTabs] renders the pinned visit row in + * that header; on a narrow one the caller owns the visit strip below instead, so the + * header must not double it. * * The file is fetched once per url through the app's shared artifact byte cache and * the fetch/parse run off the main thread, so switching views or reopening the pane @@ -146,13 +148,14 @@ internal fun SessionExportSection( onVisitIndexChange: (Int) -> Unit, configuredServerUrl: String, fetchArtifactBytes: suspend (String) -> ByteArray?, + visitTabs: Boolean = true, modifier: Modifier = Modifier, ) { val text = pipelinesText() val files = remember(step) { sessionExportFiles(step) } Column(modifier.fillMaxSize()) { if (files == null) { - SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange) { + SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange, visitTabs) { Text("No session was exported for this visit.", style = text.meta) } return@Column @@ -163,7 +166,7 @@ internal fun SessionExportSection( val toggle = sessionViewToggle(files) val artifact = sessionArtifact(files, view) val url = artifact?.let { resolvedArtifactUrl(it, configuredServerUrl) } - SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange) { + SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange, visitTabs) { Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, @@ -194,10 +197,12 @@ internal fun SessionExportSection( } /** - * The session pane's pinned header: the context line naming the stage and the - * visit tabs, followed by the caller's [content] (the view toggle, or the - * missing-export notice). It stays above the session's own scroll, exactly as the - * other section panes keep their chrome. + * The session pane's pinned header: the context line naming the stage and — on a + * wide window — the visit row, followed by the caller's [content] (the view toggle, + * or the missing-export notice). It stays above the session's own scroll, exactly as + * the other section panes keep their chrome. On a narrow window [visitTabs] is false + * and the visit selector is the caller's bottom strip instead, so the header does not + * show it twice. */ @Composable private fun SessionHeader( @@ -205,6 +210,7 @@ private fun SessionHeader( runSteps: List, visitIndex: Int, onVisitIndexChange: (Int) -> Unit, + visitTabs: Boolean, content: @Composable () -> Unit, ) { val text = pipelinesText() @@ -215,7 +221,7 @@ private fun SessionHeader( verticalArrangement = Arrangement.spacedBy(SPACING_S), ) { Text(GraphSemantics.nodeLabel(stageKey), style = text.meta) - StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) + if (visitTabs) StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) content() } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt index 8faaf0cc..418f8dc8 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt @@ -47,8 +47,11 @@ import net.awan.pipelines.ui.components.DetailTabBody import net.awan.pipelines.ui.components.KeyValueRow import net.awan.pipelines.ui.components.PaneIdentity import net.awan.pipelines.ui.components.SectionHeader +import net.awan.pipelines.ui.components.SelectorStrip import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.pillBottomPadding +import net.awan.pipelines.ui.components.visitSelectorEntries +import net.awan.pipelines.ui.components.visitSelectorLabel import net.awan.pipelines.ui.STAGE_RUN_LABEL_LINES import net.awan.pipelines.ui.displayMap import net.awan.pipelines.ui.fileChangeLine @@ -518,64 +521,74 @@ private fun StageDetailBody( } DetailTabBody(wide, modifier) { columnModifier -> - Column( - modifier = columnModifier - .verticalScroll(rememberScrollState()) - .padding(horizontal = SPACING_L, vertical = SPACING_S) - .pillBottomPadding(), - verticalArrangement = Arrangement.spacedBy(SPACING_XS), - ) { - // A run parked on this stage surfaces its decision here, at the top of - // the stage screen: reaching the stage is enough. Rendered - // unconditionally so the open sheet survives a refusal (which clears the - // decision) and can report the server's reason. - DecisionPrompt(decision = decision, onSend = onDecide) - // The stage's own name is the app bar's title, so the body does not - // repeat it: the pane leads with the stage's type and facts instead of - // a duplicated heading. - StageTypeChip(typeLabel) - StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange) + Column(columnModifier) { + Column( + modifier = Modifier + .weight(1f) + .fillMaxWidth() + .verticalScroll(rememberScrollState()) + .padding(horizontal = SPACING_L, vertical = SPACING_S) + .pillBottomPadding(), + verticalArrangement = Arrangement.spacedBy(SPACING_XS), + ) { + // A run parked on this stage surfaces its decision here, at the top of + // the stage screen: reaching the stage is enough. Rendered + // unconditionally so the open sheet survives a refusal (which clears the + // decision) and can report the server's reason. + DecisionPrompt(decision = decision, onSend = onDecide) + // The stage's own name is the app bar's title, so the body does not + // repeat it: the pane leads with the stage's type and facts instead of + // a duplicated heading. + StageTypeChip(typeLabel) + // A wide window keeps the visit row where it was, pinned with the + // content it belongs to; a narrow one moves it to the strip below, + // where a thumb reaches. + if (wide) StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange) - // The verdict leads the run pane, above the facts: the chosen option, - // the concise reason and the artifacts it names. Absent when the server - // reported none, so no empty heading is ever drawn. - if (runContext && selectedStep != null) { - StageVerdictBlock( - verdict = selectedStep.verdict, - outcome = selectedStep.outcome, - status = selectedStep.status, - artifacts = selectedStep.artifacts.orEmpty(), - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, - ) - } - headline.forEach { field -> StageFieldRow(field) } - if (headline.isEmpty() && selectedStep == null && stage == null && sections.isEmpty()) { - Text("No details recorded for this node.", style = text.meta) - } + // The verdict leads the run pane, above the facts: the chosen option, + // the concise reason and the artifacts it names. Absent when the server + // reported none, so no empty heading is ever drawn. + if (runContext && selectedStep != null) { + StageVerdictBlock( + verdict = selectedStep.verdict, + outcome = selectedStep.outcome, + status = selectedStep.status, + artifacts = selectedStep.artifacts.orEmpty(), + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + ) + } + headline.forEach { field -> StageFieldRow(field) } + if (headline.isEmpty() && selectedStep == null && stage == null && sections.isEmpty()) { + Text("No details recorded for this node.", style = text.meta) + } - // The compact list of sections: each row opens that section as its own - // pane instead of growing this screen inline (which stacked a section's - // several rows at the top of its header). The row is a navigation row, - // so it reads as "Open Artifacts" with a forward chevron rather than an - // in-place "Expand Artifacts"/collapsed disclosure. - sections.forEach { section -> - SectionHeader( - title = section.title, - expanded = false, - onToggle = { onOpenSection(section.key) }, - containerColor = paneContainerColor(), - navigation = true, - ) + // The compact list of sections: each row opens that section as its own + // pane instead of growing this screen inline (which stacked a section's + // several rows at the top of its header). The row is a navigation row, + // so it reads as "Open Artifacts" with a forward chevron rather than an + // in-place "Expand Artifacts"/collapsed disclosure. + sections.forEach { section -> + SectionHeader( + title = section.title, + expanded = false, + onToggle = { onOpenSection(section.key) }, + containerColor = paneContainerColor(), + navigation = true, + ) + } } + if (!wide) StageVisitStrip(runSteps, clampedVisit, onVisitIndexChange) } } } /** - * The shared visit tab row: rendered only when [visitCount] is more than one, so - * a single-visit stage never shows a pointless one-tab row. Both the stage screen - * and a run-section pane use it, so a visit always reads the same way. + * The wide visit selector: the pinned top row, rendered only when [visitCount] is + * more than one, so a single-visit stage never shows a pointless one-tab row. Both + * the stage screen and a run-section pane use it on a **wide** window; on a narrow + * one they use the thumb-reachable [StageVisitStrip] instead, and both label a visit + * the same way ([visitSelectorLabel]). */ @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -596,12 +609,34 @@ internal fun StageVisitTabs( Tab( selected = index == selectedIndex, onClick = { onSelect(index) }, - text = { Text("visit ${index + 1}", maxLines = 1) }, + text = { Text(visitSelectorLabel(index), maxLines = 1) }, ) } } } +/** + * The narrow visit selector: the shared bottom strip, with each visit's own label and + * the marker of the state that visit actually recorded (its status, or its outcome + * when no status was recorded). A stage visited once — or not at all — shows no strip. + * The labels and markers come from [visitSelectorEntries], so the strip and the wide + * row never spell a visit differently. + */ +@Composable +internal fun StageVisitStrip( + runSteps: List, + selectedIndex: Int, + onSelect: (Int) -> Unit, + modifier: Modifier = Modifier, +) { + SelectorStrip( + entries = visitSelectorEntries(runSteps), + selectedIndex = selectedIndex, + onSelect = onSelect, + modifier = modifier, + ) +} + /** * One stage section opened as its own pane: its own Scaffold/[TopAppBar] titled * with the section's own name, its own scroll and its own top spacing, so the @@ -715,12 +750,14 @@ fun StageSectionPane( /** * One section's content: its own single scroll, a context line naming the stage, - * its own top spacing, and — for a visit's result section — the visit tab row, - * so the operator can switch visits in place. The stage definition skips the tab - * row (it does not change per visit). Plain sections render their rows; the - * artifacts section renders the shared [ArtifactsSection] gallery; the session - * section renders [SessionExportSection], which owns its own lazy/large-content - * scroll instead of the eager one below. + * its own top spacing, and — for a visit's result section — the visit selector, so + * the operator can switch visits in place. The stage definition skips the selector + * (it does not change per visit). A wide window keeps the pinned top row inside the + * scroll; a narrow one pins the shared bottom strip below the scroll, so a visit is + * switchable from the thumb zone. Plain sections render their rows; the artifacts + * section renders the shared [ArtifactsSection] gallery; the session section renders + * [SessionExportSection], which owns its own lazy/large-content scroll instead of the + * eager one below. */ @Composable private fun StageSectionBody( @@ -738,46 +775,56 @@ private fun StageSectionBody( modifier: Modifier = Modifier, ) { val text = pipelinesText() + val visitSelector = spec != null && spec.key != STAGE_DEFINITION_KEY if (spec?.session == true && step != null) { - DetailTabBody(wide, modifier) { columnModifier -> - SessionExportSection( - stageKey = stageKey, - step = step, - runSteps = runSteps, - visitIndex = visitIndex, - onVisitIndexChange = onVisitIndexChange, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, - modifier = columnModifier, - ) + Column(modifier.fillMaxSize()) { + DetailTabBody(wide, Modifier.weight(1f)) { columnModifier -> + SessionExportSection( + stageKey = stageKey, + step = step, + runSteps = runSteps, + visitIndex = visitIndex, + onVisitIndexChange = onVisitIndexChange, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + visitTabs = wide, + modifier = columnModifier, + ) + } + if (!wide) StageVisitStrip(runSteps, visitIndex, onVisitIndexChange) } return } DetailTabBody(wide, modifier) { columnModifier -> - Column( - modifier = columnModifier - .verticalScroll(rememberScrollState()) - .padding(horizontal = SPACING_L, vertical = SPACING_L) - .pillBottomPadding(), - verticalArrangement = Arrangement.spacedBy(SPACING_XS), - ) { - KeyValueRow("Stage", GraphSemantics.nodeLabel(stageKey)) - if (spec != null && spec.key != STAGE_DEFINITION_KEY) { - StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) - } - when { - spec == null -> Text("This section is not recorded for this stage.", style = text.meta) - spec.artifacts -> if (step != null) { - ArtifactsSection( - step = step, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, - selection = selection, - onSelectionChange = onSelectionChange, - ) + Column(columnModifier) { + Column( + modifier = Modifier + .weight(1f) + .fillMaxWidth() + .verticalScroll(rememberScrollState()) + .padding(horizontal = SPACING_L, vertical = SPACING_L) + .pillBottomPadding(), + verticalArrangement = Arrangement.spacedBy(SPACING_XS), + ) { + KeyValueRow("Stage", GraphSemantics.nodeLabel(stageKey)) + if (wide && visitSelector) { + StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) + } + when { + spec == null -> Text("This section is not recorded for this stage.", style = text.meta) + spec.artifacts -> if (step != null) { + ArtifactsSection( + step = step, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + selection = selection, + onSelectionChange = onSelectionChange, + ) + } + else -> spec.fields.forEach { field -> StageFieldRow(field) } } - else -> spec.fields.forEach { field -> StageFieldRow(field) } } + if (!wide && visitSelector) StageVisitStrip(runSteps, visitIndex, onVisitIndexChange) } } } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt index beb119ac..610ab715 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt @@ -2,8 +2,10 @@ package net.awan.pipelines.ui import androidx.compose.ui.Alignment import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp import net.awan.pipelines.ui.theme.ATTENTION_CHIP_RESERVE import net.awan.pipelines.ui.theme.DESTINATION_PILL_RESERVE +import net.awan.pipelines.ui.theme.SPACING_L import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -132,6 +134,15 @@ class PipelinesNavTest { } } + @Test + fun thePillLiftsClearOfAnyBottomSelectorStrip() { + // With no strip up the pill keeps its own resting margin; with a strip up it + // is lifted by exactly that strip's measured height, so the two stack with + // the pill clear above the strip instead of overlapping it. + assertDp(SPACING_L.value, pillBottomOffset(0.dp)) + assertDp((SPACING_L + 72.dp).value, pillBottomOffset(72.dp)) + } + private fun assertDp(expected: Float, actual: Dp) = assertEquals(expected, actual.value, 0.01f) } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/components/SelectorStripTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/components/SelectorStripTest.kt new file mode 100644 index 00000000..0bcbe372 --- /dev/null +++ b/android/app/src/test/java/net/awan/pipelines/ui/components/SelectorStripTest.kt @@ -0,0 +1,83 @@ +package net.awan.pipelines.ui.components + +import net.awan.pipelines.data.protocol.RunStep +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Test + +class SelectorStripTest { + + @Test + fun theNarrowDetailSelectorIsTheBottomStripAndTheWideOneKeepsTheRail() { + // The narrow arrangement puts the selector after the content, pinned to the + // bottom; the wide arrangement keeps the always-visible left rail, unmoved. + assertEquals(SelectorPlacement.BottomStrip, detailSelectorPlacement(wide = false)) + assertEquals(SelectorPlacement.Rail, detailSelectorPlacement(wide = true)) + } + + @Test + fun theNarrowVisitSelectorIsTheBottomStripAndTheWideOneKeepsThePinnedRow() { + assertEquals(SelectorPlacement.BottomStrip, visitSelectorPlacement(wide = false)) + assertEquals(SelectorPlacement.TopRow, visitSelectorPlacement(wide = true)) + } + + @Test + fun aSingleEntryShowsNoPointlessStrip() { + assertTrue(!selectorStripShown(0)) + assertTrue(!selectorStripShown(1)) + assertTrue(selectorStripShown(2)) + assertTrue(selectorStripShown(6)) + } + + @Test + fun detailEntriesCarryTheTabKeysAndTitlesInOrderSoSavedStateIsKeyedTheSame() { + // Each entry keeps its tab's stable key, which is what a section's own saved + // state (its scroll position) is keyed by through the saveable state holder; + // the strip and the rail therefore preserve exactly the same per-entry state. + listOf(runDetailTabs, pipelineDetailTabs).forEach { tabs -> + val entries = detailSelectorEntries(tabs) + assertEquals(tabs.map { it.key }, entries.map { it.key }) + assertEquals(tabs.map { it.title }, entries.map { it.label }) + assertEquals(tabs.map { it.icon }, entries.map { it.icon }) + // No marker is invented: a detail tab's model carries no per-entry state. + assertTrue(entries.all { it.marker == null }) + } + } + + @Test + fun visitEntriesAreTheVisitLabelsWithEachVisitsOwnRecordedMarker() { + val steps = listOf( + RunStep(status = "succeeded", outcome = "success"), + RunStep(status = "failed"), + RunStep(status = "running"), + RunStep(outcome = "success"), + ) + val entries = visitSelectorEntries(steps) + assertEquals(listOf("visit 1", "visit 2", "visit 3", "visit 4"), entries.map { it.label }) + // The marker is the state the visit actually recorded, never invented. + assertEquals( + listOf(RunState.Succeeded, RunState.Failed, RunState.Running, RunState.Succeeded), + entries.map { it.marker }, + ) + // A visit's strip entry and the wide row spell the visit the same way. + assertEquals("visit 1", visitSelectorLabel(0)) + assertEquals("visit 3", visitSelectorLabel(2)) + } + + @Test + fun aVisitThatRecordedNoStateShowsNoMarker() { + assertEquals(null, visitMarker(RunStep())) + assertEquals(null, visitMarker(RunStep(status = " ", outcome = ""))) + // A status wins over the outcome when both are recorded. + assertEquals(RunState.Failed, visitMarker(RunStep(status = "failed", outcome = "success"))) + assertNull(visitSelectorEntries(listOf(RunStep(), RunStep())).first().marker) + } + + @Test + fun visitKeysAreStableAndDistinct() { + // Two stages' strips must never share a visit's saved state, so each visit + // has its own stable key derived from its index. + assertEquals(listOf("visit-1", "visit-2", "visit-3"), (0..2).map { visitSelectorKey(it) }) + } +} diff --git a/docs/notes/bottom-selector-strip.md b/docs/notes/bottom-selector-strip.md new file mode 100644 index 00000000..df89a127 --- /dev/null +++ b/docs/notes/bottom-selector-strip.md @@ -0,0 +1,123 @@ +# The detail and visit selectors: a bottom strip narrow, the rail wide + +## What this item changed + +`android/` only, the two selectors that used to be a horizontally scrolling Material 3 +tab row at the top of a surface. + +- `ui/components/SelectorStrip.kt` (new) — the one bottom selector strip, plus its pure + model. `SelectorEntry(key, label, icon, marker)`, `SelectorPlacement` (`Rail` / `TopRow` + / `BottomStrip`), `detailSelectorPlacement(wide)`, `visitSelectorPlacement(wide)`, + `selectorStripShown(entryCount)`, `detailSelectorEntries(tabs)`, + `visitSelectorKey/Label(index)`, `visitMarker(step)`, `visitSelectorEntries(runSteps)`; + the `BottomStripInset` cell and `LocalBottomStripInset` the strip publishes its measured + height through; and the `SelectorStrip` composable (a full-width `Surface`, a hairline + top divider, one horizontally scrolling row of entries, each entry at least the platform + minimum touch target, the selected one carried by `Role.Tab` + selected state and the + container colour, a visit's recorded state shown as a small `RunStatusIcon` marker, and + a single entry drawing no strip at all). +- `ui/components/DetailTabs.kt` — the narrow branch's `PrimaryScrollableTabRow` is replaced + by `SelectorStrip(detailSelectorEntries(tabs), …)` **after** the panel in a `Column`, so + the content fills the area above the strip and the selector sits in the thumb zone. The + wide branch is unchanged (the left `RailTab` rail). The `@OptIn(ExperimentalMaterial3Api)` + and the `PrimaryScrollableTabRow`/`Tab` imports are gone. +- `ui/graph/StageDetailPane.kt` — `StageVisitTabs` stays the pinned **wide** visit row (now + labelling each visit through `visitSelectorLabel`); new `StageVisitStrip` is the narrow + form, the shared `SelectorStrip` fed by `visitSelectorEntries(runSteps)` (labels `visit N` + plus each visit's recorded status/outcome marker). `StageDetailBody` and `StageSectionBody` + put the strip below a `weight(1f)` scroll on a narrow window and keep the top row on a wide + one; a section that does not change per visit (`Stage definition`) still shows no strip. + The session branch composes `DetailTabBody` with `weight(1f)` above the strip. +- `ui/graph/SessionExport.kt` — `SessionExportSection` gains `visitTabs: Boolean` (passed as + `wide`), and `SessionHeader` renders the pinned visit row only when it is true, so the + narrow pane does not show the visit selector twice. +- `ui/PipelinesApp.kt` — the bottom strip's measured height is published to the content + through `LocalBottomStripInset` (a `BottomStripInset` cell created in the shell), and the + floating pill's overlay `Column` lifts by it: `pillBottomOffset(stripHeight) = SPACING_L + + stripHeight` (pure, new). So the pill moves clear of the strip while it is shown — the + chosen of the brief's two options — implemented once, and zero when no strip is up. +- Tests — `ui/components/SelectorStripTest.kt` (new: the placements, one-entry shows no + strip, the detail entries keep every tab key/title/icon so per-entry saved state is keyed + the same, the visit labels with their recorded markers, no marker for a visit with no + recorded state, the stable per-visit key) and `PipelinesNavTest` (the pill lifts by + exactly the strip height and keeps its margin with none). The existing `DetailTabsTest` + clamping/state tests and `StageDetailSheetTest` visit tests are unchanged and still pass. + +## Shared documents this change makes stale + +`android/README.md` documents the app's selector presentation and is written here rather +than edited in place; the `docs-fold` writer should update it. + +- `android/README.md:182-184` — the bullet ending "Narrow windows show a horizontally + scrolling `PrimaryScrollableTabRow`; wide windows show an always-visible selectable rail + (icon + label, no collapse control)." should read "Narrow windows show the shared + `SelectorStrip` pinned to the bottom of the surface, in the thumb zone, with the panel + filling the area above it; wide windows show an always-visible selectable rail on the + left (icon + label, no collapse control)." The rest of the bullet (the in-place + `Crossfade`, no lateral motion, the per-section `rememberSaveableStateHolder` keyed by + the tab key, `clampTabIndex`) is still true. +- `android/README.md:233-235` — "The section index presentation does follow the window + width: a narrow window shows the tab row across the top, a wide window the always-visible + side rail…" should read "…a narrow window shows the bottom selector strip, a wide window + the always-visible side rail…". +- `android/README.md:487-488` — the Timeline + visit tabs bullet's "shows a `visit 1..N` + tab row only when there is more than one visit" should read "shows a `visit 1..N` row + (the pinned top row on a wide window, the bottom strip on a narrow one, each visit's + recorded state as a small marker) only when there is more than one visit". +- Append the dated section below at the end of `android/README.md`, after the last record. + +```markdown +## The detail and visit selectors: a bottom strip narrow, the rail wide (18 Oct 2026) + +Both selectors that were a horizontally scrolling Material 3 tab row at the top of a +surface are now one deliberate treatment: the shared detail selector (`DetailTabs`, the +pipeline and the run detail) and the visit selector (`StageVisitTabs`). On a **narrow** +window the selector is the shared `SelectorStrip` pinned to the bottom of the surface, in +the thumb zone above the system gesture inset, with the content filling the area above it; +on a **wide** one the detail selector keeps its existing left rail and the visit selector +its pinned top row. `android/` only; no new dependency (still only the declared +`material-icons-extended`), no Pipelines server/Go/installer/Docker file touched and no run +started from the app; the build and unit tests only, no device command run. + +- **One shared strip.** `ui/components/SelectorStrip.kt` holds the strip and its pure + model: `SelectorEntry(key, label, icon, marker)`, `SelectorPlacement` (`Rail` / `TopRow` / + `BottomStrip`), `detailSelectorPlacement(wide)` / `visitSelectorPlacement(wide)`, + `selectorStripShown(entryCount)`, `detailSelectorEntries(tabs)`, `visitSelectorKey/Label`, + `visitMarker(step)` and `visitSelectorEntries(runSteps)`. A single entry (or none) draws + no strip, so a single-visit stage and a one-section surface stay strip-free. +- **Legible, unmistakable, token-driven.** Each entry keeps at least the platform minimum + touch target and shows its whole label (an ellipsis only if the row is scrolled), carries + the rail's glyph where the model has one, and shows a visit's recorded status/outcome as a + small marker (`RunStatusIcon`) — never a stand-in for data the model does not carry. The + selected entry is conveyed by `Role.Tab` + selected state and the container colour, not + colour alone. Every dimension is an existing `Dimens` token or the layout; no new + hardcoded value. +- **The pill moves clear of the strip.** The strip publishes its measured height through the + new `LocalBottomStripInset` (`BottomStripInset`), and the floating pill's overlay lifts by + `pillBottomOffset(stripHeight) = SPACING_L + stripHeight` — the one of the brief's two + options, implemented once and zero when no strip is up (a unit test pins both). The pane + stack's Back gesture and the in-place `Crossfade` swap are untouched, and each section's + own saved state is still keyed by its tab key. +- **Evidence.** ` --offline --no-daemon :app:assembleDebug :app:testDebugUnitTest` + → `BUILD SUCCESSFUL`; the 69 result XMLs aggregate to **654 tests, 0 failures, 0 errors, + 0 skipped**. New `SelectorStripTest` (7 tests) and one new `PipelinesNavTest` case. + `app-debug.apk` 18,700,429 bytes, sha256 + `5b5bb9e0d67586c0a964853097be89842fc99053f428d4d24905fda1aaa71af3`, published as + `pipelines-debug-wip-d9619ea.apk` (`HTTP/1.1 200 OK`, the published bytes + Content-Length-matching the local file). Built in a worktree at `d9619ea`, which is + `main`'s tip, so no feature of `main` is missing from it. + +Not verified in this pass: how the strip and the lifted pill actually render, and the +screenshots the brief names (the pipeline and run detail on a narrow window, a stage detail +with more than one visit, the single-entry case, and the wide rail) — that needs the device, +which this build-and-unit-test pass did not use; visual review owns the operator's Pixel 9 +Pro XL. +``` + +## Not stale + +- No packaged OpenCode skill reference (`internal/author/skill/references/`) documents the + app's detail/visit selectors; they describe the server, the CLI and the pipeline authoring + model. No packaged template (`examples/*.md`) and no `internal/author/` managed file names + them, so `internal/author/install.go`'s inventory needs no change. +- `android/AGENTS.md` lists `ui/components/` and `ui/graph/` generically and needs no change.