From 5f2a6a184f8a63cb04542dd5e8e9a7737c2c4faf Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 28 Oct 2026 23:51:29 -0400 Subject: [PATCH] ui: design tokens and the shared component set (plan P1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One palette, one geometry, one button. The alpha build had a four-colour darkColorScheme and every screen inventing its own pill, which is why the app read as a debug harness; `ui/Theme.kt` now carries the tokens and new UI takes them from `OwColors` / `OwRadius` / `OwSize` instead of Material defaults. Tokens (§1.1, §1.2): canvas #0A0C0E, surface #12161A, interactive #1C2228, border #262E36, mint accent #2EE59D, text #F3F5F7 / #9BA3AE / #5E6773, and the amber/crimson status triples. Cards are 16dp; buttons and inputs are 12dp squircles; 999dp survives only for status pills. Typography is system sans for chrome, and `MonoStyle` is the single mono style, reserved for pubkeys, truncated locators, seeds, host:port and block heights. Primitives (§1.3), in `ui/components/`: - OwButton — primary / secondary / outline / destructive, exact heights and radii, no elevation; - OwSegmentedControl — one track, accent selected segment, animated; - OwAlertBanner — warning / error / info with a status icon and a tinted surface; - OwCard, OwDivider, OwPill, OwStatusDot, TorStatusPill, OwSectionTitle, OwIconButton (36dp), Identicon, OwConfirmDialog (typed confirmation), OwQrCode (zxing, light plate for scanning). Fourteen single-colour vector icons, so no `material-icons-extended` (a multi-MB dependency) and no icon font. `Label`/`Mono` moved here from the roster so the design system is not owned by one screen. Behaviour: none. These are pure view helpers. --- .../com/siriusdevops/onionwire/ui/Theme.kt | 155 +++++++++-- .../onionwire/ui/components/AlertBanner.kt | 103 +++++++ .../onionwire/ui/components/Buttons.kt | 136 +++++++++ .../onionwire/ui/components/Dialogs.kt | 93 +++++++ .../onionwire/ui/components/QrCode.kt | 78 ++++++ .../ui/components/SegmentedControl.kt | 93 +++++++ .../onionwire/ui/components/Surfaces.kt | 260 ++++++++++++++++++ .../app/src/main/res/drawable/ic_ow_add.xml | 11 + .../app/src/main/res/drawable/ic_ow_chat.xml | 11 + .../main/res/drawable/ic_ow_chevron_left.xml | 15 + .../app/src/main/res/drawable/ic_ow_copy.xml | 18 ++ .../app/src/main/res/drawable/ic_ow_info.xml | 16 ++ .../app/src/main/res/drawable/ic_ow_lock.xml | 16 ++ .../src/main/res/drawable/ic_ow_more_vert.xml | 11 + .../src/main/res/drawable/ic_ow_person.xml | 18 ++ .../app/src/main/res/drawable/ic_ow_qr.xml | 16 ++ .../app/src/main/res/drawable/ic_ow_share.xml | 18 ++ .../src/main/res/drawable/ic_ow_shield.xml | 18 ++ .../src/main/res/drawable/ic_ow_sliders.xml | 22 ++ .../src/main/res/drawable/ic_ow_wallet.xml | 13 + .../src/main/res/drawable/ic_ow_warning.xml | 21 ++ .../onionwire/ui/components/IdenticonTest.kt | 45 +++ 22 files changed, 1167 insertions(+), 20 deletions(-) create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AlertBanner.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Buttons.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Dialogs.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/QrCode.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Surfaces.kt create mode 100644 android/app/src/main/res/drawable/ic_ow_add.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_chat.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_chevron_left.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_copy.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_info.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_lock.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_more_vert.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_person.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_qr.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_share.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_shield.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_sliders.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_wallet.xml create mode 100644 android/app/src/main/res/drawable/ic_ow_warning.xml create mode 100644 android/app/src/test/java/com/siriusdevops/onionwire/ui/components/IdenticonTest.kt diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/Theme.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/Theme.kt index b04565b..7133a98 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/Theme.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/Theme.kt @@ -1,34 +1,149 @@ package com.siriusdevops.onionwire.ui import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Typography import androidx.compose.material3.darkColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp -private val OnionViolet = Color(0xFF7C4DFF) -private val WireCyan = Color(0xFF38F2C7) -private val DeepVoid = Color(0xFF0B0B10) -private val PanelVoid = Color(0xFF15151C) +/** + * OnionWire design tokens. + * + * One canvas, two surfaces, one accent. The palette is deliberately small: + * every screen used to invent its own pill and its own grey, which is what made + * the alpha build read as a debug harness. + * + * Typography rule — the reason this file carries a [MonoStyle]: monospace is + * reserved for cryptographic material and numbers (pubkeys, truncated onion + * locators, seeds, `host:port`, block heights). Chrome is sans. A screen that + * sets `fontFamily = FontFamily.Monospace` on a sentence is a bug. + */ +object OwColors { + /** App canvas. */ + val Canvas = Color(0xFF0A0C0E) + /** Cards and elevated surfaces. */ + val Surface = Color(0xFF12161A) + + /** Inputs, secondary buttons, segmented-control track. */ + val SurfaceInteractive = Color(0xFF1C2228) + + /** The one border. 1dp, never a gradient. */ + val Border = Color(0xFF262E36) + + /** Primary brand / accent. Text on top of it is [Canvas], semibold. */ + val Accent = Color(0xFF2EE59D) + + val TextPrimary = Color(0xFFF3F5F7) + val TextSecondary = Color(0xFF9BA3AE) + val TextMuted = Color(0xFF5E6773) + + /** Success / connected is the accent — there is no second green. */ + val Success = Accent + + /** Warning / syncing. Text, 12% tint, 30% border. */ + val Warning = Color(0xFFF5A623) + val WarningTint = Color(0x1FF5A623) + val WarningBorder = Color(0x4DF5A623) + + /** Danger / error / destructive. */ + val Danger = Color(0xFFFF5C5C) + val DangerTint = Color(0x1FFF5C5C) + val DangerBorder = Color(0x4DFF5C5C) + + /** Info banner — the accent at banner tints, no third hue. */ + val InfoTint = Color(0x142EE59D) + val InfoBorder = Color(0x3D2EE59D) +} + +/** Geometry. Buttons and inputs are 12dp squircles, never 999dp pills. */ +object OwRadius { + /** Cards and the identity bar. */ + val Card = 16.dp + + /** Buttons, inputs, icon surfaces, segmented control. */ + val Control = 12.dp + + /** Small status badges and address chips only. */ + val Pill = 999.dp +} + +/** Fixed sizes from the spec. */ +object OwSize { + val Button = 48.dp + val ButtonCompact = 44.dp + val IconButton = 36.dp + val TabBar = 64.dp + val TabBarBorder = 1.dp + val ProgressTrack = 6.dp +} + +/** The only monospace style in the app. */ +val MonoStyle: TextStyle = TextStyle( + fontFamily = FontFamily.Monospace, + fontSize = 13.sp, + lineHeight = 18.sp, + color = OwColors.TextPrimary, +) + +private val OnionWireTypography = Typography( + // Chrome: system sans. No display face, no bundled grotesque. + displaySmall = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.Bold, fontSize = 28.sp, lineHeight = 34.sp), + headlineSmall = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.SemiBold, fontSize = 22.sp, lineHeight = 28.sp), + titleLarge = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.SemiBold, fontSize = 20.sp, lineHeight = 26.sp), + titleMedium = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.SemiBold, fontSize = 16.sp, lineHeight = 22.sp), + titleSmall = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.Medium, fontSize = 15.sp, lineHeight = 20.sp), + bodyLarge = TextStyle(fontFamily = FontFamily.SansSerif, fontSize = 16.sp, lineHeight = 24.sp), + bodyMedium = TextStyle(fontFamily = FontFamily.SansSerif, fontSize = 14.sp, lineHeight = 20.sp), + bodySmall = TextStyle(fontFamily = FontFamily.SansSerif, fontSize = 13.sp, lineHeight = 18.sp), + labelLarge = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.SemiBold, fontSize = 14.sp, lineHeight = 18.sp), + labelMedium = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.Medium, fontSize = 12.sp, lineHeight = 16.sp), + labelSmall = TextStyle(fontFamily = FontFamily.SansSerif, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 14.sp, letterSpacing = 0.6.sp), +) + +/** + * The scheme Material components (text fields, dialogs, dividers) still read + * from. New UI should take tokens from [OwColors] directly; `surfaceVariant` + * and `onSurfaceVariant` are mapped so untouched Material defaults do not fall + * back to purple. + */ private val OnionWireColors = darkColorScheme( - primary = WireCyan, - onPrimary = DeepVoid, - primaryContainer = OnionViolet, - onPrimaryContainer = Color.White, - secondary = OnionViolet, - onSecondary = Color.White, - background = DeepVoid, - onBackground = Color(0xFFE6E6F0), - surface = DeepVoid, - onSurface = Color(0xFFE6E6F0), - surfaceVariant = PanelVoid, - onSurfaceVariant = Color(0xFFB9B9CC), - outline = Color(0xFF3A3A4A), - error = Color(0xFFFF6B6B), - onError = DeepVoid, + primary = OwColors.Accent, + onPrimary = OwColors.Canvas, + primaryContainer = OwColors.SurfaceInteractive, + onPrimaryContainer = OwColors.TextPrimary, + secondary = OwColors.SurfaceInteractive, + onSecondary = OwColors.TextPrimary, + tertiary = OwColors.TextSecondary, + onTertiary = OwColors.Canvas, + background = OwColors.Canvas, + onBackground = OwColors.TextPrimary, + surface = OwColors.Canvas, + onSurface = OwColors.TextPrimary, + surfaceVariant = OwColors.Surface, + onSurfaceVariant = OwColors.TextSecondary, + surfaceContainer = OwColors.Surface, + surfaceContainerHigh = OwColors.SurfaceInteractive, + surfaceContainerLow = OwColors.Surface, + outline = OwColors.Border, + outlineVariant = OwColors.Border, + error = OwColors.Danger, + onError = OwColors.Canvas, + errorContainer = OwColors.DangerTint, + onErrorContainer = OwColors.Danger, + scrim = Color(0xCC000000), ) @Composable fun OnionWireTheme(content: @Composable () -> Unit) { - MaterialTheme(colorScheme = OnionWireColors, content = content) + MaterialTheme( + colorScheme = OnionWireColors, + typography = OnionWireTypography, + content = content, + ) } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AlertBanner.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AlertBanner.kt new file mode 100644 index 0000000..a7cbb3f --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AlertBanner.kt @@ -0,0 +1,103 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius + +/** Banner severity. Three states, matching the status colours exactly. */ +enum class OwAlertVariant { Warning, Error, Info } + +/** + * A contextual banner: status icon, one-line title, one- or two-line body. + * + * Replaces the raw red and grey paragraphs that used to trail the wallet and + * invite screens. A state the app is *in* (no wallet open, node experimental) is + * an info or warning banner; only a real failure gets [OwAlertVariant.Error]. + */ +@Composable +fun OwAlertBanner( + variant: OwAlertVariant, + title: String, + description: String? = null, + modifier: Modifier = Modifier, + action: (@Composable () -> Unit)? = null, +) { + val text: Color = when (variant) { + OwAlertVariant.Warning -> OwColors.Warning + OwAlertVariant.Error -> OwColors.Danger + OwAlertVariant.Info -> OwColors.TextPrimary + } + val tint: Color = when (variant) { + OwAlertVariant.Warning -> OwColors.WarningTint + OwAlertVariant.Error -> OwColors.DangerTint + OwAlertVariant.Info -> OwColors.InfoTint + } + val border: Color = when (variant) { + OwAlertVariant.Warning -> OwColors.WarningBorder + OwAlertVariant.Error -> OwColors.DangerBorder + OwAlertVariant.Info -> OwColors.InfoBorder + } + val iconRes = when (variant) { + OwAlertVariant.Warning -> R.drawable.ic_ow_warning + OwAlertVariant.Error -> R.drawable.ic_ow_warning + OwAlertVariant.Info -> R.drawable.ic_ow_info + } + val iconTint = when (variant) { + OwAlertVariant.Info -> OwColors.Accent + else -> text + } + + Row( + modifier = modifier + .fillMaxWidth() + .clip(RoundedCornerShape(OwRadius.Control)) + .background(tint) + .border(1.dp, border, RoundedCornerShape(OwRadius.Control)) + .padding(horizontal = 14.dp, vertical = 12.dp), + horizontalArrangement = Arrangement.Start, + ) { + Icon( + painter = painterResource(iconRes), + contentDescription = null, + tint = iconTint, + modifier = Modifier.padding(top = 1.dp).size(18.dp), + ) + Spacer(Modifier.width(10.dp)) + Column(Modifier.weight(1f)) { + Text(title, style = MaterialTheme.typography.titleSmall, color = text) + if (!description.isNullOrBlank()) { + Spacer(Modifier.height(3.dp)) + Text( + description, + style = MaterialTheme.typography.bodySmall, + color = if (variant == OwAlertVariant.Info) OwColors.TextSecondary else text, + ) + } + if (action != null) { + Spacer(Modifier.height(10.dp)) + action() + } + } + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Buttons.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Buttons.kt new file mode 100644 index 0000000..5c9832f --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Buttons.kt @@ -0,0 +1,136 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius +import com.siriusdevops.onionwire.ui.OwSize + +/** + * The four button tiers. There is no fifth: a screen that needs something + * quieter than [Outline] uses a text action, not a new shape. + */ +enum class OwButtonVariant { + /** Solid accent, canvas-coloured semibold text. One per screen region. */ + Primary, + + /** Solid interactive surface, no border. */ + Secondary, + + /** Transparent with the one border. */ + Outline, + + /** Tinted crimson with a crimson border. Destructive actions only. */ + Destructive, +} + +/** + * The app's button. + * + * Heights and radii come from the spec, not from Material's 40dp default: a + * 48dp target is comfortable and consistent, and a 12dp squircle replaces the + * 999dp pill that made every alpha action look identical. + */ +@Composable +fun OwButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + variant: OwButtonVariant = OwButtonVariant.Primary, + enabled: Boolean = true, + leadingIconRes: Int? = null, +) { + val height = when (variant) { + OwButtonVariant.Outline -> OwSize.ButtonCompact + else -> OwSize.Button + } + val container = when (variant) { + OwButtonVariant.Primary -> OwColors.Accent + OwButtonVariant.Secondary -> OwColors.SurfaceInteractive + OwButtonVariant.Outline -> Color.Transparent + OwButtonVariant.Destructive -> OwColors.DangerTint + } + val content = when (variant) { + OwButtonVariant.Primary -> OwColors.Canvas + OwButtonVariant.Secondary -> OwColors.TextPrimary + OwButtonVariant.Outline -> OwColors.TextPrimary + OwButtonVariant.Destructive -> OwColors.Danger + } + val weight = if (variant == OwButtonVariant.Primary) FontWeight.SemiBold else FontWeight.Medium + + Button( + onClick = onClick, + enabled = enabled, + modifier = modifier.height(height), + shape = RoundedCornerShape(OwRadius.Control), + border = when (variant) { + OwButtonVariant.Outline -> BorderStroke(1.dp, OwColors.Border) + OwButtonVariant.Destructive -> BorderStroke(1.dp, OwColors.DangerBorder) + else -> null + }, + colors = ButtonDefaults.buttonColors( + containerColor = container, + contentColor = content, + disabledContainerColor = when (variant) { + OwButtonVariant.Outline -> Color.Transparent + OwButtonVariant.Primary -> OwColors.SurfaceInteractive + OwButtonVariant.Secondary -> OwColors.Surface + OwButtonVariant.Destructive -> OwColors.Surface + }, + disabledContentColor = OwColors.TextMuted, + ), + elevation = ButtonDefaults.buttonElevation(defaultElevation = 0.dp, pressedElevation = 0.dp), + contentPadding = ButtonDefaults.ContentPadding, + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + ) { + if (leadingIconRes != null) { + Icon( + painter = painterResource(leadingIconRes), + contentDescription = null, + modifier = Modifier.size(18.dp), + ) + Spacer(Modifier.width(8.dp)) + } + Text(text, style = MaterialTheme.typography.labelLarge, fontWeight = weight) + } + } +} + +/** + * Two buttons sharing a row: the primary action takes the space, the secondary + * one takes what it needs. Used by the identity bar and the empty state. + */ +@Composable +fun OwButtonRow( + modifier: Modifier = Modifier, + content: @Composable androidx.compose.foundation.layout.RowScope.() -> Unit, +) { + Row( + modifier = modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(12.dp), + verticalAlignment = Alignment.CenterVertically, + content = content, + ) +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Dialogs.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Dialogs.kt new file mode 100644 index 0000000..cb8d1ea --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Dialogs.kt @@ -0,0 +1,93 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius + +/** + * A typed-confirmation dialog for an irreversible action. + * + * The typed word is not theatre: "Rotate identity" cuts every friend who is + * offline off the current locator, and "Wipe all chats" deletes every message + * body. Both are one stray tap away from a menu, so the dialog asks for the + * word the user is about to lose. + * + * [confirmationWord] is echoed in the field label; the confirm button stays + * disabled until it is typed (case-insensitively) — same contract the old inline + * confirm strip had, now with a real scrim behind it. + */ +@Composable +fun OwConfirmDialog( + title: String, + body: String, + confirmationWord: String, + confirmLabel: String, + destructive: Boolean, + onConfirm: () -> Unit, + onDismiss: () -> Unit, +) { + var typed by remember { mutableStateOf("") } + val armed = typed.trim().equals(confirmationWord, ignoreCase = true) + + AlertDialog( + onDismissRequest = onDismiss, + shape = RoundedCornerShape(OwRadius.Card), + containerColor = OwColors.Surface, + titleContentColor = OwColors.TextPrimary, + textContentColor = OwColors.TextSecondary, + title = { Text(title, style = MaterialTheme.typography.titleMedium) }, + text = { + Column { + Text(body, style = MaterialTheme.typography.bodyMedium) + Spacer(Modifier.height(14.dp)) + OutlinedTextField( + value = typed, + onValueChange = { typed = it }, + singleLine = true, + label = { Text("Type $confirmationWord") }, + modifier = Modifier.fillMaxWidth(), + ) + } + }, + confirmButton = { + Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) { + TextButton(onClick = onDismiss) { + Text("Cancel", color = OwColors.TextSecondary) + } + TextButton( + onClick = onConfirm, + enabled = armed, + ) { + Text( + confirmLabel, + color = when { + !armed -> OwColors.TextMuted + destructive -> OwColors.Danger + else -> OwColors.Accent + }, + ) + } + } + }, + modifier = Modifier.padding(horizontal = 8.dp), + ) +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/QrCode.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/QrCode.kt new file mode 100644 index 0000000..9e3fb3d --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/QrCode.kt @@ -0,0 +1,78 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.google.zxing.BarcodeFormat +import com.google.zxing.EncodeHintType +import com.google.zxing.qrcode.QRCodeWriter +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius + +/** + * Renders [payload] as a QR code. + * + * The invite is a locator plus a prekey — long, and it has to survive a person + * pointing a phone at a screen, so the modules are drawn at full contrast on a + * light plate rather than tinted to match the dark theme. + * + * A payload zxing cannot encode (too long for version 40) renders as an empty + * plate; callers always show the copyable text as well, so a failed encode is + * degraded, not fatal. + */ +@Composable +fun OwQrCode( + payload: String, + modifier: Modifier = Modifier, + size: Dp = 200.dp, +) { + val matrix = remember(payload) { + runCatching { + QRCodeWriter().encode( + payload, + BarcodeFormat.QR_CODE, + 0, + 0, + mapOf(EncodeHintType.MARGIN to 0), + ) + }.getOrNull() + } + Box( + modifier = modifier + .size(size) + .clip(RoundedCornerShape(OwRadius.Control)) + .background(OwColors.TextPrimary), + contentAlignment = Alignment.Center, + ) { + if (matrix != null) { + Canvas(Modifier.size(size)) { + val cells = matrix.width.toFloat() + val cellW = this.size.width / cells + val cellH = this.size.height / matrix.height.toFloat() + for (y in 0 until matrix.height) { + for (x in 0 until matrix.width) { + if (matrix.get(x, y)) { + drawRect( + color = Color(0xFF0A0C0E), + topLeft = Offset(x * cellW, y * cellH), + size = Size(cellW + 0.5f, cellH + 0.5f), + ) + } + } + } + } + } + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt new file mode 100644 index 0000000..11be548 --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt @@ -0,0 +1,93 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.role +import androidx.compose.ui.semantics.selected +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius + +/** + * Horizontal segmented control: one track, [OwColors.SurfaceInteractive], 4dp of + * inside padding, 12dp radius. + * + * This replaces the stacks of full-width pill buttons that made "Pruned / Full / + * Testnet" read as three unrelated actions rather than one choice with three + * values. The selected segment is an accent fill with canvas text. + */ +@Composable +fun OwSegmentedControl( + options: List, + selectedIndex: Int, + onSelect: (Int) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, +) { + Row( + modifier = modifier + .fillMaxWidth() + .clip(RoundedCornerShape(OwRadius.Control)) + .background(OwColors.SurfaceInteractive) + .padding(4.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + options.forEachIndexed { index, label -> + val selected = index == selectedIndex + val container by animateColorAsState( + targetValue = if (selected) OwColors.Accent else OwColors.SurfaceInteractive, + animationSpec = tween(durationMillis = 160), + label = "segment-container", + ) + val textColor by animateColorAsState( + targetValue = when { + selected -> OwColors.Canvas + enabled -> OwColors.TextSecondary + else -> OwColors.TextMuted + }, + animationSpec = tween(durationMillis = 160), + label = "segment-text", + ) + Box( + modifier = Modifier + .weight(1f) + .height(36.dp) + .clip(RoundedCornerShape(9.dp)) + .background(container) + .clickable(enabled = enabled && !selected) { onSelect(index) } + .semantics { + role = Role.Tab + this.selected = selected + }, + contentAlignment = Alignment.Center, + ) { + Text( + label, + style = MaterialTheme.typography.labelLarge, + fontSize = 13.sp, + fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Medium, + color = textColor, + ) + } + } + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Surfaces.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Surfaces.kt new file mode 100644 index 0000000..57bdfde --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/Surfaces.kt @@ -0,0 +1,260 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.siriusdevops.onionwire.ui.MonoStyle +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius +import com.siriusdevops.onionwire.ui.OwSize + +/** + * A section card: [OwColors.Surface], 16dp radius, one 1dp border, 16dp of + * padding. Every non-list block on every screen is one of these. + */ +@Composable +fun OwCard( + modifier: Modifier = Modifier, + padding: Dp = 16.dp, + content: @Composable ColumnScope.() -> Unit, +) { + Column( + modifier = modifier + .clip(RoundedCornerShape(OwRadius.Card)) + .background(OwColors.Surface) + .border(1.dp, OwColors.Border, RoundedCornerShape(OwRadius.Card)) + .padding(padding), + content = content, + ) +} + +/** Small tracked label, secondary colour. Never monospace. */ +@Composable +fun Label(text: String, modifier: Modifier = Modifier) { + Text( + text, + modifier = modifier, + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextSecondary, + ) +} + +/** + * Cryptographic material and numbers only: pubkeys, truncated locators, seeds, + * `host:port`, block heights. Never a sentence. + */ +@Composable +fun Mono(text: String, modifier: Modifier = Modifier, color: Color = OwColors.TextPrimary) { + Text(text, modifier = modifier, style = MonoStyle.copy(color = color)) +} + +/** Section heading inside a card. */ +@Composable +fun OwSectionTitle(text: String, modifier: Modifier = Modifier) { + Text( + text, + modifier = modifier, + style = MaterialTheme.typography.titleMedium, + color = OwColors.TextPrimary, + ) +} + +/** A 7dp status dot. Colour is the caller's statement, not decoration. */ +@Composable +fun OwStatusDot(color: Color, modifier: Modifier = Modifier) { + Box(modifier.size(7.dp).clip(CircleShape).background(color)) +} + +/** Small status badge — the one place a 999dp radius is correct. */ +@Composable +fun OwPill( + text: String, + modifier: Modifier = Modifier, + textColor: Color = OwColors.TextSecondary, + container: Color = OwColors.SurfaceInteractive, + borderColor: Color? = null, + dotColor: Color? = null, +) { + Row( + modifier = modifier + .clip(RoundedCornerShape(OwRadius.Pill)) + .background(container) + .then( + if (borderColor != null) { + Modifier.border(1.dp, borderColor, RoundedCornerShape(OwRadius.Pill)) + } else { + Modifier + }, + ) + .padding(horizontal = 10.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(6.dp), + ) { + if (dotColor != null) OwStatusDot(dotColor) + Text(text, style = MaterialTheme.typography.labelSmall, color = textColor, fontSize = 11.sp) + } +} + +/** + * The header status pill: `● Tor active`. + * + * Shown while the app is in `Phase.Ready`, which is exactly when the node (and + * therefore Arti) is up. It says nothing about reachability after the app + * leaves the foreground — the keep-alive state is a separate row on the + * settings screen, because that is the honest place for it. + */ +@Composable +fun TorStatusPill(modifier: Modifier = Modifier) { + OwPill( + text = "Tor active", + modifier = modifier, + textColor = OwColors.Accent, + container = OwColors.InfoTint, + borderColor = OwColors.InfoBorder, + dotColor = OwColors.Accent, + ) +} + +/** + * A 36x36 icon button on an interactive surface. Used for Lock, back chevrons + * and the overflow trigger. + */ +@Composable +fun OwIconButton( + iconRes: Int, + contentDescription: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + tint: Color = OwColors.TextPrimary, + background: Color = OwColors.SurfaceInteractive, + size: Dp = OwSize.IconButton, +) { + Box( + modifier = modifier + .size(size) + .clip(RoundedCornerShape(OwRadius.Control)) + .background(background) + .clickable(onClick = onClick) + .semantics { this.contentDescription = contentDescription }, + contentAlignment = Alignment.Center, + ) { + Icon( + painter = painterResource(iconRes), + contentDescription = null, + tint = tint, + modifier = Modifier.size(18.dp), + ) + } +} + +/** + * A deterministic 5x5 identicon derived from the identity fingerprint. + * + * Not a security feature: it is a stable visual handle so "your identity" is + * recognisable at a glance without reading 64 hex characters. It renders the + * seed it was given — it never invents a value, and two devices showing the + * same fingerprint show the same picture. + */ +@Composable +fun Identicon(seed: String, modifier: Modifier = Modifier, size: Dp = 40.dp) { + val palette = listOf(OwColors.Accent, OwColors.TextSecondary, OwColors.TextMuted) + val cells = identiconCells(seed) + Box( + modifier = modifier + .size(size) + .clip(CircleShape) + .background(OwColors.SurfaceInteractive), + contentAlignment = Alignment.Center, + ) { + Canvas(Modifier.size(size * 0.62f)) { + val cell = this.size.minDimension / 5f + val pad = (this.size.minDimension - cell * 5f) / 2f + cells.forEach { (x, y, tone) -> + drawRect( + color = palette[tone % palette.size], + topLeft = Offset(pad + x * cell, pad + y * cell), + size = Size(cell, cell), + ) + } + } + } +} + +/** + * The left half of a 5-wide grid plus its mirror, as (column, row, tone) + * triples. Pure and cheap: the same seed always yields the same picture. + */ +internal fun identiconCells(seed: String): List> { + if (seed.isEmpty()) return emptyList() + val bytes = seed.map { it.code }.toIntArray() + var i = 0 + val out = mutableListOf>() + for (row in 0 until 5) { + for (col in 0 until 3) { + val v = bytes[i % bytes.size] + i++ + // A cell exists when the byte says so; tone varies the shade. + if (v % 3 != 0) { + val tone = (v / 3) % 3 + out += Triple(col, row, tone) + val mirrored = 4 - col + if (mirrored != col) out += Triple(mirrored, row, tone) + } + } + } + return out +} + +/** The one hairline rule. */ +@Composable +fun OwDivider(modifier: Modifier = Modifier, color: Color = OwColors.Border) { + Box(modifier.fillMaxWidth().height(1.dp).background(color)) +} + +/** Border stroke helper so screens never hardcode the token twice. */ +val OwCardBorder: BorderStroke = BorderStroke(1.dp, OwColors.Border) + +/** Convenience for the many `Icon(painterResource(...))` call sites. */ +@Composable +fun OwIcon( + iconRes: Int, + contentDescription: String?, + tint: Color = OwColors.TextPrimary, + size: Dp = 20.dp, +) { + Icon( + painter = painterResource(iconRes), + contentDescription = contentDescription, + tint = tint, + modifier = Modifier.size(size), + ) +} diff --git a/android/app/src/main/res/drawable/ic_ow_add.xml b/android/app/src/main/res/drawable/ic_ow_add.xml new file mode 100644 index 0000000..3f91af8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_add.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_chat.xml b/android/app/src/main/res/drawable/ic_ow_chat.xml new file mode 100644 index 0000000..e673602 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_chat.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_chevron_left.xml b/android/app/src/main/res/drawable/ic_ow_chevron_left.xml new file mode 100644 index 0000000..b235eaa --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_chevron_left.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_copy.xml b/android/app/src/main/res/drawable/ic_ow_copy.xml new file mode 100644 index 0000000..d52c3fb --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_copy.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_info.xml b/android/app/src/main/res/drawable/ic_ow_info.xml new file mode 100644 index 0000000..2a5d106 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_info.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_lock.xml b/android/app/src/main/res/drawable/ic_ow_lock.xml new file mode 100644 index 0000000..fce7ee1 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_lock.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_more_vert.xml b/android/app/src/main/res/drawable/ic_ow_more_vert.xml new file mode 100644 index 0000000..bcd27db --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_more_vert.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_person.xml b/android/app/src/main/res/drawable/ic_ow_person.xml new file mode 100644 index 0000000..7bc0b35 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_person.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_qr.xml b/android/app/src/main/res/drawable/ic_ow_qr.xml new file mode 100644 index 0000000..7e43c96 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_qr.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_share.xml b/android/app/src/main/res/drawable/ic_ow_share.xml new file mode 100644 index 0000000..dc49c02 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_share.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_shield.xml b/android/app/src/main/res/drawable/ic_ow_shield.xml new file mode 100644 index 0000000..2aab4a8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_shield.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_sliders.xml b/android/app/src/main/res/drawable/ic_ow_sliders.xml new file mode 100644 index 0000000..d16a838 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_sliders.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_wallet.xml b/android/app/src/main/res/drawable/ic_ow_wallet.xml new file mode 100644 index 0000000..ed74045 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_wallet.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/android/app/src/main/res/drawable/ic_ow_warning.xml b/android/app/src/main/res/drawable/ic_ow_warning.xml new file mode 100644 index 0000000..234711a --- /dev/null +++ b/android/app/src/main/res/drawable/ic_ow_warning.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/components/IdenticonTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/components/IdenticonTest.kt new file mode 100644 index 0000000..38d6424 --- /dev/null +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/components/IdenticonTest.kt @@ -0,0 +1,45 @@ +package com.siriusdevops.onionwire.ui.components + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * The identicon is a rendering of the identity fingerprint, so it has to be a + * function of that value and nothing else: same fingerprint, same picture, on + * every device and every launch. Pure (a list of cells), no Compose runtime. + */ +class IdenticonTest { + + private val fingerprint = + "9f2c41ab77de03b5c8e1f0a6d4b39c2e5a7f81c0d3e6b492af17c5d80e3b6a49" + + @Test + fun the_same_seed_always_produces_the_same_cells() { + assertEquals(identiconCells(fingerprint), identiconCells(fingerprint)) + } + + @Test + fun the_picture_is_mirrored_about_the_middle_column() { + val cells = identiconCells(fingerprint) + val columns = cells.map { it.first } + cells.forEach { (col, row, tone) -> + assertTrue( + "column $col row $row is not mirrored", + cells.any { it.first == 4 - col && it.second == row && it.third == tone }, + ) + } + assertTrue(columns.all { it in 0..4 }) + } + + @Test + fun a_different_seed_produces_a_different_picture() { + val other = fingerprint.reversed() + assertTrue(identiconCells(fingerprint) != identiconCells(other)) + } + + @Test + fun an_empty_seed_draws_nothing() { + assertEquals(emptyList>(), identiconCells("")) + } +}