From 9ca775291b89913c4e8af5b00736c27eeb2ef9f7 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 14 Oct 2026 12:36:58 +0100 Subject: [PATCH] Give the Android client a dark-first Material 3 look and TUI-style graph terminals Three UI changes requested after reviewing the first on-device screenshots: - Dark-first theme: the app now owns its colour scheme instead of following the system wallpaper. Theme.kt defaults to a deliberate darkColorScheme built from a mint/teal seed with an amber tertiary (new Color.kt) so it matches the dark Pipelines TUI; dynamic colour is gone and a complete light scheme is retained for when it is explicitly requested. themes.xml/colors.xml give the app a dark window background and dark system bars with light icons, so launching never flashes light. - Workflow graph matches the TUI: the #success/#failure terminals now share a lower row under the stage row, with arrows entering their top borders and the error -> #failure route leaving the bottom of its source stage, mirroring internal/tui/graph_layout.go ('Terminals share a lower row...') and graph.go's '[FAILURE] [SUCCESS]' bottom row. Fit-to-content, pan clamping, the Fit action, run highlighting and the TalkBack description are preserved. - More style: consistent Material 3 top app bars for Pipelines, Runs and Settings, the new colour scheme applied across the screens and state components, and monospace retained for hashes, source and run input/output. Verified on the host and on the device: :app:compileDebugKotlin, :app:assembleDebug and :app:testDebugUnitTest succeed offline with 34 tests and 0 failures (WorkflowGraphTest grew to 15 tests covering the terminal row, bottom exits and fit/clamp), and the app was run on the Pixel_Fold_API_36 emulator in dark mode against the live server: the whole 4-stage graph renders with its terminal row, and the list, detail and settings screens use the new theme. --- android/README.md | 36 ++-- .../awan/pipelines/ui/components/States.kt | 14 +- .../awan/pipelines/ui/graph/WorkflowGraph.kt | 165 +++++++++++------- .../ui/screens/PipelineDetailScreen.kt | 2 +- .../pipelines/ui/screens/RunDetailScreen.kt | 2 +- .../pipelines/ui/screens/SettingsScreen.kt | 68 ++++++-- .../java/net/awan/pipelines/ui/theme/Color.kt | 81 +++++++++ .../java/net/awan/pipelines/ui/theme/Theme.kt | 98 +++++++++-- .../app/src/main/res/values-night/themes.xml | 8 +- android/app/src/main/res/values/colors.xml | 7 + android/app/src/main/res/values/themes.xml | 12 +- .../pipelines/ui/graph/WorkflowGraphTest.kt | 88 +++++++++- 12 files changed, 466 insertions(+), 115 deletions(-) create mode 100644 android/app/src/main/java/net/awan/pipelines/ui/theme/Color.kt create mode 100644 android/app/src/main/res/values/colors.xml diff --git a/android/README.md b/android/README.md index 8ac79654..5f06568d 100644 --- a/android/README.md +++ b/android/README.md @@ -81,10 +81,18 @@ stops it. - Pipeline list (search/refresh, empty/error/loading states), pipeline details (version list, content hash, source) and the workflow graph. -- Workflow graph composable: content-sized nodes, labelled outcome edges - (`error*` marks the implicit fallback), `#success`/`#failure` terminals, loops - and branches, pan/zoom, and run highlighting (executed routes highlighted, - others dimmed) plus a screen-reader description. +- Workflow graph composable: content-sized stage nodes laid out in one row in + declaration order, with `#failure`/`#success` terminals sharing a lower row and + arrows entering their top borders (an `error -> #failure` route leaves its + source's bottom); labelled outcome edges (`error*` marks the implicit + fallback), loops and branches, pan/zoom, and run highlighting (executed routes + highlighted, others dimmed) plus a screen-reader description. +- Dark-first Material 3 theme with an app-owned colour scheme (no dynamic/ + wallpaper colour): the dark scheme is the default and the window background and + system bars are dark so launching shows no light flash; a complete light scheme + is retained for when it is explicitly requested. +- Consistent Material 3 top app bars on Pipelines, Runs and Settings (and the + existing back/refresh/start/cancel/retry bars on the detail screens). - Run history with server `usage` aggregates, and run details with steps (status/outcome/diagnostic/session/transcript/file changes/notifications/ control evidence). Session evidence is scoped to the selected run and each @@ -121,13 +129,15 @@ Verified on macOS with the host toolchain (JDK 17 from Android Studio, `ANDROID_HOME=/Users/alan/Library/Android/sdk`, Gradle 8.11.1 `--offline`): - `:app:compileDebugKotlin`, `:app:assembleDebug` and `:app:testDebugUnitTest` - all succeed; **20 unit tests, 0 failures** (protocol model, graph semantics, - server URL, workflow-graph layout). Re-run with `--rerun-tasks` to confirm. + all succeed; **34 unit tests, 0 failures** (protocol model, graph semantics, + server URL, workflow-graph layout including the terminal row, bottom exits and + back edges). Re-run with `--rerun-tasks` to confirm. - The debug APK was installed and driven on the `Pixel_Fold_API_36` emulator - (Android 16) against a live server at `ws://10.0.2.2:8080/connect` with - workspace `/Users/alan`. Settings, pipeline list (all 9 pipelines), pipeline - detail, the workflow graph, run history, run detail and the disconnected/ - reconnect states were captured to `captures/` (git-ignored) and reviewed. + (Android 16, `adb shell cmd uimode night yes`) against a live server at + `ws://10.0.2.2:8080/connect` with workspace `/Users/alan/repos/pipelines`. + Settings, pipeline list (all 9 pipelines), pipeline detail, the workflow graph, + run history and run detail were captured to `captures/` and + `captures/style_pass/` (both git-ignored) and reviewed. - `adb logcat` for the app package contained no `FATAL EXCEPTION`, Compose or other runtime exception during the sweep. @@ -138,4 +148,8 @@ cannot leave the view, added a "Fit graph to view" action, connected on launch when a server URL is already saved, and made the completed/recorded visit wording and the outcome-label contrast consistent. The fitted graph still sits slightly above the box's vertical centre, because the layout box includes padding that is -not drawn. +not drawn. A later style pass made the theme dark-first (app-owned scheme; the +launch window/bar colours match it) and moved the `#failure`/`#success` terminals +to a lower row beneath the stage row; before/after captures for the theme, graph +and app bar/style are under `captures/style_pass/` (`*_before.png` are the +pre-change baseline referenced by the task, `*_after.png` are the new build). diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/States.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/States.kt index c20f233c..b7b4cd86 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/States.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/States.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -66,10 +67,19 @@ fun EmptyState(message: String, modifier: Modifier = Modifier) { /** Renders a labelled key/value row used across detail screens. */ @Composable -fun KeyValueRow(label: String, value: String, modifier: Modifier = Modifier) { +fun KeyValueRow( + label: String, + value: String, + modifier: Modifier = Modifier, + monospace: Boolean = false, +) { if (value.isBlank()) return Column(modifier = modifier.fillMaxWidth().padding(vertical = 4.dp)) { Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary) - Text(value, style = MaterialTheme.typography.bodyMedium) + Text( + value, + style = MaterialTheme.typography.bodyMedium, + fontFamily = if (monospace) FontFamily.Monospace else null, + ) } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/WorkflowGraph.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/WorkflowGraph.kt index 4f9ca5fc..33fc26cf 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/WorkflowGraph.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/WorkflowGraph.kt @@ -51,7 +51,7 @@ import net.awan.pipelines.data.protocol.Protocol import net.awan.pipelines.data.protocol.RunGraphState import net.awan.pipelines.data.protocol.edges -private data class NodeLayout( +internal data class NodeLayout( val key: String, val label: String, val x: Float, @@ -61,11 +61,16 @@ private data class NodeLayout( val terminal: Boolean, ) -private data class EdgeLayout( +internal data class EdgeLayout( val edge: GraphEdge, val from: Offset, val to: Offset, val backEdge: Boolean, + // Terminals sit on a lower row and receive arrows entering their top border, + // while an error->#failure route drops out of its source's bottom, mirroring + // tui.graphEdge.topEntry/bottomExit. + val topEntry: Boolean, + val bottomExit: Boolean, val sourceRank: Int, val targetRank: Int, // Index of this edge among the outgoing edges of its source plus how many @@ -74,7 +79,7 @@ private data class EdgeLayout( val labelCount: Int, ) -private data class GraphLayout( +internal data class GraphLayout( val nodes: List, val edges: List, val width: Float, @@ -126,6 +131,7 @@ fun WorkflowGraph( nodeBorder = scheme.outline, nodeText = scheme.onSurface, terminalFill = scheme.secondaryContainer, + terminalErrorFill = scheme.errorContainer, labelBackground = scheme.surface, labelText = scheme.onSurfaceVariant, ) @@ -225,6 +231,7 @@ private class GraphColors( val nodeBorder: Color, val nodeText: Color, val terminalFill: Color, + val terminalErrorFill: Color, val labelBackground: Color, val labelText: Color, ) @@ -267,65 +274,62 @@ internal fun clampOffset(offset: Offset, content: Size, viewport: Size, minVisib return Offset(x, y) } -private fun layoutGraph(graph: Graph, density: androidx.compose.ui.unit.Density): GraphLayout { +internal fun layoutGraph(graph: Graph, density: androidx.compose.ui.unit.Density): GraphLayout { if (graph.stages.isEmpty()) return GraphLayout(emptyList(), emptyList(), 0f, 0f) val nodeWidth = with(density) { 132.dp.toPx() } val nodeHeight = with(density) { 56.dp.toPx() } val hGap = with(density) { 88.dp.toPx() } - val vGap = with(density) { 28.dp.toPx() } val pad = with(density) { 32.dp.toPx() } + val terminalRowGap = with(density) { 72.dp.toPx() } val ranks = rankStages(graph) - val maxRank = ranks.values.maxOrNull() ?: 0 - val terminalRank = maxRank + 1 - val columns = HashMap>() - for (stage in graph.stages) { - val rank = ranks[stage.key] ?: 0 - columns.getOrPut(rank) { mutableListOf() } += stage.key - } - val terminalKeys = mutableListOf() - if (graph.stages.any { stage -> stage.edges.values.any { Protocol.isTerminal(it) || it == "#" } }) { - terminalKeys += Protocol.SUCCESS_END - terminalKeys += Protocol.FAILURE_END + val hasTerminal = graph.stages.any { stage -> + stage.edges.values.any { Protocol.isTerminal(it) || it == "#" } } - val columnHeights = HashMap() - for ((rank, keys) in columns) { - columnHeights[rank] = keys.size * nodeHeight + (keys.size - 1).coerceAtLeast(0) * vGap - } - columnHeights[terminalRank] = terminalKeys.size * nodeHeight + (terminalKeys.size - 1).coerceAtLeast(0) * vGap - val tallest = columnHeights.values.maxOrNull() ?: nodeHeight - + // Stages occupy a single top row in declaration order, exactly like + // tui.layoutSingleRowGraph: x grows with the declared stage index and every + // stage shares the same y. val positions = HashMap() - val sortedRanks = columns.keys.sorted() - for ((columnIndex, rank) in sortedRanks.withIndex()) { - val keys = columns.getValue(rank) - val columnHeight = columnHeights.getValue(rank) - var y = (tallest - columnHeight) / 2f - val x = pad + columnIndex * (nodeWidth + hGap) - for (key in keys) { - positions[key] = NodeLayout( - key = key, - label = GraphSemantics.nodeLabel(key), - x = x, - y = y, - width = nodeWidth, - height = nodeHeight, - terminal = false, - ) - y += nodeHeight + vGap - } + graph.stages.forEachIndexed { index, stage -> + positions[stage.key] = NodeLayout( + key = stage.key, + label = GraphSemantics.nodeLabel(stage.key), + x = pad + index * (nodeWidth + hGap), + y = pad, + width = nodeWidth, + height = nodeHeight, + terminal = false, + ) } - terminalKeys.forEachIndexed { index, key -> - val columnHeight = columnHeights.getValue(terminalRank) - val x = pad + sortedRanks.size * (nodeWidth + hGap) - val y = (tallest - columnHeight) / 2f + index * (nodeHeight + vGap) - positions[key] = NodeLayout( - key = key, - label = GraphSemantics.nodeLabel(key), - x = x, - y = y, + + val stageRowInner = graph.stages.size * nodeWidth + + (graph.stages.size - 1).coerceAtLeast(0) * hGap + val terminalPairInner = 2 * nodeWidth + hGap + val contentInner = if (hasTerminal) maxOf(stageRowInner, terminalPairInner) else stageRowInner + val width = pad * 2 + contentInner + + if (hasTerminal) { + // Both terminals share one lower row, FAILURE left of SUCCESS, the pair + // centred on the content width, so incoming arrows enter their top border. + val terminalY = pad + nodeHeight + terminalRowGap + val failureX = pad + (contentInner - terminalPairInner) / 2f + val successX = failureX + nodeWidth + hGap + positions[Protocol.FAILURE_END] = NodeLayout( + key = Protocol.FAILURE_END, + label = GraphSemantics.nodeLabel(Protocol.FAILURE_END), + x = failureX, + y = terminalY, + width = nodeWidth, + height = nodeHeight, + terminal = true, + ) + positions[Protocol.SUCCESS_END] = NodeLayout( + key = Protocol.SUCCESS_END, + label = GraphSemantics.nodeLabel(Protocol.SUCCESS_END), + x = successX, + y = terminalY, width = nodeWidth, height = nodeHeight, terminal = true, @@ -339,14 +343,26 @@ private fun layoutGraph(graph: Graph, density: androidx.compose.ui.unit.Density) val source = positions[edge.source] ?: return@mapNotNull null val target = positions[edge.target] ?: return@mapNotNull null val sourceRank = ranks[edge.source] ?: 0 - val targetRank = if (Protocol.isTerminal(edge.target)) terminalRank else (ranks[edge.target] ?: 0) + val targetIsTerminal = Protocol.isTerminal(edge.target) + val targetRank = if (targetIsTerminal) graph.stages.size else (ranks[edge.target] ?: 0) + val bottomExit = edge.outcome == "error" && edge.target == Protocol.FAILURE_END val labelSlot = slotsBySource.getOrDefault(edge.source, 0) slotsBySource[edge.source] = labelSlot + 1 EdgeLayout( edge = edge, - from = Offset(source.x + source.width, source.y + source.height / 2f), - to = Offset(target.x, target.y + target.height / 2f), - backEdge = targetRank <= sourceRank, + from = if (bottomExit) { + Offset(source.x + source.width / 2f, source.y + source.height) + } else { + Offset(source.x + source.width, source.y + source.height / 2f) + }, + to = if (targetIsTerminal) { + Offset(target.x + target.width / 2f, target.y) + } else { + Offset(target.x, target.y + target.height / 2f) + }, + backEdge = !targetIsTerminal && targetRank <= sourceRank, + topEntry = targetIsTerminal, + bottomExit = bottomExit, sourceRank = sourceRank, targetRank = targetRank, labelSlot = labelSlot, @@ -354,8 +370,7 @@ private fun layoutGraph(graph: Graph, density: androidx.compose.ui.unit.Density) ) } - val width = pad * 2 + (sortedRanks.size + 1) * nodeWidth + sortedRanks.size * hGap - val height = pad * 2 + tallest + val height = pad * 2 + nodeHeight + (if (hasTerminal) terminalRowGap + nodeHeight else 0f) return GraphLayout(positions.values.toList(), edgeLayouts, width, height) } @@ -383,12 +398,29 @@ private fun DrawScope.drawEdgePaths( val alpha = if (executed) 1f else 0.25f val path = Path() path.moveTo(edge.from.x, edge.from.y) - if (edge.backEdge) { - val dip = maxOf(edge.from.y, edge.to.y) + 64f - path.cubicTo(edge.from.x + 24f, dip, edge.to.x - 24f, dip, edge.to.x, edge.to.y) - } else { - val midX = (edge.from.x + edge.to.x) / 2f - path.cubicTo(midX, edge.from.y, midX, edge.to.y, edge.to.x, edge.to.y) + when { + // An error->#failure route drops out of the source bottom, runs down + // and across, then rises into the terminal top border. + edge.bottomExit -> { + val approachY = edge.to.y - BOTTOM_EXIT_APPROACH + path.lineTo(edge.from.x, approachY) + path.lineTo(edge.to.x, approachY) + path.lineTo(edge.to.x, edge.to.y) + } + // Terminal edges leave the source's right edge and curve down/right + // into the terminal's top border. + edge.topEntry -> { + val midX = (edge.from.x + edge.to.x) / 2f + path.cubicTo(midX, edge.from.y, midX, edge.to.y, edge.to.x, edge.to.y) + } + edge.backEdge -> { + val dip = maxOf(edge.from.y, edge.to.y) + BACK_EDGE_DIP + path.cubicTo(edge.from.x + 24f, dip, edge.to.x - 24f, dip, edge.to.x, edge.to.y) + } + else -> { + val midX = (edge.from.x + edge.to.x) / 2f + path.cubicTo(midX, edge.from.y, midX, edge.to.y, edge.to.x, edge.to.y) + } } drawPath(path, color = color.copy(alpha = alpha), style = Stroke(width = 3f)) drawArrowHead(edge.from, edge.to, color.copy(alpha = alpha)) @@ -469,12 +501,15 @@ private fun DrawScope.drawNodes( val executed = runState == null || node.key in runState.visitedStages val selected = node.key == selectedStage val alpha = if (executed) 1f else 0.3f + val failureTerminal = node.key == Protocol.FAILURE_END val fill = when { + node.terminal && failureTerminal -> colors.terminalErrorFill node.terminal -> colors.terminalFill selected -> colors.nodeFillActive else -> colors.nodeFill }.copy(alpha = alpha) val border = when { + node.terminal && failureTerminal -> colors.error node.terminal -> colors.success else -> colors.nodeBorder }.copy(alpha = alpha) @@ -552,6 +587,12 @@ private fun graphDescription(graph: Graph, runState: RunGraphState?): String { private const val MIN_SCALE = 0.3f private const val MAX_SCALE = 3f +/** How far below the stage row a loop route dips before curving back. */ +private const val BACK_EDGE_DIP = 64f + +/** How far above a terminal's top border the bottom-exit route levels off. */ +private const val BOTTOM_EXIT_APPROACH = 32f + /** Breathing room left around a fitted graph, and the least content kept visible. */ private val FIT_PADDING = 16.dp private val MIN_VISIBLE = 48.dp diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/PipelineDetailScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/PipelineDetailScreen.kt index d390ee46..e963a636 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/PipelineDetailScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/PipelineDetailScreen.kt @@ -120,7 +120,7 @@ private fun PipelineDetailContent(detail: PipelineDetail, modifier: Modifier = M "id ${detail.id} · v${detail.version} · ${detail.graph.stages.size} stages", style = MaterialTheme.typography.bodyMedium, ) - KeyValueRow("Content hash", detail.contentHash) + KeyValueRow("Content hash", detail.contentHash, monospace = true) KeyValueRow("Latest version", if (detail.latestVersion > 0) "v${detail.latestVersion}" else "") KeyValueRow("Version created", detail.versionCreatedAt) KeyValueRow("Pipeline created", detail.createdAt) diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt index 01100c8d..b7a6e7d9 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt @@ -223,7 +223,7 @@ private fun RunDetailContent( ) KeyValueRow("Pipeline", "id ${run.pipelineId} · v${run.version}") KeyValueRow("Workspace", run.workspace) - KeyValueRow("Content hash", run.contentHash) + KeyValueRow("Content hash", run.contentHash, monospace = true) KeyValueRow("Started", run.createdAt) KeyValueRow("Finished", run.finishedAt) KeyValueRow("Duration", formatDuration(run.createdAt, run.finishedAt) ?: "") diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/SettingsScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/SettingsScreen.kt index 62b88560..167c6da1 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/SettingsScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/SettingsScreen.kt @@ -13,10 +13,13 @@ import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Scaffold import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -26,6 +29,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import net.awan.pipelines.data.transport.ConnectionState import net.awan.pipelines.ui.AppViewModel +@OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { val serverUrl by vm.serverUrlDraft.collectAsStateWithLifecycle() @@ -37,18 +41,62 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { val configuredWorkspace by vm.configuredWorkspace.collectAsStateWithLifecycle() val workspaceError by vm.workspaceError.collectAsStateWithLifecycle() + Scaffold( + modifier = modifier, + topBar = { TopAppBar(title = { Text("Settings") }) }, + ) { padding -> + SettingsContent( + padding = Modifier.padding(padding), + serverUrl = serverUrl, + onServerUrlChange = vm::updateServerUrlDraft, + urlError = urlError, + state = state, + buildVersion = build?.version, + buildCommit = build?.commit, + serverTime = serverTime, + workspace = workspace, + onWorkspaceChange = vm::updateWorkspaceDraft, + workspaceError = workspaceError, + configuredWorkspace = configuredWorkspace, + onConnect = vm::connect, + onDisconnect = vm::disconnect, + onReconnect = vm::reconnect, + onSaveWorkspace = vm::saveWorkspace, + ) + } +} + +@Composable +private fun SettingsContent( + padding: Modifier, + serverUrl: String, + onServerUrlChange: (String) -> Unit, + urlError: String?, + state: ConnectionState, + buildVersion: String?, + buildCommit: String?, + serverTime: String?, + workspace: String, + onWorkspaceChange: (String) -> Unit, + workspaceError: String?, + configuredWorkspace: String, + onConnect: () -> Unit, + onDisconnect: () -> Unit, + onReconnect: () -> Unit, + onSaveWorkspace: () -> Unit, +) { Column( - modifier = modifier + modifier = padding .fillMaxSize() .verticalScroll(rememberScrollState()) .padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp), ) { - Text("Connection", style = MaterialTheme.typography.headlineSmall) + Text("Connection", style = MaterialTheme.typography.titleMedium) OutlinedTextField( value = serverUrl, - onValueChange = vm::updateServerUrlDraft, + onValueChange = onServerUrlChange, label = { Text("Server URL") }, placeholder = { Text("ws://192.168.1.20:8081/connect") }, singleLine = true, @@ -61,15 +109,15 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { ) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Button(onClick = vm::connect) { Text("Connect") } + Button(onClick = onConnect) { Text("Connect") } if (state is ConnectionState.Connected || state is ConnectionState.Connecting) { - OutlinedButton(onClick = vm::disconnect) { Text("Disconnect") } + OutlinedButton(onClick = onDisconnect) { Text("Disconnect") } } else { - OutlinedButton(onClick = vm::reconnect) { Text("Reconnect") } + OutlinedButton(onClick = onReconnect) { Text("Reconnect") } } } - ConnectionStatusCard(state, build?.version, build?.commit, serverTime) + ConnectionStatusCard(state, buildVersion, buildCommit, serverTime) Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer)) { Text( @@ -82,11 +130,11 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { ) } - Text("Workspace", style = MaterialTheme.typography.headlineSmall) + Text("Workspace", style = MaterialTheme.typography.titleMedium) OutlinedTextField( value = workspace, - onValueChange = vm::updateWorkspaceDraft, + onValueChange = onWorkspaceChange, label = { Text("Workspace path (on the server)") }, placeholder = { Text("/Users/you/repos/pipelines") }, singleLine = true, @@ -101,7 +149,7 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { }, modifier = Modifier.fillMaxWidth(), ) - Button(onClick = vm::saveWorkspace, enabled = workspaceError == null) { Text("Save workspace") } + Button(onClick = onSaveWorkspace, enabled = workspaceError == null) { Text("Save workspace") } Text("Saved workspace: ${configuredWorkspace.ifBlank { "(none)" }}") } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/theme/Color.kt b/android/app/src/main/java/net/awan/pipelines/ui/theme/Color.kt new file mode 100644 index 00000000..0020f17b --- /dev/null +++ b/android/app/src/main/java/net/awan/pipelines/ui/theme/Color.kt @@ -0,0 +1,81 @@ +package net.awan.pipelines.ui.theme + +import androidx.compose.ui.graphics.Color + +/** + * The app's own colour identity, deliberately dark-first so it matches the dark + * Pipelines TUI instead of the device wallpaper. The brand leans on a cool + * mint/teal seed with an amber tertiary, which also gives the workflow graph a + * clear success (tertiary) vs failure (error) distinction. + * + * Every on-colour is chosen for high contrast against its paired container in + * its own scheme, so text stays legible in both appearances. + */ + +// Dark scheme roles. +internal val DarkPrimary = Color(0xFF6FD3B8) +internal val DarkOnPrimary = Color(0xFF00382E) +internal val DarkPrimaryContainer = Color(0xFF005143) +internal val DarkOnPrimaryContainer = Color(0xFF8BF0D4) +internal val DarkSecondary = Color(0xFF7FC8D8) +internal val DarkOnSecondary = Color(0xFF00363F) +internal val DarkSecondaryContainer = Color(0xFF064E5A) +internal val DarkOnSecondaryContainer = Color(0xFFA9E9F5) +internal val DarkTertiary = Color(0xFFF2C879) +internal val DarkOnTertiary = Color(0xFF3F2E00) +internal val DarkTertiaryContainer = Color(0xFF5B4300) +internal val DarkOnTertiaryContainer = Color(0xFFFFE0A3) +internal val DarkError = Color(0xFFFFB4AB) +internal val DarkOnError = Color(0xFF690005) +internal val DarkErrorContainer = Color(0xFF93000A) +internal val DarkOnErrorContainer = Color(0xFFFFDAD6) +internal val DarkBackground = Color(0xFF0E1513) +internal val DarkOnBackground = Color(0xFFDEE4E1) +internal val DarkSurface = Color(0xFF0E1513) +internal val DarkOnSurface = Color(0xFFDEE4E1) +internal val DarkSurfaceVariant = Color(0xFF3F4946) +internal val DarkOnSurfaceVariant = Color(0xFFBEC9C5) +internal val DarkOutline = Color(0xFF889391) +internal val DarkOutlineVariant = Color(0xFF3F4946) +internal val DarkInverseSurface = Color(0xFFDEE4E1) +internal val DarkInverseOnSurface = Color(0xFF2B3230) +internal val DarkScrim = Color(0xFF000000) +internal val DarkSurfaceContainerLowest = Color(0xFF090F0E) +internal val DarkSurfaceContainerLow = Color(0xFF161D1B) +internal val DarkSurfaceContainer = Color(0xFF1A211F) +internal val DarkSurfaceContainerHigh = Color(0xFF252C2A) +internal val DarkSurfaceContainerHighest = Color(0xFF2F3634) + +// Light scheme roles. +internal val LightPrimary = Color(0xFF006B5B) +internal val LightOnPrimary = Color(0xFFFFFFFF) +internal val LightPrimaryContainer = Color(0xFF74F8DD) +internal val LightOnPrimaryContainer = Color(0xFF00201A) +internal val LightSecondary = Color(0xFF4A6368) +internal val LightOnSecondary = Color(0xFFFFFFFF) +internal val LightSecondaryContainer = Color(0xFFCCE8EF) +internal val LightOnSecondaryContainer = Color(0xFF051F23) +internal val LightTertiary = Color(0xFF7A5900) +internal val LightOnTertiary = Color(0xFFFFFFFF) +internal val LightTertiaryContainer = Color(0xFFFFDF9E) +internal val LightOnTertiaryContainer = Color(0xFF261A00) +internal val LightError = Color(0xFFBA1A1A) +internal val LightOnError = Color(0xFFFFFFFF) +internal val LightErrorContainer = Color(0xFFFFDAD6) +internal val LightOnErrorContainer = Color(0xFF410002) +internal val LightBackground = Color(0xFFF5FBF8) +internal val LightOnBackground = Color(0xFF171D1B) +internal val LightSurface = Color(0xFFF5FBF8) +internal val LightOnSurface = Color(0xFF171D1B) +internal val LightSurfaceVariant = Color(0xFFDAE5E1) +internal val LightOnSurfaceVariant = Color(0xFF3F4946) +internal val LightOutline = Color(0xFF6F7976) +internal val LightOutlineVariant = Color(0xFFBEC9C5) +internal val LightInverseSurface = Color(0xFF2B3230) +internal val LightInverseOnSurface = Color(0xFFECF2EF) +internal val LightScrim = Color(0xFF000000) +internal val LightSurfaceContainerLowest = Color(0xFFFFFFFF) +internal val LightSurfaceContainerLow = Color(0xFFEFF5F2) +internal val LightSurfaceContainer = Color(0xFFE9EFEC) +internal val LightSurfaceContainerHigh = Color(0xFFE3EAE7) +internal val LightSurfaceContainerHighest = Color(0xFFDDE4E1) diff --git a/android/app/src/main/java/net/awan/pipelines/ui/theme/Theme.kt b/android/app/src/main/java/net/awan/pipelines/ui/theme/Theme.kt index 51253138..ee866ca1 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/theme/Theme.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/theme/Theme.kt @@ -1,29 +1,93 @@ package net.awan.pipelines.ui.theme -import android.os.Build -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext -/** Material 3 theming with optional dynamic color and dark-mode support. */ +/** + * Material 3 theming. Dark is the default appearance so the app matches the dark + * Pipelines TUI on launch; the light scheme is retained for when it is + * explicitly requested. Dynamic (wallpaper) colour is deliberately not used so + * the app keeps its own identity. + */ @Composable fun PipelinesTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - dynamicColor: Boolean = true, + darkTheme: Boolean = true, content: @Composable () -> Unit, ) { - val context = LocalContext.current - val colorScheme = when { - dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) - } - darkTheme -> darkColorScheme() - else -> lightColorScheme() - } - MaterialTheme(colorScheme = colorScheme, content = content) + MaterialTheme( + colorScheme = if (darkTheme) PipelinesDarkColors else PipelinesLightColors, + content = content, + ) } + +internal val PipelinesDarkColors = darkColorScheme( + primary = DarkPrimary, + onPrimary = DarkOnPrimary, + primaryContainer = DarkPrimaryContainer, + onPrimaryContainer = DarkOnPrimaryContainer, + secondary = DarkSecondary, + onSecondary = DarkOnSecondary, + secondaryContainer = DarkSecondaryContainer, + onSecondaryContainer = DarkOnSecondaryContainer, + tertiary = DarkTertiary, + onTertiary = DarkOnTertiary, + tertiaryContainer = DarkTertiaryContainer, + onTertiaryContainer = DarkOnTertiaryContainer, + error = DarkError, + onError = DarkOnError, + errorContainer = DarkErrorContainer, + onErrorContainer = DarkOnErrorContainer, + background = DarkBackground, + onBackground = DarkOnBackground, + surface = DarkSurface, + onSurface = DarkOnSurface, + surfaceVariant = DarkSurfaceVariant, + onSurfaceVariant = DarkOnSurfaceVariant, + outline = DarkOutline, + outlineVariant = DarkOutlineVariant, + inverseSurface = DarkInverseSurface, + inverseOnSurface = DarkInverseOnSurface, + scrim = DarkScrim, + surfaceContainerLowest = DarkSurfaceContainerLowest, + surfaceContainerLow = DarkSurfaceContainerLow, + surfaceContainer = DarkSurfaceContainer, + surfaceContainerHigh = DarkSurfaceContainerHigh, + surfaceContainerHighest = DarkSurfaceContainerHighest, +) + +internal val PipelinesLightColors = lightColorScheme( + primary = LightPrimary, + onPrimary = LightOnPrimary, + primaryContainer = LightPrimaryContainer, + onPrimaryContainer = LightOnPrimaryContainer, + secondary = LightSecondary, + onSecondary = LightOnSecondary, + secondaryContainer = LightSecondaryContainer, + onSecondaryContainer = LightOnSecondaryContainer, + tertiary = LightTertiary, + onTertiary = LightOnTertiary, + tertiaryContainer = LightTertiaryContainer, + onTertiaryContainer = LightOnTertiaryContainer, + error = LightError, + onError = LightOnError, + errorContainer = LightErrorContainer, + onErrorContainer = LightOnErrorContainer, + background = LightBackground, + onBackground = LightOnBackground, + surface = LightSurface, + onSurface = LightOnSurface, + surfaceVariant = LightSurfaceVariant, + onSurfaceVariant = LightOnSurfaceVariant, + outline = LightOutline, + outlineVariant = LightOutlineVariant, + inverseSurface = LightInverseSurface, + inverseOnSurface = LightInverseOnSurface, + scrim = LightScrim, + surfaceContainerLowest = LightSurfaceContainerLowest, + surfaceContainerLow = LightSurfaceContainerLow, + surfaceContainer = LightSurfaceContainer, + surfaceContainerHigh = LightSurfaceContainerHigh, + surfaceContainerHighest = LightSurfaceContainerHighest, +) diff --git a/android/app/src/main/res/values-night/themes.xml b/android/app/src/main/res/values-night/themes.xml index 0f0070e6..2da27ca1 100644 --- a/android/app/src/main/res/values-night/themes.xml +++ b/android/app/src/main/res/values-night/themes.xml @@ -1,6 +1,12 @@ + diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..6b4c933f --- /dev/null +++ b/android/app/src/main/res/values/colors.xml @@ -0,0 +1,7 @@ + + + + #0E1513 + diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml index 41abc6a9..5ace3547 100644 --- a/android/app/src/main/res/values/themes.xml +++ b/android/app/src/main/res/values/themes.xml @@ -1,6 +1,14 @@ - diff --git a/android/app/src/test/java/net/awan/pipelines/ui/graph/WorkflowGraphTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/graph/WorkflowGraphTest.kt index 8d20cd7d..b23280ab 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/graph/WorkflowGraphTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/graph/WorkflowGraphTest.kt @@ -2,7 +2,9 @@ package net.awan.pipelines.ui.graph import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size +import androidx.compose.ui.unit.Density import net.awan.pipelines.data.protocol.Graph +import net.awan.pipelines.data.protocol.Protocol import net.awan.pipelines.data.protocol.Stage import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue @@ -12,6 +14,15 @@ class WorkflowGraphTest { private fun stage(key: String, edges: Map) = Stage(key = key, edges = edges) + private fun sampleGraph() = Graph( + stages = listOf( + stage("planner", mapOf("success" to "implementer", "error" to "#failure")), + stage("implementer", mapOf("success" to "reviewer", "blocked" to "#failure", "error" to "#failure")), + stage("reviewer", mapOf("success" to "ui_reviewer", "rejected" to "implementer", "error" to "#failure")), + stage("ui_reviewer", mapOf("approved" to "#success", "blocked" to "#failure", "rejected" to "implementer", "skipped" to "#success")), + ), + ) + /** * Regression for the back-edge ordering defect: `reviewer rejected -> implementer` * used to feed the longest-path relaxation and push `implementer` past @@ -20,14 +31,7 @@ class WorkflowGraphTest { */ @Test fun ranksFollowDeclarationOrderEvenWithBackEdges() { - val graph = Graph( - stages = listOf( - stage("planner", mapOf("success" to "implementer", "error" to "#failure")), - stage("implementer", mapOf("success" to "reviewer", "blocked" to "#failure", "error" to "#failure")), - stage("reviewer", mapOf("success" to "ui_reviewer", "rejected" to "implementer", "error" to "#failure")), - stage("ui_reviewer", mapOf("approved" to "#success", "blocked" to "#failure", "rejected" to "implementer", "skipped" to "#success")), - ), - ) + val graph = sampleGraph() val ranks = rankStages(graph) assertEquals(listOf("planner", "implementer", "reviewer", "ui_reviewer"), graph.stages.map { it.key }) assertEquals(0, ranks["planner"]) @@ -115,4 +119,72 @@ class WorkflowGraphTest { assertEquals(Offset.Zero, clampOffset(Offset.Zero, Size(0f, 0f), viewport, 40f)) assertTrue(clampOffset(Offset(1f, 2f), content, Size(10f, 10f), 40f).x.isFinite()) } + + @Test + fun terminalsShareALowerRowBelowEveryStage() { + val layout = layoutGraph(sampleGraph(), Density(1f)) + val failure = layout.nodes.single { it.key == Protocol.FAILURE_END } + val success = layout.nodes.single { it.key == Protocol.SUCCESS_END } + assertEquals(failure.y, success.y, 0.001f) + assertTrue(layout.nodes.filterNot { it.terminal } + .all { failure.y > it.y + it.height }) + } + + @Test + fun failureTerminalIsLeftOfSuccess() { + val layout = layoutGraph(sampleGraph(), Density(1f)) + val failure = layout.nodes.single { it.key == Protocol.FAILURE_END } + val success = layout.nodes.single { it.key == Protocol.SUCCESS_END } + assertTrue(failure.x < success.x) + } + + @Test + fun successEdgesEnterTheTerminalTopFromTheSourceRightEdge() { + val layout = layoutGraph(sampleGraph(), Density(1f)) + val success = layout.nodes.single { it.key == Protocol.SUCCESS_END } + val edge = layout.edges.first { it.edge.target == Protocol.SUCCESS_END } + val source = layout.nodes.single { it.key == edge.edge.source } + assertTrue(edge.topEntry) + assertTrue(!edge.bottomExit) + assertEquals(success.y, edge.to.y, 0.001f) + assertEquals(success.x + success.width / 2f, edge.to.x, 0.001f) + assertEquals(source.x + source.width, edge.from.x, 0.001f) + assertEquals(source.y + source.height / 2f, edge.from.y, 0.001f) + } + + @Test + fun errorToFailureDropsOutOfTheSourceBottomIntoTheTerminalTop() { + val layout = layoutGraph(sampleGraph(), Density(1f)) + val failure = layout.nodes.single { it.key == Protocol.FAILURE_END } + val planner = layout.nodes.single { it.key == "planner" } + val edge = layout.edges.first { it.edge.source == "planner" && it.edge.outcome == "error" } + assertTrue(edge.bottomExit) + assertTrue(edge.topEntry) + assertEquals(planner.y + planner.height, edge.from.y, 0.001f) + assertEquals(planner.x + planner.width / 2f, edge.from.x, 0.001f) + assertEquals(failure.x + failure.width / 2f, edge.to.x, 0.001f) + assertEquals(failure.y, edge.to.y, 0.001f) + } + + @Test + fun backEdgesKeepTheirFlagAndDeclarationOrderX() { + val layout = layoutGraph(sampleGraph(), Density(1f)) + val back = layout.edges.first { it.edge.source == "reviewer" && it.edge.outcome == "rejected" } + assertTrue(back.backEdge) + val reviewer = layout.nodes.single { it.key == "reviewer" } + val implementer = layout.nodes.single { it.key == "implementer" } + assertTrue(reviewer.x > implementer.x) + } + + @Test + fun smallGraphsProduceFiniteNonNegativeExtents() { + val empty = layoutGraph(Graph(), Density(1f)) + assertTrue(empty.width >= 0f && empty.height >= 0f) + assertTrue(empty.width.isFinite() && empty.height.isFinite()) + + val single = layoutGraph(Graph(stages = listOf(stage("only", emptyMap()))), Density(1f)) + assertTrue(single.width > 0f && single.height > 0f) + assertTrue(single.width.isFinite() && single.height.isFinite()) + assertTrue(single.nodes.single().terminal.not()) + } }