ui: design tokens and the shared component set (plan P1)
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.
This commit is contained in:
parent
4e8342b2d8
commit
5f2a6a184f
22 changed files with 1167 additions and 20 deletions
|
|
@ -1,34 +1,149 @@
|
||||||
package com.siriusdevops.onionwire.ui
|
package com.siriusdevops.onionwire.ui
|
||||||
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.Color
|
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)
|
* OnionWire design tokens.
|
||||||
private val DeepVoid = Color(0xFF0B0B10)
|
*
|
||||||
private val PanelVoid = Color(0xFF15151C)
|
* 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(
|
private val OnionWireColors = darkColorScheme(
|
||||||
primary = WireCyan,
|
primary = OwColors.Accent,
|
||||||
onPrimary = DeepVoid,
|
onPrimary = OwColors.Canvas,
|
||||||
primaryContainer = OnionViolet,
|
primaryContainer = OwColors.SurfaceInteractive,
|
||||||
onPrimaryContainer = Color.White,
|
onPrimaryContainer = OwColors.TextPrimary,
|
||||||
secondary = OnionViolet,
|
secondary = OwColors.SurfaceInteractive,
|
||||||
onSecondary = Color.White,
|
onSecondary = OwColors.TextPrimary,
|
||||||
background = DeepVoid,
|
tertiary = OwColors.TextSecondary,
|
||||||
onBackground = Color(0xFFE6E6F0),
|
onTertiary = OwColors.Canvas,
|
||||||
surface = DeepVoid,
|
background = OwColors.Canvas,
|
||||||
onSurface = Color(0xFFE6E6F0),
|
onBackground = OwColors.TextPrimary,
|
||||||
surfaceVariant = PanelVoid,
|
surface = OwColors.Canvas,
|
||||||
onSurfaceVariant = Color(0xFFB9B9CC),
|
onSurface = OwColors.TextPrimary,
|
||||||
outline = Color(0xFF3A3A4A),
|
surfaceVariant = OwColors.Surface,
|
||||||
error = Color(0xFFFF6B6B),
|
onSurfaceVariant = OwColors.TextSecondary,
|
||||||
onError = DeepVoid,
|
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
|
@Composable
|
||||||
fun OnionWireTheme(content: @Composable () -> Unit) {
|
fun OnionWireTheme(content: @Composable () -> Unit) {
|
||||||
MaterialTheme(colorScheme = OnionWireColors, content = content)
|
MaterialTheme(
|
||||||
|
colorScheme = OnionWireColors,
|
||||||
|
typography = OnionWireTypography,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<String>,
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<Triple<Int, Int, Int>> {
|
||||||
|
if (seed.isEmpty()) return emptyList()
|
||||||
|
val bytes = seed.map { it.code }.toIntArray()
|
||||||
|
var i = 0
|
||||||
|
val out = mutableListOf<Triple<Int, Int, Int>>()
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
11
android/app/src/main/res/drawable/ic_ow_add.xml
Normal file
11
android/app/src/main/res/drawable/ic_ow_add.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M10.8,4 H13.2 V10.8 H20 V13.2 H13.2 V20 H10.8 V13.2 H4 V10.8 H10.8 Z" />
|
||||||
|
</vector>
|
||||||
11
android/app/src/main/res/drawable/ic_ow_chat.xml
Normal file
11
android/app/src/main/res/drawable/ic_ow_chat.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M4,3 H20 A3,3 0 0 1 23,6 V15 A3,3 0 0 1 20,18 H12 L7,22 V18 H4 A3,3 0 0 1 1,15 V6 A3,3 0 0 1 4,3 Z" />
|
||||||
|
</vector>
|
||||||
15
android/app/src/main/res/drawable/ic_ow_chevron_left.xml
Normal file
15
android/app/src/main/res/drawable/ic_ow_chevron_left.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="2"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:pathData="M14.5,4.5 L7.5,12 L14.5,19.5" />
|
||||||
|
</vector>
|
||||||
18
android/app/src/main/res/drawable/ic_ow_copy.xml
Normal file
18
android/app/src/main/res/drawable/ic_ow_copy.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M9,8 H18 A2,2 0 0 1 20,10 V20 A2,2 0 0 1 18,22 H9 A2,2 0 0 1 7,20 V10 A2,2 0 0 1 9,8 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M4,16 H3 A1,1 0 0 1 2,15 V4 A1,1 0 0 1 3,3 H14 A1,1 0 0 1 15,4 V5" />
|
||||||
|
</vector>
|
||||||
16
android/app/src/main/res/drawable/ic_ow_info.xml
Normal file
16
android/app/src/main/res/drawable/ic_ow_info.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M12,2 A10,10 0 1 1 11.99,2 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M11,10 H13 V17.5 H11 Z M11,6 H13 V8.5 H11 Z" />
|
||||||
|
</vector>
|
||||||
16
android/app/src/main/res/drawable/ic_ow_lock.xml
Normal file
16
android/app/src/main/res/drawable/ic_ow_lock.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M7,10 V7 A5,5 0 0 1 17,7 V10" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M5,10 H19 A1,1 0 0 1 20,11 V21 A1,1 0 0 1 19,22 H5 A1,1 0 0 1 4,21 V11 A1,1 0 0 1 5,10 Z" />
|
||||||
|
</vector>
|
||||||
11
android/app/src/main/res/drawable/ic_ow_more_vert.xml
Normal file
11
android/app/src/main/res/drawable/ic_ow_more_vert.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M12,4 A2,2 0 1 0 12,8 A2,2 0 1 0 12,4 Z M12,10 A2,2 0 1 0 12,14 A2,2 0 1 0 12,10 Z M12,16 A2,2 0 1 0 12,20 A2,2 0 1 0 12,16 Z" />
|
||||||
|
</vector>
|
||||||
18
android/app/src/main/res/drawable/ic_ow_person.xml
Normal file
18
android/app/src/main/res/drawable/ic_ow_person.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M12,3 A4,4 0 1 1 11.99,3 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M4,21 C4,16.6 7.6,13.5 12,13.5 C16.4,13.5 20,16.6 20,21" />
|
||||||
|
</vector>
|
||||||
16
android/app/src/main/res/drawable/ic_ow_qr.xml
Normal file
16
android/app/src/main/res/drawable/ic_ow_qr.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="2"
|
||||||
|
android:pathData="M4,4 H10 V10 H4 Z M14,4 H20 V10 H14 Z M4,14 H10 V20 H4 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M14,14 H17 V17 H14 Z M19,18 H21 V20 H19 Z M14,20 H16.5 V22 H14 Z M19.5,14 H21 V16 H19.5 Z" />
|
||||||
|
</vector>
|
||||||
18
android/app/src/main/res/drawable/ic_ow_share.xml
Normal file
18
android/app/src/main/res/drawable/ic_ow_share.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M12,3 V15 M12,3 L8,7 M12,3 L16,7" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M5,12 V19 A2,2 0 0 0 7,21 H17 A2,2 0 0 0 19,19 V12" />
|
||||||
|
</vector>
|
||||||
18
android/app/src/main/res/drawable/ic_ow_shield.xml
Normal file
18
android/app/src/main/res/drawable/ic_ow_shield.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.6"
|
||||||
|
android:pathData="M12,2 L20,5 V11 C20,16.4 16.6,20.8 12,22 C7.4,20.8 4,16.4 4,11 V5 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.6"
|
||||||
|
android:pathData="M8.5,11.5 L11,14 L15.5,9.5" />
|
||||||
|
</vector>
|
||||||
22
android/app/src/main/res/drawable/ic_ow_sliders.xml
Normal file
22
android/app/src/main/res/drawable/ic_ow_sliders.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M3,6 H7.5 M12.5,6 H21 M3,12 H14.5 M19.5,12 H21 M3,18 H4.5 M9.5,18 H21" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M10,3.5 A2.5,2.5 0 1 0 10,8.5 A2.5,2.5 0 1 0 10,3.5 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M17,9.5 A2.5,2.5 0 1 0 17,14.5 A2.5,2.5 0 1 0 17,9.5 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M7,15.5 A2.5,2.5 0 1 0 7,20.5 A2.5,2.5 0 1 0 7,15.5 Z" />
|
||||||
|
</vector>
|
||||||
13
android/app/src/main/res/drawable/ic_ow_wallet.xml
Normal file
13
android/app/src/main/res/drawable/ic_ow_wallet.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Single colour; tinted at the call site. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:pathData="M4,6 H18 A2,2 0 0 1 20,8 V10 H16 A3,3 0 0 0 16,16 H20 V18 A2,2 0 0 1 18,20 H4 A2,2 0 0 1 2,18 V8 A2,2 0 0 1 4,6 Z" />
|
||||||
|
</vector>
|
||||||
21
android/app/src/main/res/drawable/ic_ow_warning.xml
Normal file
21
android/app/src/main/res/drawable/ic_ow_warning.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- OnionWire design-system icon. Outline only: a filled triangle would lose
|
||||||
|
its knock-out once the call site tints the drawable. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:pathData="M12,3 L22,20.5 H2 Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#FF000000"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M12,9 V14.5 M12,17 V17.2" />
|
||||||
|
</vector>
|
||||||
|
|
@ -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<Triple<Int, Int, Int>>(), identiconCells(""))
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue