ui: app shell, messenger and invite refresh (plan P2 and P3)

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.
This commit is contained in:
agent 2026-10-28 23:51:51 -04:00
commit 0283e6bf48
No known key found for this signature in database
13 changed files with 1228 additions and 406 deletions

View file

@ -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
}
}

View file

@ -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,

View file

@ -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),
)
)
}

View file

@ -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<String?>(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))
}
}
}

View file

@ -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,

View file

@ -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<FriendInfo>,
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
}

View file

@ -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,
),

View file

@ -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,
)
}
}

View file

@ -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()
}
}
}

View file

@ -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,
)
}
}

View file

@ -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() },
)
}
}
}