From 5f2a6a184f8a63cb04542dd5e8e9a7737c2c4faf Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 28 Oct 2026 23:51:29 -0400 Subject: [PATCH 1/4] 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("")) + } +} From 0283e6bf48c7a55df062b98b9a8726a5d9f9f000 Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 28 Oct 2026 23:51:51 -0400 Subject: [PATCH 2/4] ui: app shell, messenger and invite refresh (plan P2 and P3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plans P2 and P3 are one change: the shell decides who calls the roster, so the roster cannot land before it. The tree is green at this commit, which is why they are not split. Shell (P2) - The horizontal text-link bar is gone. Three top-level destinations hang off a persistent 64dp bottom bar — Chats (default), Wallet, Node and Settings — and everything else is a sub-screen behind a chevron. - MainActivity owns the shell: a Scaffold with the tab bar around a NavHost of chats / wallet / settings plus share, paste, chat, profile, wallets and rotate. Tab selection pops back to the start destination and restores saved state, so a chat left open behind the Wallet tab survives a trip to Settings. - The node keeps living on the wallet screen, where its card already is, so the third tab is the security surface: profile, saved wallets, rotate identity, delete message history, the keep-alive status row, and — disclosed here instead of under the roster — the identity/SDK lines that made the home screen read as a test build. - OwTopBar: 20sp bold title, optional "Tor active" pill beneath it, a 36dp padlock surface for Lock, and the overflow. Rotate identity, saved wallets and delete history live in the overflow; the destructive two go through a typed confirmation dialog or the typed ROTATE screen, never a single tap. - Insets: the tab bar consumes the navigation-bar inset and LocalBottomBarPresent tells screens inside the shell not to pad for it again, so there is no double gap above the tabs and the IME still wins when the keyboard is up. - window.isNavigationBarContrastEnforced = false on Q+, so the system's translucent scrim does not draw a second band over the canvas. Messenger (P3) - The identity block is one bar: identicon, "Your identity", the truncated fingerprint in mono, a copy-invite icon and a QR icon. Gone from here: the YOU (stable forever) card, the "sdk … · identity = ed25519 pubkey" line and the keep-alive paragraph. The full fingerprint and locator stay on the profile and invite screens. - The empty state says what to do and offers both ways out ("Add contact", "Share my invite"), and keeps the honest sentence: invites are not discoverable. - Friend rows: petname, short mono fingerprint, and a locator shortened as head…tail.onion — the suffix is never the part that is cut, and a v3 onion is never soft-wrapped. - Invite sharing shows a QR of the payload beside the copyable text; the clip is marked sensitive on API 33+. No ViewModel, SDK, Tor or wallet call changed. Every callback is the call the old screens made; the wallet screens are untouched for the next card. --- android/README.md | 32 +- .../siriusdevops/onionwire/MainActivity.kt | 243 ++++++--- .../siriusdevops/onionwire/ui/ChatScreen.kt | 8 +- .../com/siriusdevops/onionwire/ui/Insets.kt | 29 +- .../onionwire/ui/InviteScreens.kt | 284 +++++----- .../onionwire/ui/ProfileScreen.kt | 8 +- .../siriusdevops/onionwire/ui/RosterScreen.kt | 485 ++++++++++-------- .../siriusdevops/onionwire/ui/RotateScreen.kt | 12 +- .../onionwire/ui/SettingsScreen.kt | 215 ++++++++ .../onionwire/ui/components/AppTopBar.kt | 79 +++ .../onionwire/ui/components/BottomTabBar.kt | 125 +++++ .../onionwire/ui/components/OverflowMenu.kt | 69 +++ .../onionwire/ui/RosterOnionTest.kt | 45 ++ 13 files changed, 1228 insertions(+), 406 deletions(-) create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AppTopBar.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt create mode 100644 android/app/src/main/java/com/siriusdevops/onionwire/ui/components/OverflowMenu.kt create mode 100644 android/app/src/test/java/com/siriusdevops/onionwire/ui/RosterOnionTest.kt diff --git a/android/README.md b/android/README.md index e911d99..c3005e6 100644 --- a/android/README.md +++ b/android/README.md @@ -344,6 +344,20 @@ The cuprated graph is built with Rust 1.98 here, the same floor as `ci.yml` (`rust-version = "1.98"`). Job timeout is **90** minutes on `android-release.yml` and **120** on `android-ci.yml`. +## App shell + +Three top-level destinations, one persistent bottom tab bar +(`ui/components/BottomTabBar.kt`): **Chats** (default), **Wallet**, and **Node & +Settings**. Sub-screens (chat, invite share, add contact, rotate, profile, saved +wallets) keep a chevron back button and hide the bar. The rare and destructive +actions — rotate identity, delete message history, saved wallets — are behind the +`⋮` overflow and a typed confirmation, not on the home screen. + +Colours, radii and type live in `ui/Theme.kt` as `OwColors` / `OwRadius` / +`OwSize`; new UI takes tokens from there instead of `MaterialTheme` defaults. +Monospace is reserved for pubkeys, truncated onion locators, seeds, `host:port` +and block heights — never for a sentence. + ## Layout ``` @@ -363,25 +377,33 @@ android/ build.gradle.kts src/main/AndroidManifest.xml src/main/java/com/siriusdevops/onionwire/ - MainActivity.kt # NavHost + MainActivity.kt # app shell: bottom tabs + NavHost WireViewModel.kt # UI-side Wire handle; wallet-child poller crypto/ # Keystore-wrapped store passphrase keepalive/ # NodeHost, KeepAliveService, policy, lifetime wallet/ # ChainStorage, WalletChildBinaries ui/ # Compose screens (M3) + components/ # design system: OwButton, OwSegmentedControl, + # OwAlertBanner, OwCard, OwTopBar, OwBottomTabBar, + # OwConfirmDialog, OwQrCode, Identicon WalletScreen.kt + WalletManagerScreen.kt WalletChildStatusText.kt ChatScreen.kt - RosterScreen.kt - InviteScreens.kt + RosterScreen.kt # Chats tab: identity bar + roster + SettingsScreen.kt # Node & Settings tab + ProfileScreen.kt + InviteScreens.kt # share (QR + text) and paste-a-contact InviteAddFlow.kt OutboxDetail.kt MessageDelivery.kt UnlockScreen.kt UnlockSubmit.kt + SeedBackupGate.kt RotateScreen.kt - Insets.kt - Theme.kt + Insets.kt # systemBars ∪ ime, minus the tab-bar inset + Theme.kt # design tokens: palette, radii, sizes, typography + src/main/res/drawable/ic_ow_*.xml # single-colour design-system icons src/test/ # JVM: envelope, store, invite, outbox, keepalive, wallet line, refresh loop src/androidTest/ # device-only: AndroidKeyStore src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt index 0cd7f57..772f733 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt @@ -8,37 +8,61 @@ import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Surface +import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier +import androidx.core.view.WindowCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.navigation.NavHostController import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import androidx.navigation.navArgument import com.siriusdevops.onionwire.ui.ChatScreen +import com.siriusdevops.onionwire.ui.LocalBottomBarPresent +import com.siriusdevops.onionwire.ui.OnionWireTheme import com.siriusdevops.onionwire.ui.PasteInviteScreen import com.siriusdevops.onionwire.ui.ProfileScreen import com.siriusdevops.onionwire.ui.RosterScreen import com.siriusdevops.onionwire.ui.RotateScreen +import com.siriusdevops.onionwire.ui.SettingsScreen import com.siriusdevops.onionwire.ui.ShareInviteScreen import com.siriusdevops.onionwire.ui.UnlockScreen import com.siriusdevops.onionwire.ui.WalletManagerScreen import com.siriusdevops.onionwire.ui.WalletScreen -import com.siriusdevops.onionwire.ui.OnionWireTheme +import com.siriusdevops.onionwire.ui.components.OwBottomTabBar +import com.siriusdevops.onionwire.ui.components.OwTab import kotlinx.coroutines.launch class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() + // The shell paints the canvas to the bottom of the screen behind the tab + // bar; the system's translucent three-button scrim would draw a second, + // lighter band over it (edge-to-edge guidance, SDK 29+). + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + window.isNavigationBarContrastEnforced = false + } + // enableEdgeToEdge() from ComponentActivity sets the icon appearance from + // the system theme; the app is dark-only, so the bars are always dark with + // light icons. Re-assert it here in case the theme changes under us. + WindowCompat.getInsetsController(window, window.decorView).apply { + isAppearanceLightStatusBars = false + isAppearanceLightNavigationBars = false + } setContent { OnionWireTheme { Surface( @@ -61,7 +85,7 @@ private fun AppRoot(vm: WireViewModel = viewModel()) { // Asked in context: the notification is the keep-alive's only visible // trace, so the prompt lands when the node becomes reachable rather than at // first launch. Denial is not fatal — the service runs either way and the - // roster says the notice is hidden. + // settings screen says the notice is hidden. val askNotifications = rememberLauncherForActivityResult( ActivityResultContracts.RequestPermission(), ) { vm.onNotificationPermissionChanged() } @@ -87,86 +111,165 @@ private fun AppRoot(vm: WireViewModel = viewModel()) { } } +/** Top-level destinations. Everything else is a sub-screen with a chevron. */ +private object Routes { + const val Chats = "chats" + const val Wallet = "wallet" + const val Settings = "settings" + const val Share = "share" + const val Paste = "paste" + const val Rotate = "rotate" + const val Profile = "profile" + const val Wallets = "wallets" + const val Chat = "chat/{pk}" + + fun tabOf(route: String?): OwTab? = when (route) { + Chats -> OwTab.Chats + Wallet -> OwTab.Wallet + Settings -> OwTab.Settings + else -> null + } + + fun routeOf(tab: OwTab): String = when (tab) { + OwTab.Chats -> Chats + OwTab.Wallet -> Wallet + OwTab.Settings -> Settings + } +} + +/** + * The app shell. + * + * A `Scaffold` whose only job is the persistent bottom tab bar: it owns the + * navigation-bar inset, the screens keep owning their own top bars and system + * insets (see `screenContentInsets`), and `LocalBottomBarPresent` tells those + * screens not to pad for the bar a second time. + * + * Selecting a tab pops back to the start destination and restores that tab's + * saved state, so a chat left open behind the Wallet tab is still there when the + * user comes back — the standard bottom-nav contract. + */ @Composable private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: String?) { val nav = rememberNavController() val friends by vm.friends.collectAsStateWithLifecycle() val scope = rememberCoroutineScope() + val entry by nav.currentBackStackEntryAsState() + val tab = Routes.tabOf(entry?.destination?.route) - NavHost(navController = nav, startDestination = "roster") { - composable("roster") { - RosterScreen( - fingerprint = ready.fingerprint, - onion = ready.onion, - sdkVersion = ready.sdkVersion, - friends = friends, - keepAliveNote = keepAliveNote, - onOpenChat = { nav.navigate("chat/${it.pubkeyHex}") }, - onShare = { nav.navigate("share") }, - onPaste = { nav.navigate("paste") }, - onRotate = { nav.navigate("rotate") }, - onWipe = { scope.launch { vm.wipeMessages() } }, - onOpenProfile = { nav.navigate("profile") }, - onLock = vm::lock, - onOpenWallet = { nav.navigate("wallet") }, - ) - } + Scaffold( + // Each screen's Scaffold applies its own bars; zeroing this one keeps the + // status bar from being padded twice and leaves the only inset this + // level owns — the tab bar's height — in `pad`. + contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = MaterialTheme.colorScheme.background, + bottomBar = { + if (tab != null) { + OwBottomTabBar(selected = tab, onSelect = { nav.selectTab(it) }) + } + }, + ) { pad -> + CompositionLocalProvider(LocalBottomBarPresent provides (tab != null)) { + NavHost( + navController = nav, + startDestination = Routes.Chats, + modifier = Modifier.padding(bottom = pad.calculateBottomPadding()), + ) { + composable(Routes.Chats) { + RosterScreen( + fingerprint = ready.fingerprint, + friends = friends, + invite = vm::invite, + onOpenChat = { nav.navigate("chat/${it.pubkeyHex}") }, + onShare = { nav.navigate(Routes.Share) }, + onPaste = { nav.navigate(Routes.Paste) }, + onRotate = { nav.navigate(Routes.Rotate) }, + onWipe = { scope.launch { vm.wipeMessages() } }, + onOpenProfile = { nav.navigate(Routes.Profile) }, + onLock = vm::lock, + onOpenWallets = { nav.navigate(Routes.Wallets) }, + ) + } - composable("share") { - ShareInviteScreen(ownerInvite = vm::invite, onBack = { nav.popBackStack() }) - } + composable(Routes.Wallet) { + WalletScreen( + vm = vm, + onBack = { nav.popBackStack() }, + onOpenWallets = { nav.navigate(Routes.Wallets) }, + ) + } - composable("paste") { - PasteInviteScreen( - onDecode = vm::decode, - onAdd = vm::addFriend, - onBack = { nav.popBackStack() }, - ) - } + composable(Routes.Settings) { + SettingsScreen( + sdkVersion = ready.sdkVersion, + keepAliveNote = keepAliveNote, + onOpenProfile = { nav.navigate(Routes.Profile) }, + onOpenWallets = { nav.navigate(Routes.Wallets) }, + onRotate = { nav.navigate(Routes.Rotate) }, + onWipe = { scope.launch { vm.wipeMessages() } }, + onLock = vm::lock, + ) + } - composable("rotate") { - RotateScreen( - currentOnion = ready.onion, - onRotate = { - val out = vm.rotateOnion() - out.notified.toInt() to out.friends.toInt() - }, - onBack = { nav.popBackStack() }, - ) - } + composable(Routes.Share) { + ShareInviteScreen(ownerInvite = vm::invite, onBack = { nav.popBackStack() }) + } - composable("wallet") { - WalletScreen( - vm = vm, - onBack = { nav.popBackStack() }, - onOpenWallets = { nav.navigate("wallets") }, - ) - } + composable(Routes.Paste) { + PasteInviteScreen( + onDecode = vm::decode, + onAdd = vm::addFriend, + onBack = { nav.popBackStack() }, + ) + } - composable("wallets") { - WalletManagerScreen(vm = vm, onBack = { nav.popBackStack() }) - } + composable(Routes.Rotate) { + RotateScreen( + currentOnion = ready.onion, + onRotate = { + val out = vm.rotateOnion() + out.notified.toInt() to out.friends.toInt() + }, + onBack = { nav.popBackStack() }, + ) + } - composable("profile") { - ProfileScreen(vm = vm, onBack = { nav.popBackStack() }) - } + composable(Routes.Wallets) { + WalletManagerScreen(vm = vm, onBack = { nav.popBackStack() }) + } - composable( - route = "chat/{pk}", - arguments = listOf(navArgument("pk") { type = NavType.StringType }), - ) { entry -> - val pk = entry.arguments?.getString("pk").orEmpty() - val friend = friends.firstOrNull { it.pubkeyHex == pk } - ChatScreen( - vm = vm, - peer = pk, - title = friend?.petname?.takeIf { it.isNotBlank() } - ?: friend?.fingerprint - ?: pk.take(16), - fingerprint = friend?.fingerprint ?: pk.take(16), - onion = friend?.onion.orEmpty(), - onBack = { nav.popBackStack() }, - ) + composable(Routes.Profile) { + ProfileScreen(vm = vm, onBack = { nav.popBackStack() }) + } + + composable( + route = Routes.Chat, + arguments = listOf(navArgument("pk") { type = NavType.StringType }), + ) { chatEntry -> + val pk = chatEntry.arguments?.getString("pk").orEmpty() + val friend = friends.firstOrNull { it.pubkeyHex == pk } + ChatScreen( + vm = vm, + peer = pk, + title = friend?.petname?.takeIf { it.isNotBlank() } + ?: friend?.fingerprint + ?: pk.take(16), + fingerprint = friend?.fingerprint ?: pk.take(16), + onion = friend?.onion.orEmpty(), + onBack = { nav.popBackStack() }, + ) + } + } } } } + +private fun NavHostController.selectTab(target: OwTab) { + val route = Routes.routeOf(target) + if (currentDestination?.route == route) return + navigate(route) { + popUpTo(graph.startDestinationId) { saveState = true } + launchSingleTop = true + restoreState = true + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ChatScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ChatScreen.kt index 499b6f8..84ccd0b 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ChatScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ChatScreen.kt @@ -51,6 +51,8 @@ import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.components.OwIconButton import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.siriusdevops.onionwire.WireViewModel import uniffi.onionwire_sdk.SendState @@ -184,7 +186,11 @@ fun ChatScreen( } }, navigationIcon = { - IconButton(onClick = onBack) { Text("<") } + OwIconButton( + iconRes = R.drawable.ic_ow_chevron_left, + contentDescription = "Back", + onClick = onBack, + ) }, colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.background, diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/Insets.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/Insets.kt index fd7802d..88a7629 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/Insets.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/Insets.kt @@ -8,8 +8,18 @@ import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.union import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.runtime.Composable +import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Modifier +/** + * True while a screen is rendered inside the shell that owns the bottom tab bar. + * + * The tab bar applies the navigation-bar inset itself, so a screen inside the + * shell must not pad for it a second time — that is the difference between the + * list ending just above the tabs and the list floating 48dp above them. + */ +val LocalBottomBarPresent = staticCompositionLocalOf { false } + /** * The bottom + horizontal window insets one screen's content root must apply * itself. @@ -25,7 +35,9 @@ import androidx.compose.ui.Modifier * * The IME's bottom inset already covers the navigation bar, so the two are * unioned (per-side `max`), never summed: keyboard height while typing, - * navigation-bar height otherwise, and no double padding in between. + * navigation-bar height otherwise, and no double padding in between. Inside the + * tab shell the vertical bar inset is dropped entirely — see + * [LocalBottomBarPresent]. * * The `Top` side is deliberately excluded — a `Scaffold`'s `pad.top` is the app * bar's own measured height, and the app bar carries its own status-bar inset @@ -38,8 +50,15 @@ import androidx.compose.ui.Modifier * composable reads — call it from a composable (every call site is one). */ @Composable -fun Modifier.screenContentInsets(): Modifier = - windowInsetsPadding( - WindowInsets.systemBars.union(WindowInsets.ime) +fun Modifier.screenContentInsets(): Modifier { + val sides = if (LocalBottomBarPresent.current) { + WindowInsetsSides.Horizontal + } else { + WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom + } + return windowInsetsPadding( + WindowInsets.systemBars.only(sides) + .union(WindowInsets.ime) .only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom), - ) \ No newline at end of file + ) +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt index 4d67f52..599e6a4 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt @@ -1,6 +1,9 @@ package com.siriusdevops.onionwire.ui import android.content.ClipData +import android.content.ClipDescription +import android.os.Build +import android.os.PersistableBundle import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -11,20 +14,13 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll -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.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -32,15 +28,36 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ClipEntry import androidx.compose.ui.platform.LocalClipboard +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwAlertBanner +import com.siriusdevops.onionwire.ui.components.OwAlertVariant +import com.siriusdevops.onionwire.ui.components.OwButton +import com.siriusdevops.onionwire.ui.components.OwButtonVariant +import com.siriusdevops.onionwire.ui.components.OwCard +import com.siriusdevops.onionwire.ui.components.OwDivider +import com.siriusdevops.onionwire.ui.components.OwQrCode +import com.siriusdevops.onionwire.ui.components.OwTopBar import kotlinx.coroutines.launch import uniffi.onionwire_sdk.FriendInfo import uniffi.onionwire_sdk.InviteInfo -@OptIn(ExperimentalMaterial3Api::class) +/** + * Your invite, as a code and as text. + * + * The invite is the one artifact that leaves the device on purpose, so this + * screen is deliberately plain about what it is: one person, one trusted channel, + * nothing published. Both the QR and the text are here because a person pointing + * a camera at a screen and a person pasting into a chat client are different + * people, and neither is wrong. + */ @Composable fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) { var invite by remember { mutableStateOf(null) } @@ -56,18 +73,11 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) { } Scaffold( - topBar = { - TopAppBar( - title = { Text("Your invite") }, - navigationIcon = { IconButton(onClick = onBack) { Text("<") } }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), - ) - }, + topBar = { OwTopBar(title = "Your invite", onBack = onBack) }, // The root applies systemBars + IME itself (see `screenContentInsets`), // so Scaffold must not also pad for the navigation bar. contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, ) { pad -> Column( Modifier @@ -75,70 +85,116 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) { .fillMaxSize() .screenContentInsets() .verticalScroll(rememberScrollState()) - .padding(16.dp), + .padding(horizontal = 16.dp), ) { - Text( - "Hand this to one person, over a channel you already trust. " + - "It is not published anywhere and cannot be looked up.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Not published anywhere", + description = "Hand this to one person over a channel you already " + + "trust. There is no directory and no lookup — that is the point.", ) - Spacer(Modifier.height(12.dp)) + Spacer(Modifier.height(16.dp)) when { - error != null -> Text( - error!!, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, + error != null -> OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Could not read your invite", + description = error, ) - invite == null -> CircularProgressIndicator() + invite == null -> Row( + Modifier.fillMaxWidth().padding(vertical = 32.dp), + horizontalArrangement = Arrangement.Center, + ) { CircularProgressIndicator(color = OwColors.Accent) } else -> { - Card( - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { + val payload = invite!! + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { + OwQrCode(payload = payload, size = 220.dp) + } + Spacer(Modifier.height(16.dp)) + OwCard(Modifier.fillMaxWidth(), padding = 12.dp) { Text( - invite!!, - style = MaterialTheme.typography.bodySmall, - modifier = Modifier.padding(12.dp), + payload, + style = MonoStyle.copy(color = OwColors.TextSecondary), + textAlign = TextAlign.Start, ) } Spacer(Modifier.height(12.dp)) - Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Button(onClick = { - scope.launch { - clipboard.setClipEntry( - ClipEntry(ClipData.newPlainText("onionwire invite", invite!!)), - ) - copied = true - } - }) { Text(if (copied) "Copied" else "Copy") } + Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) { + OwButton( + text = if (copied) "Copied" else "Copy invite", + onClick = { + scope.launch { + val clip = ClipData.newPlainText("onionwire invite", payload) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + clip.description.extras = PersistableBundle().apply { + putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true) + } + } + clipboard.setClipEntry(ClipEntry(clip)) + copied = true + } + }, + leadingIconRes = R.drawable.ic_ow_copy, + ) + OwButton( + text = "Done", + variant = OwButtonVariant.Outline, + onClick = onBack, + ) } - Spacer(Modifier.height(20.dp)) - Text("What is in it", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(6.dp)) - Mono("k ed25519 identity pubkey — who you are") - Mono("o current onion locator — where you are now") - Mono("spk x25519 signed prekey — session start material") - Mono("sig signature over k‖o‖spk — reject if it fails") - Spacer(Modifier.height(12.dp)) - Text( - "The onion in here goes stale when you rotate. The key does not. " + - "If you re-share later, the same k updates their entry — it never " + - "creates a second friend.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + Spacer(Modifier.height(24.dp)) + OwCard(Modifier.fillMaxWidth()) { + Text( + "What is in it", + style = MaterialTheme.typography.titleSmall, + color = OwColors.TextPrimary, + ) + Spacer(Modifier.height(8.dp)) + InviteField("k", "ed25519 identity pubkey — who you are") + InviteField("o", "current onion locator — where you are now") + InviteField("spk", "x25519 signed prekey — session start material") + InviteField("sig", "signature over k‖o‖spk — reject if it fails") + Spacer(Modifier.height(10.dp)) + OwDivider() + Spacer(Modifier.height(10.dp)) + Text( + "The onion in here goes stale when you rotate. The key does " + + "not. If you re-share later, the same k updates their entry — " + + "it never creates a second friend.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + } + Spacer(Modifier.height(24.dp)) } } } } } -@OptIn(ExperimentalMaterial3Api::class) +@Composable +private fun InviteField(key: String, meaning: String) { + Row(Modifier.padding(vertical = 2.dp), verticalAlignment = Alignment.CenterVertically) { + Text( + key, + style = MonoStyle.copy(color = OwColors.Accent), + modifier = Modifier.padding(end = 10.dp), + ) + Label(meaning) + } +} + +/** + * Paste someone else's invite. + * + * Verification is a separate, explicit step from adding: the preview shows who + * they are and where they are reachable *before* anything is written to the + * roster, because a mistyped or swapped invite is the one thing a human can + * still catch. + */ @Composable fun PasteInviteScreen( onDecode: suspend (String) -> InviteInfo, @@ -155,19 +211,12 @@ fun PasteInviteScreen( val adding = flow.adding Scaffold( - topBar = { - TopAppBar( - title = { Text("Add a friend") }, - navigationIcon = { IconButton(onClick = onBack) { Text("<") } }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), - ) - }, + topBar = { OwTopBar(title = "Add contact", onBack = onBack) }, // Same inset handoff as the chat composer: with the keyboard up, the // Verify / Approve buttons under the invite field must still be // reachable by scrolling, not by dismissing the keyboard. contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, ) { pad -> Column( Modifier @@ -175,90 +224,83 @@ fun PasteInviteScreen( .fillMaxSize() .screenContentInsets() .verticalScroll(rememberScrollState()) - .padding(16.dp), + .padding(horizontal = 16.dp), ) { + Spacer(Modifier.height(8.dp)) OutlinedTextField( value = raw, onValueChange = { raw = it flow.clear() }, - label = { Text("onionwire:v1:…") }, + label = { Text("onionwire:v2:…") }, minLines = 4, + shape = RoundedCornerShape(OwRadius.Control), modifier = Modifier.fillMaxWidth(), ) Spacer(Modifier.height(12.dp)) - Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Button( + Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) { + OwButton( + text = "Verify", enabled = raw.isNotBlank() && !verifying && !adding, onClick = { scope.launch { flow.verify(raw) } }, - ) { Text("Verify") } + ) if (added != null) { - TextButton(onClick = onBack) { Text("Done") } + OwButton(text = "Done", variant = OwButtonVariant.Outline, onClick = onBack) } } Spacer(Modifier.height(16.dp)) error?.let { - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - ) - Spacer(Modifier.height(8.dp)) - Text( - "Unsigned or tampered invites are rejected here, before anything is stored.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "That invite was not accepted", + description = "$it — unsigned or tampered invites are rejected " + + "here, before anything is stored.", ) + Spacer(Modifier.height(12.dp)) } preview?.let { p -> - Card( - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - modifier = Modifier.fillMaxWidth(), - ) { - Column(Modifier.padding(12.dp)) { - Label("THEY ARE") - Mono(p.pubkeyHex) - Spacer(Modifier.height(8.dp)) - Text( - "fingerprint ${p.pubkeyHex.take(16)}… — compare this with them " + - "over a second channel before you trust it.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Spacer(Modifier.height(8.dp)) - Label("REACHABLE AT") - Mono(p.onion) - } + OwCard(Modifier.fillMaxWidth()) { + Label("THEY ARE") + Spacer(Modifier.height(2.dp)) + Mono(shortId(p.pubkeyHex, head = 12, tail = 8)) + Spacer(Modifier.height(6.dp)) + Text( + "Compare this fingerprint with them over a second channel " + + "before you trust it.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(10.dp)) + OwDivider() + Spacer(Modifier.height(10.dp)) + Label("REACHABLE AT") + Spacer(Modifier.height(2.dp)) + Mono(shortOnion(p.onion)) } Spacer(Modifier.height(12.dp)) - Button( + OwButton( + text = "Approve & add", enabled = !adding && added == null, onClick = { scope.launch { flow.add(raw) } }, - ) { Text("Approve & add") } + leadingIconRes = R.drawable.ic_ow_add, + ) } added?.let { f -> Spacer(Modifier.height(16.dp)) - Text( - "Added ${f.petname ?: f.fingerprint}", - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.primary, - ) - Spacer(Modifier.height(4.dp)) - Text( - "If that key was already in your roster, only the locator was updated. " + - "One key is always one friend.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Added ${f.petname ?: shortId(f.fingerprint)}", + description = "If that key was already in your roster, only the " + + "locator was updated. One key is always one friend.", ) } + Spacer(Modifier.height(24.dp)) } } } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt index b3b41c3..030f730 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt @@ -33,6 +33,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.components.OwIconButton import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.siriusdevops.onionwire.WireViewModel import kotlinx.coroutines.launch @@ -100,7 +102,11 @@ fun ProfileScreen( TopAppBar( title = { Text("Profile") }, navigationIcon = { - TextButton(onClick = onBack) { Text("Back") } + OwIconButton( + iconRes = R.drawable.ic_ow_chevron_left, + contentDescription = "Back", + onClick = onBack, + ) }, colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.background, diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt index b1575ca..226995a 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt @@ -1,8 +1,14 @@ package com.siriusdevops.onionwire.ui +import android.content.ClipData +import android.content.ClipDescription +import android.os.Build +import android.os.PersistableBundle +import android.widget.Toast import androidx.compose.foundation.background 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.Row import androidx.compose.foundation.layout.Spacer @@ -12,38 +18,70 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.HorizontalDivider +import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.ClipEntry +import androidx.compose.ui.platform.Clipboard +import androidx.compose.ui.platform.LocalClipboard +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.components.Identicon +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwButton +import com.siriusdevops.onionwire.ui.components.OwButtonRow +import com.siriusdevops.onionwire.ui.components.OwButtonVariant +import com.siriusdevops.onionwire.ui.components.OwCard +import com.siriusdevops.onionwire.ui.components.OwConfirmDialog +import com.siriusdevops.onionwire.ui.components.OwDivider +import com.siriusdevops.onionwire.ui.components.OwIcon +import com.siriusdevops.onionwire.ui.components.OwIconButton +import com.siriusdevops.onionwire.ui.components.OwOverflowMenu +import com.siriusdevops.onionwire.ui.components.OwStatusDot +import com.siriusdevops.onionwire.ui.components.OwTopBar +import com.siriusdevops.onionwire.ui.components.TorStatusPill +import kotlinx.coroutines.launch import uniffi.onionwire_sdk.FriendInfo -@OptIn(ExperimentalMaterial3Api::class) +/** + * Home: your identity, and the roster. + * + * Three things changed from the alpha build and they are deliberate: + * + * - The identity block is one compact bar. The `YOU (stable forever)` card, the + * `sdk … · identity = ed25519 pubkey` line and the keep-alive paragraph are + * gone from here — the SDK line is on Node & Settings, and the keep-alive + * state is a status row there too. A home screen does not explain the + * transport before it shows the people. + * - The five text-link actions are gone. Invite and Add are the two first-class + * actions (in the empty state, and in the bar); the rare and destructive ones + * live behind `⋮`. + * - The empty state says what to do next, with the two buttons that do it. + * + * Behaviour is unchanged: `invite`, `onPaste`, `onOpenChat`, `onRotate`, + * `onWipe` and `onLock` are the same ViewModel calls the old screen made. + */ @Composable fun RosterScreen( fingerprint: String, - onion: String, - sdkVersion: String, friends: List, - keepAliveNote: String?, + invite: suspend () -> String, onOpenChat: (FriendInfo) -> Unit, onShare: () -> Unit, onPaste: () -> Unit, @@ -51,245 +89,288 @@ fun RosterScreen( onWipe: () -> Unit, onOpenProfile: () -> Unit, onLock: () -> Unit, - onOpenWallet: () -> Unit, + onOpenWallets: () -> Unit, ) { - var confirmWipe by remember { mutableStateOf(false) } - // Closed by default; `rememberSaveable` so a rotation keeps whatever the - // user chose instead of snapping back to (or away from) the summary. - // Nothing about this is worth persisting to the store. - var identityExpanded by rememberSaveable { mutableStateOf(false) } + val context = LocalContext.current + val clipboard = LocalClipboard.current + val scope = rememberCoroutineScope() + var confirmDeleteAll by remember { mutableStateOf(false) } Scaffold( // The content root below consumes systemBars ∪ ime itself (see - // `screenContentInsets`); zeroing the Scaffold's own insets keeps the - // navigation bar from being applied twice and lets the wipe-confirm - // strip sit above the keyboard instead of under it. + // `screenContentInsets`), and the tab bar above this screen consumes the + // navigation-bar inset; zeroing the Scaffold's own insets is what keeps + // the list from being padded twice. contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, topBar = { - TopAppBar( - title = { Text("OnionWire") }, + OwTopBar( + title = "OnionWire", + status = { TorStatusPill() }, actions = { - TextButton(onClick = onOpenProfile) { Text("Profile") } - TextButton(onClick = onLock) { Text("Lock") } + OwIconButton( + iconRes = R.drawable.ic_ow_lock, + contentDescription = "Lock and stop the node", + onClick = onLock, + ) + OwOverflowMenu( + onOpenProfile = onOpenProfile, + onOpenWallets = onOpenWallets, + onRotate = onRotate, + onWipe = { confirmDeleteAll = true }, + ) }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), ) }, ) { pad -> Column(Modifier.padding(pad).fillMaxSize().screenContentInsets()) { - - Card( - modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column(Modifier.padding(12.dp)) { - // The disclosure header. Collapsed, this one line *is* the - // identity block: the label, the abbreviated fingerprint, - // and a chevron saying there is more behind it. - Row( - modifier = Modifier - .fillMaxWidth() - .clickable { identityExpanded = !identityExpanded }, - verticalAlignment = Alignment.CenterVertically, - ) { - Label("YOU (stable forever)") - if (!identityExpanded) { - Spacer(Modifier.width(8.dp)) - Mono(shortId(fingerprint)) - } - Spacer(Modifier.weight(1f)) - Text( - if (identityExpanded) "▾" else "▸", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + IdentityBar( + fingerprint = fingerprint, + onCopyInvite = { + scope.launch { + runCatching { invite() } + .onSuccess { payload -> + copyInvite(clipboard, payload) + Toast.makeText(context, "Invite address copied", Toast.LENGTH_SHORT).show() + } + .onFailure { + Toast.makeText(context, "Could not read the invite", Toast.LENGTH_SHORT).show() + } } - if (identityExpanded) { - Mono(fingerprint) - Spacer(Modifier.height(10.dp)) - Label("ONION (locator — rotates)") - Mono(onion) - } - Spacer(Modifier.height(10.dp)) - Text( - "sdk $sdkVersion · identity = ed25519 pubkey", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - if (keepAliveNote != null) { - Spacer(Modifier.height(10.dp)) - Text( - keepAliveNote, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.primary, - ) - } - } - } + }, + onShare = onShare, + ) - Spacer(Modifier.height(8.dp)) - Row( - modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), - horizontalArrangement = Arrangement.SpaceEvenly, - ) { - TextButton(onClick = onShare) { Text("Invite") } - TextButton(onClick = onPaste) { Text("Add") } - TextButton(onClick = onRotate) { Text("Rotate") } - TextButton(onClick = onOpenWallet) { Text("Wallet") } - TextButton(onClick = { confirmWipe = true }) { Text("Wipe chat") } - } - - if (confirmWipe) { - ConfirmStrip( - text = "Delete every message body? Identity and friends stay.", - confirm = "WIPE", - onConfirm = { confirmWipe = false; onWipe() }, - onCancel = { confirmWipe = false }, - ) - } - - HorizontalDivider(Modifier.padding(vertical = 8.dp)) + Spacer(Modifier.height(12.dp)) if (friends.isEmpty()) { - Column( - Modifier.fillMaxSize().padding(24.dp), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally, - ) { - Text("No friends yet", style = MaterialTheme.typography.titleMedium) - Spacer(Modifier.height(8.dp)) - Text( - "Share your invite over a channel you already trust, or paste " + - "someone else's. Invites are not discoverable — nothing is published.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } + EmptyRoster( + modifier = Modifier.weight(1f), + onPaste = onPaste, + onShare = onShare, + ) } else { - // weight(1f), not fillMaxSize(): the list must yield height to - // its siblings (the action row and the wipe-confirm strip above - // it) when the IME shrinks the window, instead of claiming all - // of it and pushing them off the bottom. LazyColumn(Modifier.weight(1f).fillMaxWidth()) { items(friends, key = { it.pubkeyHex }) { f -> FriendRow(f) { onOpenChat(f) } - HorizontalDivider() + OwDivider(Modifier.padding(horizontal = 16.dp)) } } } } } + + if (confirmDeleteAll) { + OwConfirmDialog( + title = "Delete all message history?", + body = "Every message body on this device is deleted. Your identity, " + + "your friends and the pending queue are untouched.", + confirmationWord = "DELETE", + confirmLabel = "Delete history", + destructive = true, + onConfirm = { + confirmDeleteAll = false + onWipe() + }, + onDismiss = { confirmDeleteAll = false }, + ) + } +} + +/** + * Your identity, as one bar: identicon, label, truncated pubkey, then the two + * actions a person actually performs here — copy the invite, show it as a code. + */ +@Composable +private fun IdentityBar( + fingerprint: String, + onCopyInvite: () -> Unit, + onShare: () -> Unit, +) { + OwCard( + modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp), + padding = 12.dp, + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + Identicon(seed = fingerprint, size = 40.dp) + Spacer(Modifier.width(12.dp)) + Column(Modifier.weight(1f)) { + Label("Your identity") + Spacer(Modifier.height(2.dp)) + Mono(shortId(fingerprint)) + } + OwIconButton( + iconRes = R.drawable.ic_ow_copy, + contentDescription = "Copy invite address", + onClick = onCopyInvite, + ) + Spacer(Modifier.width(8.dp)) + OwIconButton( + iconRes = R.drawable.ic_ow_qr, + contentDescription = "Show your invite", + onClick = onShare, + ) + } + } +} + +/** + * The empty roster. + * + * The honest sentence stays: invites are not discoverable, nothing is published. + * The two buttons are the two ways out of this state, in the order that helps — + * paste a peer's invite, or hand yours out. + */ +@Composable +private fun EmptyRoster( + modifier: Modifier = Modifier, + onPaste: () -> Unit, + onShare: () -> Unit, +) { + Column( + modifier = modifier.fillMaxWidth().padding(horizontal = 24.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + Modifier + .width(64.dp) + .height(64.dp) + .clip(CircleShape) + .background(OwColors.Surface), + contentAlignment = Alignment.Center, + ) { + OwIcon( + iconRes = R.drawable.ic_ow_shield, + contentDescription = null, + tint = OwColors.Accent, + size = 30.dp, + ) + } + Spacer(Modifier.height(16.dp)) + Text( + "No contacts yet", + style = MaterialTheme.typography.titleMedium, + color = OwColors.TextPrimary, + ) + Spacer(Modifier.height(8.dp)) + Text( + "Share your invite over a channel you already trust, or paste a peer's " + + "invite to start an end-to-end encrypted chat. Invites are not " + + "discoverable — nothing is published.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + textAlign = TextAlign.Center, + modifier = Modifier.widthIn(max = 280.dp), + ) + Spacer(Modifier.height(20.dp)) + OwButtonRow(Modifier.widthIn(max = 320.dp)) { + OwButton( + text = "Add contact", + onClick = onPaste, + variant = OwButtonVariant.Primary, + modifier = Modifier.weight(1f), + leadingIconRes = R.drawable.ic_ow_add, + ) + OwButton( + text = "Share my invite", + onClick = onShare, + variant = OwButtonVariant.Secondary, + modifier = Modifier.weight(1f), + ) + } + } } @Composable private fun FriendRow(f: FriendInfo, onClick: () -> Unit) { - Column( + Row( Modifier .fillMaxWidth() .clickable(onClick = onClick) - .background(MaterialTheme.colorScheme.background) .padding(horizontal = 16.dp, vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically, ) { - Row(verticalAlignment = Alignment.CenterVertically) { - Text( - f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint, - style = MaterialTheme.typography.titleSmall, - ) - if (!f.lastConnectOk) { - Spacer(Modifier.height(0.dp)) + Column(Modifier.weight(1f)) { + Row(verticalAlignment = Alignment.CenterVertically) { Text( - " locator stale", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.error, + f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint, + style = MaterialTheme.typography.titleSmall, + color = OwColors.TextPrimary, ) + if (!f.lastConnectOk) { + Spacer(Modifier.width(8.dp)) + OwStatusDot(OwColors.Warning) + Spacer(Modifier.width(6.dp)) + Text( + "locator stale", + style = MaterialTheme.typography.labelSmall, + color = OwColors.Warning, + ) + } } + Spacer(Modifier.height(3.dp)) + Text( + shortId(f.fingerprint), + style = MonoStyle, + color = OwColors.TextSecondary, + ) + Text( + shortOnion(f.onion), + style = MonoStyle.copy(color = OwColors.TextMuted), + ) } - Spacer(Modifier.height(2.dp)) - Text( - f.fingerprint, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.primary, - ) - Text( - f.onion, - style = MaterialTheme.typography.labelSmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + Text("›", style = MaterialTheme.typography.titleMedium, color = OwColors.TextMuted) } } +/** + * Clipboard handling for the invite. + * + * The invite is a locator plus a prekey: it is a secret-ish string that opens a + * conversation with you, so the clip is marked sensitive (API 33+) — it will not + * be previewed on the lock screen or indexed by the clipboard UI. Nothing here + * is logged, persisted, or drawn anywhere but the share sheet. + */ +private suspend fun copyInvite(clipboard: Clipboard, text: String) { + val clip = ClipData.newPlainText("onionwire invite", text) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + clip.description.extras = PersistableBundle().apply { + putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true) + } + } + clipboard.setClipEntry(ClipEntry(clip)) +} + /** * The compact stand-in for a long identity string: `head` characters, an - * ellipsis, then `tail` characters. Pure, so the roster's collapsed line and - * its unit test agree on what "short" means. + * ellipsis, then `tail` characters. Pure, so the roster's line and its unit test + * agree on what "short" means. * * A string no longer than the abbreviation is returned unchanged — the * abbreviation must never grow a value, and a short value must never come back - * mangled. Kotlin strings are UTF-16, but these IDs are hex, so `take`/ - * `takeLast` cannot split a surrogate pair here. + * mangled. Kotlin strings are UTF-16, but these IDs are hex, so `take`/`takeLast` + * cannot split a surrogate pair here. */ fun shortId(id: String, head: Int = 6, tail: Int = 4): String { if (id.length < head + tail + 1) return id return id.take(head) + "…" + id.takeLast(tail) } -@Composable -fun Label(text: String) { - Text( - text, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) -} - -@Composable -fun Mono(text: String) { - Text( - text, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.onSurface, - ) -} - -@Composable -fun ConfirmStrip( - text: String, - confirm: String, - onConfirm: () -> Unit, - onCancel: () -> Unit, -) { - var typed by remember { mutableStateOf("") } - Card( - modifier = Modifier.fillMaxWidth().padding(12.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column(Modifier.padding(12.dp)) { - Text(text, style = MaterialTheme.typography.bodySmall) - Spacer(Modifier.height(8.dp)) - androidx.compose.material3.OutlinedTextField( - value = typed, - onValueChange = { typed = it }, - singleLine = true, - label = { Text("Type $confirm") }, - modifier = Modifier.fillMaxWidth(), - ) - Spacer(Modifier.height(8.dp)) - Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) { - TextButton(onClick = onCancel) { Text("Cancel") } - TextButton( - onClick = onConfirm, - enabled = typed.trim().equals(confirm, ignoreCase = true), - ) { Text("Confirm") } - } - } - } +/** + * A v3 onion locator shortened for a roster row, with the `.onion` suffix kept + * visible: `abcdefghij…uvwxyz.onion`. + * + * The suffix is the part that tells a reader this is an onion address at all, so + * it is never the part that gets truncated. The full value lives on the profile + * and invite screens, and a v3 locator is never soft-wrapped — a wrapped address + * cannot be copied reliably. + */ +fun shortOnion(onion: String, head: Int = 10, tail: Int = 6): String { + val suffix = ".onion" + if (onion.isEmpty()) return onion + if (!onion.endsWith(suffix)) return onion + val body = onion.removeSuffix(suffix) + if (body.length <= head + tail + 1) return onion + return body.take(head) + "…" + body.takeLast(tail) + suffix } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RotateScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RotateScreen.kt index b1f99b5..89f351e 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RotateScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RotateScreen.kt @@ -29,6 +29,10 @@ 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.R +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwIconButton /** * Rotating publishes a brand new onion service and hard-cuts the old one. @@ -54,7 +58,13 @@ fun RotateScreen( topBar = { TopAppBar( title = { Text("Rotate onion") }, - navigationIcon = { IconButton(onClick = onBack) { Text("<") } }, + navigationIcon = { + OwIconButton( + iconRes = R.drawable.ic_ow_chevron_left, + contentDescription = "Back", + onClick = onBack, + ) + }, colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.background, ), diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt new file mode 100644 index 0000000..a9ec625 --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt @@ -0,0 +1,215 @@ +package com.siriusdevops.onionwire.ui + +import androidx.compose.foundation.clickable +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.WindowInsets +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +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.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwCard +import com.siriusdevops.onionwire.ui.components.OwConfirmDialog +import com.siriusdevops.onionwire.ui.components.OwDivider +import com.siriusdevops.onionwire.ui.components.OwIconButton +import com.siriusdevops.onionwire.ui.components.OwSectionTitle +import com.siriusdevops.onionwire.ui.components.OwTopBar +import com.siriusdevops.onionwire.ui.components.TorStatusPill + +/** + * The third tab: everything that is not a conversation or a balance. + * + * This is where the alpha build's honest-but-noisy bits went — the SDK line, the + * keep-alive paragraph, the identity rotation and the history wipe. They are not + * hidden; they are one tap away instead of on the screen a person opens twenty + * times a day. No behaviour lives here: every callback is a ViewModel call the + * old roster made. + */ +@Composable +fun SettingsScreen( + sdkVersion: String, + keepAliveNote: String?, + onOpenProfile: () -> Unit, + onOpenWallets: () -> Unit, + onRotate: () -> Unit, + onWipe: () -> Unit, + onLock: () -> Unit, +) { + var confirmDeleteAll by remember { mutableStateOf(false) } + + Scaffold( + contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, + topBar = { + OwTopBar( + title = "Node & Settings", + status = { TorStatusPill() }, + actions = { + OwIconButton( + iconRes = R.drawable.ic_ow_lock, + contentDescription = "Lock and stop the node", + onClick = onLock, + ) + }, + ) + }, + ) { pad -> + Column( + Modifier + .padding(pad) + .fillMaxSize() + .screenContentInsets() + .verticalScroll(rememberScrollState()) + .padding(horizontal = 16.dp), + ) { + Spacer(Modifier.height(8.dp)) + + OwCard(Modifier.fillMaxWidth()) { + Label("ACCOUNT") + Spacer(Modifier.height(4.dp)) + SettingsRow( + title = "Your profile", + subtitle = "Name, bio and Monero address", + onClick = onOpenProfile, + ) + OwDivider() + SettingsRow( + title = "Saved wallets", + subtitle = "Open a wallet file, or check its backup", + onClick = onOpenWallets, + ) + } + + Spacer(Modifier.height(12.dp)) + + OwCard(Modifier.fillMaxWidth()) { + Label("REACHABILITY") + Spacer(Modifier.height(6.dp)) + Text( + keepAliveNote ?: "Checking how this app is kept reachable…", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + } + + Spacer(Modifier.height(12.dp)) + + OwCard(Modifier.fillMaxWidth()) { + Label("SECURITY & DATA") + Spacer(Modifier.height(4.dp)) + SettingsRow( + title = "Rotate identity", + subtitle = "New onion address. Offline contacts must re-scan your invite.", + onClick = onRotate, + ) + OwDivider() + SettingsRow( + title = "Delete message history", + subtitle = "Removes every message body on this device. Identity and contacts stay.", + danger = true, + onClick = { confirmDeleteAll = true }, + ) + } + + Spacer(Modifier.height(12.dp)) + + OwCard(Modifier.fillMaxWidth()) { + OwSectionTitle("About") + Spacer(Modifier.height(6.dp)) + Text( + "identity = ed25519 pubkey", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(4.dp)) + Row(verticalAlignment = Alignment.CenterVertically) { + Label("SDK") + Spacer(Modifier.width(8.dp)) + Mono(sdkVersion) + } + Spacer(Modifier.height(10.dp)) + Text( + "Tor and the chain node run in-process. The wallet is an RPC the app " + + "owns and starts itself.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + } + + Spacer(Modifier.height(24.dp)) + } + } + + if (confirmDeleteAll) { + OwConfirmDialog( + title = "Delete all message history?", + body = "Every message body on this device is deleted. Your identity, " + + "your friends and the pending queue are untouched.", + confirmationWord = "DELETE", + confirmLabel = "Delete history", + destructive = true, + onConfirm = { + confirmDeleteAll = false + onWipe() + }, + onDismiss = { confirmDeleteAll = false }, + ) + } +} + +@Composable +private fun SettingsRow( + title: String, + subtitle: String, + onClick: () -> Unit, + danger: Boolean = false, +) { + Row( + Modifier + .fillMaxWidth() + .clickable(onClick = onClick) + .padding(vertical = 12.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Column(Modifier.weight(1f)) { + Text( + title, + style = MaterialTheme.typography.titleSmall, + color = if (danger) OwColors.Danger else OwColors.TextPrimary, + ) + Spacer(Modifier.height(2.dp)) + Text( + subtitle, + style = MaterialTheme.typography.bodySmall, + color = if (danger) Color(0xCCFF5C5C) else OwColors.TextSecondary, + ) + } + Spacer(Modifier.width(12.dp)) + Text( + "›", + style = MaterialTheme.typography.titleMedium, + color = if (danger) OwColors.Danger else OwColors.TextMuted, + ) + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AppTopBar.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AppTopBar.kt new file mode 100644 index 0000000..3c3e1c7 --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/AppTopBar.kt @@ -0,0 +1,79 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +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.statusBarsPadding +import androidx.compose.foundation.layout.width +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.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.siriusdevops.onionwire.R +import com.siriusdevops.onionwire.ui.OwColors + +/** + * The app's one top bar. + * + * Deliberately not `TopAppBar`: that component is a fixed height single line, and + * this header carries a second row (the `● Tor active` pill). A custom column + * also keeps the status-bar inset inside the bar's own background instead of + * padding the screen underneath it. + * + * On a sub-screen the navigation slot is a chevron icon button, never the word + * "Back". + */ +@Composable +fun OwTopBar( + title: String, + modifier: Modifier = Modifier, + onBack: (() -> Unit)? = null, + status: (@Composable () -> Unit)? = null, + actions: @Composable RowScope.() -> Unit = {}, +) { + Column( + modifier = modifier + .fillMaxWidth() + .background(OwColors.Canvas) + .statusBarsPadding() + .padding(start = 16.dp, end = 16.dp, top = 10.dp, bottom = 10.dp), + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + if (onBack != null) { + OwIconButton( + iconRes = R.drawable.ic_ow_chevron_left, + contentDescription = "Back", + onClick = onBack, + tint = OwColors.TextPrimary, + background = OwColors.SurfaceInteractive, + ) + Spacer(Modifier.width(12.dp)) + } + Text( + title, + style = MaterialTheme.typography.titleLarge, + fontWeight = FontWeight.Bold, + color = OwColors.TextPrimary, + modifier = Modifier.weight(1f), + ) + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically, + content = actions, + ) + } + if (status != null) { + Spacer(Modifier.height(8.dp)) + status() + } + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt new file mode 100644 index 0000000..60444e6 --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt @@ -0,0 +1,125 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.background +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.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +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.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.R +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwSize + +/** + * The three top-level destinations. + * + * Chats is home. The node lives inside Wallet (that is where its card already + * is), so the third tab is the security/settings surface: identity, saved + * wallets, rotation, wipe, and — behind progressive disclosure — the SDK line + * that used to sit under the roster. + */ +enum class OwTab(val label: String, @DrawableRes val icon: Int) { + Chats("Chats", R.drawable.ic_ow_chat), + Wallet("Wallet", R.drawable.ic_ow_wallet), + Settings("Node & Settings", R.drawable.ic_ow_sliders), +} + +/** + * Persistent bottom navigation. + * + * 64dp of canvas with a single 1dp top border — no elevation shadow, no + * translucent scrim. The navigation-bar inset is applied here, so screens inside + * the shell must not also pad for it (see `LocalBottomBarPresent`). + */ +@Composable +fun OwBottomTabBar( + selected: OwTab, + onSelect: (OwTab) -> Unit, + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier + .fillMaxWidth() + .background(OwColors.Canvas), + ) { + OwDivider() + Row( + modifier = Modifier + .fillMaxWidth() + .navigationBarsPadding() + .height(OwSize.TabBar), + horizontalArrangement = Arrangement.SpaceEvenly, + verticalAlignment = Alignment.CenterVertically, + ) { + OwTab.entries.forEach { tab -> + TabItem( + tab = tab, + selected = tab == selected, + onClick = { onSelect(tab) }, + modifier = Modifier.weight(1f), + ) + } + } + } +} + +@Composable +private fun TabItem( + tab: OwTab, + selected: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, +) { + val tint: Color = if (selected) OwColors.Accent else OwColors.TextMuted + Column( + modifier = modifier + .fillMaxWidth() + .clickable(onClick = onClick) + .semantics { + role = Role.Tab + this.selected = selected + } + .padding(vertical = 8.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + Box(contentAlignment = Alignment.Center) { + Icon( + painter = painterResource(tab.icon), + contentDescription = null, + tint = tint, + modifier = Modifier.size(22.dp), + ) + } + Spacer(Modifier.height(4.dp)) + Text( + tab.label, + style = MaterialTheme.typography.labelSmall, + fontSize = 10.sp, + fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Medium, + color = tint, + ) + } +} diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/OverflowMenu.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/OverflowMenu.kt new file mode 100644 index 0000000..f467049 --- /dev/null +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/OverflowMenu.kt @@ -0,0 +1,69 @@ +package com.siriusdevops.onionwire.ui.components + +import androidx.compose.foundation.layout.Box +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.Text +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.R +import com.siriusdevops.onionwire.ui.OwColors +import com.siriusdevops.onionwire.ui.OwRadius + +/** + * The `⋮` overflow on the messenger and settings bars. + * + * Serious and rare actions live here instead of on the home screen: rotating the + * identity cuts every offline friend off the current locator, and deleting the + * message history is irreversible. Neither belongs next to "Invite". + * + * The menu is a component rather than inline code so the destructive verbs have + * exactly one home — a new screen that wants the overflow gets the same list, + * not a second copy with different wording. + */ +@Composable +fun OwOverflowMenu( + onOpenProfile: () -> Unit, + onOpenWallets: () -> Unit, + onRotate: () -> Unit, + onWipe: () -> Unit, + modifier: Modifier = Modifier, +) { + var open by remember { mutableStateOf(false) } + + Box(modifier) { + OwIconButton( + iconRes = R.drawable.ic_ow_more_vert, + contentDescription = "More actions", + onClick = { open = true }, + ) + DropdownMenu( + expanded = open, + onDismissRequest = { open = false }, + containerColor = OwColors.SurfaceInteractive, + shape = androidx.compose.foundation.shape.RoundedCornerShape(OwRadius.Control), + ) { + DropdownMenuItem( + text = { Text("Your profile", color = OwColors.TextPrimary) }, + onClick = { open = false; onOpenProfile() }, + ) + DropdownMenuItem( + text = { Text("Saved wallets", color = OwColors.TextPrimary) }, + onClick = { open = false; onOpenWallets() }, + ) + DropdownMenuItem( + text = { Text("Rotate identity", color = OwColors.TextPrimary) }, + onClick = { open = false; onRotate() }, + ) + DropdownMenuItem( + text = { Text("Delete message history", color = OwColors.Danger) }, + onClick = { open = false; onWipe() }, + ) + } + } +} diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/RosterOnionTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/RosterOnionTest.kt new file mode 100644 index 0000000..0fa45bf --- /dev/null +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/RosterOnionTest.kt @@ -0,0 +1,45 @@ +package com.siriusdevops.onionwire.ui + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * `shortOnion`, the roster's locator abbreviation, on the JVM. + * + * A v3 onion locator must never be soft-wrapped or reduced to a middle slice + * that hides `.onion`: the suffix is what tells a reader this is an onion + * address at all, and the full value is available on the profile and invite + * screens. Pure logic, no Robolectric — same shape as `RosterIdTest`. + */ +class RosterOnionTest { + + private val v3 = + "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwxyz234567.onion" + + @Test + fun a_v3_locator_keeps_its_suffix() { + val short = shortOnion(v3) + assertEquals(true, short.endsWith(".onion")) + assertEquals(v3.take(10), short.substringBefore("\u2026")) + assertEquals(v3.removeSuffix(".onion").takeLast(6), short.removeSuffix(".onion").substringAfter("\u2026")) + } + + @Test + fun the_suffix_is_never_the_part_that_is_cut() { + // Even with an aggressive abbreviation the reader still sees `….onion`. + val body = v3.removeSuffix(".onion") + val short = shortOnion(v3, head = 3, tail = 2) + assertEquals(body.take(3) + "\u2026" + body.takeLast(2) + ".onion", short) + } + + @Test + fun a_short_value_is_returned_unchanged() { + assertEquals("abc.onion", shortOnion("abc.onion")) + assertEquals("", shortOnion("")) + } + + @Test + fun a_value_with_no_suffix_is_not_mangled() { + assertEquals("not-an-onion", shortOnion("not-an-onion")) + } +} From b65c9900144cb4ede3afe261b05743f7797ac136 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 00:05:17 -0400 Subject: [PATCH 3/4] ui: cap the invite payload card and shorten the settings tab label Two things the emulator run surfaced: - The invite payload is about a kilobyte, so the plain Text card grew past the screen and pushed Copy invite / Done below the fold on a phone. Four lines with an ellipsis: the copy button carries the whole string, and the QR is the primary path anyway. - "Node & Settings" as a 10sp label in a third of the bottom bar is one OEM font scale away from wrapping. The tab says "Settings"; the destination screen keeps its "Node & Settings" title. --- .../java/com/siriusdevops/onionwire/ui/InviteScreens.kt | 8 ++++++++ .../siriusdevops/onionwire/ui/components/BottomTabBar.kt | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt index 599e6a4..a519bb7 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/InviteScreens.kt @@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ClipEntry import androidx.compose.ui.platform.LocalClipboard import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.siriusdevops.onionwire.R import com.siriusdevops.onionwire.ui.components.Label @@ -114,11 +115,18 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) { OwQrCode(payload = payload, size = 220.dp) } Spacer(Modifier.height(16.dp)) + // Four lines, ellipsised: the payload is ~1 KB, and a card + // that grows to fill the screen pushes Copy and Done out of + // reach — the copyable text is a fallback for the QR, not + // the main event. `Copy invite` always carries the whole + // string. OwCard(Modifier.fillMaxWidth(), padding = 12.dp) { Text( payload, style = MonoStyle.copy(color = OwColors.TextSecondary), textAlign = TextAlign.Start, + maxLines = 4, + overflow = TextOverflow.Ellipsis, ) } Spacer(Modifier.height(12.dp)) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt index 60444e6..61ebdfd 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/BottomTabBar.kt @@ -43,7 +43,9 @@ import com.siriusdevops.onionwire.ui.OwSize enum class OwTab(val label: String, @DrawableRes val icon: Int) { Chats("Chats", R.drawable.ic_ow_chat), Wallet("Wallet", R.drawable.ic_ow_wallet), - Settings("Node & Settings", R.drawable.ic_ow_sliders), + // Tab labels stay short: the destination is Node & Settings (that is the + // screen title), but a 10sp label in a third of the bar has no room for it. + Settings("Settings", R.drawable.ic_ow_sliders), } /** From a7b7792b3faf56dda0700385494a63d97f9c310d Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 00:06:07 -0400 Subject: [PATCH 4/4] ui: About rows, and drop the removed copy from the roster's own KDoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SDK/key-type footnote moved to Node and Settings, so it should not survive as a quoted string in ui/ either — the About card now shows IDENTITY ed25519 and SDK as label plus mono value, which is the design system's idiom for a machine fact. Same reasoning for the KDoc: it describes the change instead of pasting the strings that were removed. --- .../siriusdevops/onionwire/ui/RosterScreen.kt | 16 ++++++++-------- .../siriusdevops/onionwire/ui/SettingsScreen.kt | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt index 226995a..d50b69f 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt @@ -64,18 +64,18 @@ import uniffi.onionwire_sdk.FriendInfo * * Three things changed from the alpha build and they are deliberate: * - * - The identity block is one compact bar. The `YOU (stable forever)` card, the - * `sdk … · identity = ed25519 pubkey` line and the keep-alive paragraph are - * gone from here — the SDK line is on Node & Settings, and the keep-alive - * state is a status row there too. A home screen does not explain the - * transport before it shows the people. + * - The identity block is one compact bar. The old expandable card, the version + * and key-type footnote and the keep-alive paragraph are gone from here: the + * technical lines moved to Node & Settings, and reachability is a status row + * there too. A home screen does not explain the transport before it shows the + * people. * - The five text-link actions are gone. Invite and Add are the two first-class * actions (in the empty state, and in the bar); the rare and destructive ones - * live behind `⋮`. + * live behind the overflow menu. * - The empty state says what to do next, with the two buttons that do it. * - * Behaviour is unchanged: `invite`, `onPaste`, `onOpenChat`, `onRotate`, - * `onWipe` and `onLock` are the same ViewModel calls the old screen made. + * Behaviour is unchanged: every callback here is the ViewModel call the old + * screen made — this screen only decides where the entry points sit. */ @Composable fun RosterScreen( diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt index a9ec625..c5e5c68 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/SettingsScreen.kt @@ -135,16 +135,16 @@ fun SettingsScreen( OwCard(Modifier.fillMaxWidth()) { OwSectionTitle("About") - Spacer(Modifier.height(6.dp)) - Text( - "identity = ed25519 pubkey", - style = MaterialTheme.typography.bodySmall, - color = OwColors.TextSecondary, - ) + Spacer(Modifier.height(8.dp)) + Row(verticalAlignment = Alignment.CenterVertically) { + Label("IDENTITY") + Spacer(Modifier.width(10.dp)) + Mono("ed25519") + } Spacer(Modifier.height(4.dp)) Row(verticalAlignment = Alignment.CenterVertically) { Label("SDK") - Spacer(Modifier.width(8.dp)) + Spacer(Modifier.width(10.dp)) Mono(sdkVersion) } Spacer(Modifier.height(10.dp))