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

@ -344,6 +344,20 @@ The cuprated graph is built with Rust 1.98 here, the same floor as `ci.yml`
(`rust-version = "1.98"`). Job timeout is **90** minutes on `android-release.yml` and **120** (`rust-version = "1.98"`). Job timeout is **90** minutes on `android-release.yml` and **120**
on `android-ci.yml`. on `android-ci.yml`.
## App shell
Three top-level destinations, one persistent bottom tab bar
(`ui/components/BottomTabBar.kt`): **Chats** (default), **Wallet**, and **Node &
Settings**. Sub-screens (chat, invite share, add contact, rotate, profile, saved
wallets) keep a chevron back button and hide the bar. The rare and destructive
actions — rotate identity, delete message history, saved wallets — are behind the
`⋮` overflow and a typed confirmation, not on the home screen.
Colours, radii and type live in `ui/Theme.kt` as `OwColors` / `OwRadius` /
`OwSize`; new UI takes tokens from there instead of `MaterialTheme` defaults.
Monospace is reserved for pubkeys, truncated onion locators, seeds, `host:port`
and block heights — never for a sentence.
## Layout ## Layout
``` ```
@ -363,25 +377,33 @@ android/
build.gradle.kts build.gradle.kts
src/main/AndroidManifest.xml src/main/AndroidManifest.xml
src/main/java/com/siriusdevops/onionwire/ src/main/java/com/siriusdevops/onionwire/
MainActivity.kt # NavHost MainActivity.kt # app shell: bottom tabs + NavHost
WireViewModel.kt # UI-side Wire handle; wallet-child poller WireViewModel.kt # UI-side Wire handle; wallet-child poller
crypto/ # Keystore-wrapped store passphrase crypto/ # Keystore-wrapped store passphrase
keepalive/ # NodeHost, KeepAliveService, policy, lifetime keepalive/ # NodeHost, KeepAliveService, policy, lifetime
wallet/ # ChainStorage, WalletChildBinaries wallet/ # ChainStorage, WalletChildBinaries
ui/ # Compose screens (M3) ui/ # Compose screens (M3)
components/ # design system: OwButton, OwSegmentedControl,
# OwAlertBanner, OwCard, OwTopBar, OwBottomTabBar,
# OwConfirmDialog, OwQrCode, Identicon
WalletScreen.kt WalletScreen.kt
WalletManagerScreen.kt
WalletChildStatusText.kt WalletChildStatusText.kt
ChatScreen.kt ChatScreen.kt
RosterScreen.kt RosterScreen.kt # Chats tab: identity bar + roster
InviteScreens.kt SettingsScreen.kt # Node & Settings tab
ProfileScreen.kt
InviteScreens.kt # share (QR + text) and paste-a-contact
InviteAddFlow.kt InviteAddFlow.kt
OutboxDetail.kt OutboxDetail.kt
MessageDelivery.kt MessageDelivery.kt
UnlockScreen.kt UnlockScreen.kt
UnlockSubmit.kt UnlockSubmit.kt
SeedBackupGate.kt
RotateScreen.kt RotateScreen.kt
Insets.kt Insets.kt # systemBars ∪ ime, minus the tab-bar inset
Theme.kt Theme.kt # design tokens: palette, radii, sizes, typography
src/main/res/drawable/ic_ow_*.xml # single-colour design-system icons
src/test/ # JVM: envelope, store, invite, outbox, keepalive, wallet line, refresh loop src/test/ # JVM: envelope, store, invite, outbox, keepalive, wallet line, refresh loop
src/androidTest/ # device-only: AndroidKeyStore src/androidTest/ # device-only: AndroidKeyStore
src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so

View file

@ -8,37 +8,61 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize 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.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.NavType import androidx.navigation.NavType
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument import androidx.navigation.navArgument
import com.siriusdevops.onionwire.ui.ChatScreen 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.PasteInviteScreen
import com.siriusdevops.onionwire.ui.ProfileScreen import com.siriusdevops.onionwire.ui.ProfileScreen
import com.siriusdevops.onionwire.ui.RosterScreen import com.siriusdevops.onionwire.ui.RosterScreen
import com.siriusdevops.onionwire.ui.RotateScreen import com.siriusdevops.onionwire.ui.RotateScreen
import com.siriusdevops.onionwire.ui.SettingsScreen
import com.siriusdevops.onionwire.ui.ShareInviteScreen import com.siriusdevops.onionwire.ui.ShareInviteScreen
import com.siriusdevops.onionwire.ui.UnlockScreen import com.siriusdevops.onionwire.ui.UnlockScreen
import com.siriusdevops.onionwire.ui.WalletManagerScreen import com.siriusdevops.onionwire.ui.WalletManagerScreen
import com.siriusdevops.onionwire.ui.WalletScreen 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 import kotlinx.coroutines.launch
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enableEdgeToEdge() 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 { setContent {
OnionWireTheme { OnionWireTheme {
Surface( Surface(
@ -61,7 +85,7 @@ private fun AppRoot(vm: WireViewModel = viewModel()) {
// Asked in context: the notification is the keep-alive's only visible // 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 // 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 // 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( val askNotifications = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission(), ActivityResultContracts.RequestPermission(),
) { vm.onNotificationPermissionChanged() } ) { vm.onNotificationPermissionChanged() }
@ -87,36 +111,111 @@ 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 @Composable
private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: String?) { private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: String?) {
val nav = rememberNavController() val nav = rememberNavController()
val friends by vm.friends.collectAsStateWithLifecycle() val friends by vm.friends.collectAsStateWithLifecycle()
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val entry by nav.currentBackStackEntryAsState()
val tab = Routes.tabOf(entry?.destination?.route)
NavHost(navController = nav, startDestination = "roster") { Scaffold(
composable("roster") { // 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( RosterScreen(
fingerprint = ready.fingerprint, fingerprint = ready.fingerprint,
onion = ready.onion,
sdkVersion = ready.sdkVersion,
friends = friends, friends = friends,
keepAliveNote = keepAliveNote, invite = vm::invite,
onOpenChat = { nav.navigate("chat/${it.pubkeyHex}") }, onOpenChat = { nav.navigate("chat/${it.pubkeyHex}") },
onShare = { nav.navigate("share") }, onShare = { nav.navigate(Routes.Share) },
onPaste = { nav.navigate("paste") }, onPaste = { nav.navigate(Routes.Paste) },
onRotate = { nav.navigate("rotate") }, onRotate = { nav.navigate(Routes.Rotate) },
onWipe = { scope.launch { vm.wipeMessages() } }, onWipe = { scope.launch { vm.wipeMessages() } },
onOpenProfile = { nav.navigate("profile") }, onOpenProfile = { nav.navigate(Routes.Profile) },
onLock = vm::lock, onLock = vm::lock,
onOpenWallet = { nav.navigate("wallet") }, onOpenWallets = { nav.navigate(Routes.Wallets) },
) )
} }
composable("share") { composable(Routes.Wallet) {
WalletScreen(
vm = vm,
onBack = { nav.popBackStack() },
onOpenWallets = { nav.navigate(Routes.Wallets) },
)
}
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(Routes.Share) {
ShareInviteScreen(ownerInvite = vm::invite, onBack = { nav.popBackStack() }) ShareInviteScreen(ownerInvite = vm::invite, onBack = { nav.popBackStack() })
} }
composable("paste") { composable(Routes.Paste) {
PasteInviteScreen( PasteInviteScreen(
onDecode = vm::decode, onDecode = vm::decode,
onAdd = vm::addFriend, onAdd = vm::addFriend,
@ -124,7 +223,7 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
) )
} }
composable("rotate") { composable(Routes.Rotate) {
RotateScreen( RotateScreen(
currentOnion = ready.onion, currentOnion = ready.onion,
onRotate = { onRotate = {
@ -135,27 +234,19 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
) )
} }
composable("wallet") { composable(Routes.Wallets) {
WalletScreen(
vm = vm,
onBack = { nav.popBackStack() },
onOpenWallets = { nav.navigate("wallets") },
)
}
composable("wallets") {
WalletManagerScreen(vm = vm, onBack = { nav.popBackStack() }) WalletManagerScreen(vm = vm, onBack = { nav.popBackStack() })
} }
composable("profile") { composable(Routes.Profile) {
ProfileScreen(vm = vm, onBack = { nav.popBackStack() }) ProfileScreen(vm = vm, onBack = { nav.popBackStack() })
} }
composable( composable(
route = "chat/{pk}", route = Routes.Chat,
arguments = listOf(navArgument("pk") { type = NavType.StringType }), arguments = listOf(navArgument("pk") { type = NavType.StringType }),
) { entry -> ) { chatEntry ->
val pk = entry.arguments?.getString("pk").orEmpty() val pk = chatEntry.arguments?.getString("pk").orEmpty()
val friend = friends.firstOrNull { it.pubkeyHex == pk } val friend = friends.firstOrNull { it.pubkeyHex == pk }
ChatScreen( ChatScreen(
vm = vm, vm = vm,
@ -170,3 +261,15 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
} }
} }
} }
}
}
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.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.siriusdevops.onionwire.R
import com.siriusdevops.onionwire.ui.components.OwIconButton
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.siriusdevops.onionwire.WireViewModel import com.siriusdevops.onionwire.WireViewModel
import uniffi.onionwire_sdk.SendState import uniffi.onionwire_sdk.SendState
@ -184,7 +186,11 @@ fun ChatScreen(
} }
}, },
navigationIcon = { navigationIcon = {
IconButton(onClick = onBack) { Text("<") } OwIconButton(
iconRes = R.drawable.ic_ow_chevron_left,
contentDescription = "Back",
onClick = onBack,
)
}, },
colors = TopAppBarDefaults.topAppBarColors( colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background, 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.union
import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier 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 * The bottom + horizontal window insets one screen's content root must apply
* itself. * itself.
@ -25,7 +35,9 @@ import androidx.compose.ui.Modifier
* *
* The IME's bottom inset already covers the navigation bar, so the two are * The IME's bottom inset already covers the navigation bar, so the two are
* unioned (per-side `max`), never summed: keyboard height while typing, * 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 * 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 * 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 reads — call it from a composable (every call site is one).
*/ */
@Composable @Composable
fun Modifier.screenContentInsets(): Modifier = fun Modifier.screenContentInsets(): Modifier {
windowInsetsPadding( val sides = if (LocalBottomBarPresent.current) {
WindowInsets.systemBars.union(WindowInsets.ime) WindowInsetsSides.Horizontal
} else {
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
}
return windowInsetsPadding(
WindowInsets.systemBars.only(sides)
.union(WindowInsets.ime)
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom), .only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
) )
}

View file

@ -1,6 +1,9 @@
package com.siriusdevops.onionwire.ui package com.siriusdevops.onionwire.ui
import android.content.ClipData 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.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row 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.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll 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.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text 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.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -32,15 +28,36 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ClipEntry import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.platform.LocalClipboard import androidx.compose.ui.platform.LocalClipboard
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp 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 kotlinx.coroutines.launch
import uniffi.onionwire_sdk.FriendInfo import uniffi.onionwire_sdk.FriendInfo
import uniffi.onionwire_sdk.InviteInfo 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 @Composable
fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) { fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
var invite by remember { mutableStateOf<String?>(null) } var invite by remember { mutableStateOf<String?>(null) }
@ -56,18 +73,11 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
} }
Scaffold( Scaffold(
topBar = { topBar = { OwTopBar(title = "Your invite", onBack = onBack) },
TopAppBar(
title = { Text("Your invite") },
navigationIcon = { IconButton(onClick = onBack) { Text("<") } },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background,
),
)
},
// The root applies systemBars + IME itself (see `screenContentInsets`), // The root applies systemBars + IME itself (see `screenContentInsets`),
// so Scaffold must not also pad for the navigation bar. // so Scaffold must not also pad for the navigation bar.
contentWindowInsets = WindowInsets(0, 0, 0, 0), contentWindowInsets = WindowInsets(0, 0, 0, 0),
containerColor = OwColors.Canvas,
) { pad -> ) { pad ->
Column( Column(
Modifier Modifier
@ -75,70 +85,116 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
.fillMaxSize() .fillMaxSize()
.screenContentInsets() .screenContentInsets()
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
.padding(16.dp), .padding(horizontal = 16.dp),
) { ) {
Text( Spacer(Modifier.height(8.dp))
"Hand this to one person, over a channel you already trust. " + OwAlertBanner(
"It is not published anywhere and cannot be looked up.", variant = OwAlertVariant.Info,
style = MaterialTheme.typography.bodySmall, title = "Not published anywhere",
color = MaterialTheme.colorScheme.onSurfaceVariant, 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 { when {
error != null -> Text( error != null -> OwAlertBanner(
error!!, variant = OwAlertVariant.Error,
style = MaterialTheme.typography.bodySmall, title = "Could not read your invite",
color = MaterialTheme.colorScheme.error, description = error,
) )
invite == null -> CircularProgressIndicator() invite == null -> Row(
Modifier.fillMaxWidth().padding(vertical = 32.dp),
horizontalArrangement = Arrangement.Center,
) { CircularProgressIndicator(color = OwColors.Accent) }
else -> { else -> {
Card( val payload = invite!!
colors = CardDefaults.cardColors( Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
containerColor = MaterialTheme.colorScheme.surfaceVariant, OwQrCode(payload = payload, size = 220.dp)
), }
) { Spacer(Modifier.height(16.dp))
OwCard(Modifier.fillMaxWidth(), padding = 12.dp) {
Text( Text(
invite!!, payload,
style = MaterialTheme.typography.bodySmall, style = MonoStyle.copy(color = OwColors.TextSecondary),
modifier = Modifier.padding(12.dp), textAlign = TextAlign.Start,
) )
} }
Spacer(Modifier.height(12.dp)) Spacer(Modifier.height(12.dp))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(onClick = { OwButton(
text = if (copied) "Copied" else "Copy invite",
onClick = {
scope.launch { scope.launch {
clipboard.setClipEntry( val clip = ClipData.newPlainText("onionwire invite", payload)
ClipEntry(ClipData.newPlainText("onionwire invite", invite!!)), 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 copied = true
} }
}) { Text(if (copied) "Copied" else "Copy") } },
} leadingIconRes = R.drawable.ic_ow_copy,
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,
) )
OwButton(
text = "Done",
variant = OwButtonVariant.Outline,
onClick = onBack,
)
}
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 @Composable
fun PasteInviteScreen( fun PasteInviteScreen(
onDecode: suspend (String) -> InviteInfo, onDecode: suspend (String) -> InviteInfo,
@ -155,19 +211,12 @@ fun PasteInviteScreen(
val adding = flow.adding val adding = flow.adding
Scaffold( Scaffold(
topBar = { topBar = { OwTopBar(title = "Add contact", onBack = onBack) },
TopAppBar(
title = { Text("Add a friend") },
navigationIcon = { IconButton(onClick = onBack) { Text("<") } },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background,
),
)
},
// Same inset handoff as the chat composer: with the keyboard up, the // Same inset handoff as the chat composer: with the keyboard up, the
// Verify / Approve buttons under the invite field must still be // Verify / Approve buttons under the invite field must still be
// reachable by scrolling, not by dismissing the keyboard. // reachable by scrolling, not by dismissing the keyboard.
contentWindowInsets = WindowInsets(0, 0, 0, 0), contentWindowInsets = WindowInsets(0, 0, 0, 0),
containerColor = OwColors.Canvas,
) { pad -> ) { pad ->
Column( Column(
Modifier Modifier
@ -175,90 +224,83 @@ fun PasteInviteScreen(
.fillMaxSize() .fillMaxSize()
.screenContentInsets() .screenContentInsets()
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
.padding(16.dp), .padding(horizontal = 16.dp),
) { ) {
Spacer(Modifier.height(8.dp))
OutlinedTextField( OutlinedTextField(
value = raw, value = raw,
onValueChange = { onValueChange = {
raw = it raw = it
flow.clear() flow.clear()
}, },
label = { Text("onionwire:v1:…") }, label = { Text("onionwire:v2:…") },
minLines = 4, minLines = 4,
shape = RoundedCornerShape(OwRadius.Control),
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
) )
Spacer(Modifier.height(12.dp)) Spacer(Modifier.height(12.dp))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button( OwButton(
text = "Verify",
enabled = raw.isNotBlank() && !verifying && !adding, enabled = raw.isNotBlank() && !verifying && !adding,
onClick = { scope.launch { flow.verify(raw) } }, onClick = { scope.launch { flow.verify(raw) } },
) { Text("Verify") } )
if (added != null) { if (added != null) {
TextButton(onClick = onBack) { Text("Done") } OwButton(text = "Done", variant = OwButtonVariant.Outline, onClick = onBack)
} }
} }
Spacer(Modifier.height(16.dp)) Spacer(Modifier.height(16.dp))
error?.let { error?.let {
Text( OwAlertBanner(
it, variant = OwAlertVariant.Error,
style = MaterialTheme.typography.bodySmall, title = "That invite was not accepted",
color = MaterialTheme.colorScheme.error, description = "$it — unsigned or tampered invites are rejected " +
) "here, before anything is stored.",
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,
) )
Spacer(Modifier.height(12.dp))
} }
preview?.let { p -> preview?.let { p ->
Card( OwCard(Modifier.fillMaxWidth()) {
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
),
modifier = Modifier.fillMaxWidth(),
) {
Column(Modifier.padding(12.dp)) {
Label("THEY ARE") Label("THEY ARE")
Mono(p.pubkeyHex) Spacer(Modifier.height(2.dp))
Spacer(Modifier.height(8.dp)) Mono(shortId(p.pubkeyHex, head = 12, tail = 8))
Spacer(Modifier.height(6.dp))
Text( Text(
"fingerprint ${p.pubkeyHex.take(16)}… — compare this with them " + "Compare this fingerprint with them over a second channel " +
"over a second channel before you trust it.", "before you trust it.",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = OwColors.TextSecondary,
) )
Spacer(Modifier.height(8.dp)) Spacer(Modifier.height(10.dp))
OwDivider()
Spacer(Modifier.height(10.dp))
Label("REACHABLE AT") Label("REACHABLE AT")
Mono(p.onion) Spacer(Modifier.height(2.dp))
} Mono(shortOnion(p.onion))
} }
Spacer(Modifier.height(12.dp)) Spacer(Modifier.height(12.dp))
Button( OwButton(
text = "Approve & add",
enabled = !adding && added == null, enabled = !adding && added == null,
onClick = { scope.launch { flow.add(raw) } }, onClick = { scope.launch { flow.add(raw) } },
) { Text("Approve & add") } leadingIconRes = R.drawable.ic_ow_add,
)
} }
added?.let { f -> added?.let { f ->
Spacer(Modifier.height(16.dp)) Spacer(Modifier.height(16.dp))
Text( OwAlertBanner(
"Added ${f.petname ?: f.fingerprint}", variant = OwAlertVariant.Info,
style = MaterialTheme.typography.titleSmall, title = "Added ${f.petname ?: shortId(f.fingerprint)}",
color = MaterialTheme.colorScheme.primary, description = "If that key was already in your roster, only the " +
) "locator was updated. One key is always one friend.",
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,
) )
} }
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.platform.testTag
import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.siriusdevops.onionwire.R
import com.siriusdevops.onionwire.ui.components.OwIconButton
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.siriusdevops.onionwire.WireViewModel import com.siriusdevops.onionwire.WireViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -100,7 +102,11 @@ fun ProfileScreen(
TopAppBar( TopAppBar(
title = { Text("Profile") }, title = { Text("Profile") },
navigationIcon = { navigationIcon = {
TextButton(onClick = onBack) { Text("Back") } OwIconButton(
iconRes = R.drawable.ic_ow_chevron_left,
contentDescription = "Back",
onClick = onBack,
)
}, },
colors = TopAppBarDefaults.topAppBarColors( colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background, containerColor = MaterialTheme.colorScheme.background,

View file

@ -1,8 +1,14 @@
package com.siriusdevops.onionwire.ui 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.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer 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.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text 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.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier 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 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 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 @Composable
fun RosterScreen( fun RosterScreen(
fingerprint: String, fingerprint: String,
onion: String,
sdkVersion: String,
friends: List<FriendInfo>, friends: List<FriendInfo>,
keepAliveNote: String?, invite: suspend () -> String,
onOpenChat: (FriendInfo) -> Unit, onOpenChat: (FriendInfo) -> Unit,
onShare: () -> Unit, onShare: () -> Unit,
onPaste: () -> Unit, onPaste: () -> Unit,
@ -51,245 +89,288 @@ fun RosterScreen(
onWipe: () -> Unit, onWipe: () -> Unit,
onOpenProfile: () -> Unit, onOpenProfile: () -> Unit,
onLock: () -> Unit, onLock: () -> Unit,
onOpenWallet: () -> Unit, onOpenWallets: () -> Unit,
) { ) {
var confirmWipe by remember { mutableStateOf(false) } val context = LocalContext.current
// Closed by default; `rememberSaveable` so a rotation keeps whatever the val clipboard = LocalClipboard.current
// user chose instead of snapping back to (or away from) the summary. val scope = rememberCoroutineScope()
// Nothing about this is worth persisting to the store. var confirmDeleteAll by remember { mutableStateOf(false) }
var identityExpanded by rememberSaveable { mutableStateOf(false) }
Scaffold( Scaffold(
// The content root below consumes systemBars ∪ ime itself (see // The content root below consumes systemBars ∪ ime itself (see
// `screenContentInsets`); zeroing the Scaffold's own insets keeps the // `screenContentInsets`), and the tab bar above this screen consumes the
// navigation bar from being applied twice and lets the wipe-confirm // navigation-bar inset; zeroing the Scaffold's own insets is what keeps
// strip sit above the keyboard instead of under it. // the list from being padded twice.
contentWindowInsets = WindowInsets(0, 0, 0, 0), contentWindowInsets = WindowInsets(0, 0, 0, 0),
containerColor = OwColors.Canvas,
topBar = { topBar = {
TopAppBar( OwTopBar(
title = { Text("OnionWire") }, title = "OnionWire",
status = { TorStatusPill() },
actions = { actions = {
TextButton(onClick = onOpenProfile) { Text("Profile") } OwIconButton(
TextButton(onClick = onLock) { Text("Lock") } 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 -> ) { pad ->
Column(Modifier.padding(pad).fillMaxSize().screenContentInsets()) { Column(Modifier.padding(pad).fillMaxSize().screenContentInsets()) {
IdentityBar(
Card( fingerprint = fingerprint,
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp), onCopyInvite = {
colors = CardDefaults.cardColors( scope.launch {
containerColor = MaterialTheme.colorScheme.surfaceVariant, runCatching { invite() }
), .onSuccess { payload ->
) { copyInvite(clipboard, payload)
Column(Modifier.padding(12.dp)) { Toast.makeText(context, "Invite address copied", Toast.LENGTH_SHORT).show()
// 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)) .onFailure {
Text( Toast.makeText(context, "Could not read the invite", Toast.LENGTH_SHORT).show()
if (identityExpanded) "▾" else "▸", }
style = MaterialTheme.typography.labelSmall, }
color = MaterialTheme.colorScheme.onSurfaceVariant, },
onShare = onShare,
) )
}
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,
)
}
}
}
Spacer(Modifier.height(8.dp)) Spacer(Modifier.height(12.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))
if (friends.isEmpty()) { if (friends.isEmpty()) {
Column( EmptyRoster(
Modifier.fillMaxSize().padding(24.dp), modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.Center, onPaste = onPaste,
horizontalAlignment = Alignment.CenterHorizontally, onShare = onShare,
) {
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,
) )
}
} else { } 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()) { LazyColumn(Modifier.weight(1f).fillMaxWidth()) {
items(friends, key = { it.pubkeyHex }) { f -> items(friends, key = { it.pubkeyHex }) { f ->
FriendRow(f) { onOpenChat(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 @Composable
private fun FriendRow(f: FriendInfo, onClick: () -> Unit) { private fun FriendRow(f: FriendInfo, onClick: () -> Unit) {
Column( Row(
Modifier Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable(onClick = onClick) .clickable(onClick = onClick)
.background(MaterialTheme.colorScheme.background)
.padding(horizontal = 16.dp, vertical = 12.dp), .padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) { ) {
Column(Modifier.weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Text( Text(
f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint, f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint,
style = MaterialTheme.typography.titleSmall, style = MaterialTheme.typography.titleSmall,
color = OwColors.TextPrimary,
) )
if (!f.lastConnectOk) { if (!f.lastConnectOk) {
Spacer(Modifier.height(0.dp)) Spacer(Modifier.width(8.dp))
OwStatusDot(OwColors.Warning)
Spacer(Modifier.width(6.dp))
Text( Text(
"locator stale", "locator stale",
style = MaterialTheme.typography.labelSmall, style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.error, color = OwColors.Warning,
) )
} }
} }
Spacer(Modifier.height(2.dp)) Spacer(Modifier.height(3.dp))
Text( Text(
f.fingerprint, shortId(f.fingerprint),
style = MaterialTheme.typography.bodySmall, style = MonoStyle,
fontFamily = FontFamily.Monospace, color = OwColors.TextSecondary,
color = MaterialTheme.colorScheme.primary,
) )
Text( Text(
f.onion, shortOnion(f.onion),
style = MaterialTheme.typography.labelSmall, style = MonoStyle.copy(color = OwColors.TextMuted),
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 * The compact stand-in for a long identity string: `head` characters, an
* ellipsis, then `tail` characters. Pure, so the roster's collapsed line and * ellipsis, then `tail` characters. Pure, so the roster's line and its unit test
* its unit test agree on what "short" means. * agree on what "short" means.
* *
* A string no longer than the abbreviation is returned unchanged — the * 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 * 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`/ * mangled. Kotlin strings are UTF-16, but these IDs are hex, so `take`/`takeLast`
* `takeLast` cannot split a surrogate pair here. * cannot split a surrogate pair here.
*/ */
fun shortId(id: String, head: Int = 6, tail: Int = 4): String { fun shortId(id: String, head: Int = 6, tail: Int = 4): String {
if (id.length < head + tail + 1) return id if (id.length < head + tail + 1) return id
return id.take(head) + "…" + id.takeLast(tail) return id.take(head) + "…" + id.takeLast(tail)
} }
@Composable /**
fun Label(text: String) { * A v3 onion locator shortened for a roster row, with the `.onion` suffix kept
Text( * visible: `abcdefghij…uvwxyz.onion`.
text, *
style = MaterialTheme.typography.labelSmall, * The suffix is the part that tells a reader this is an onion address at all, so
color = MaterialTheme.colorScheme.onSurfaceVariant, * 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.
*/
@Composable fun shortOnion(onion: String, head: Int = 10, tail: Int = 6): String {
fun Mono(text: String) { val suffix = ".onion"
Text( if (onion.isEmpty()) return onion
text, if (!onion.endsWith(suffix)) return onion
style = MaterialTheme.typography.bodySmall, val body = onion.removeSuffix(suffix)
fontFamily = FontFamily.Monospace, if (body.length <= head + tail + 1) return onion
color = MaterialTheme.colorScheme.onSurface, return body.take(head) + "…" + body.takeLast(tail) + suffix
)
}
@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") }
}
}
}
} }

View file

@ -29,6 +29,10 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp 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. * Rotating publishes a brand new onion service and hard-cuts the old one.
@ -54,7 +58,13 @@ fun RotateScreen(
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { Text("Rotate onion") }, 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( colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background, 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() },
)
}
}
}

View file

@ -0,0 +1,45 @@
package com.siriusdevops.onionwire.ui
import org.junit.Assert.assertEquals
import org.junit.Test
/**
* `shortOnion`, the roster's locator abbreviation, on the JVM.
*
* A v3 onion locator must never be soft-wrapped or reduced to a middle slice
* that hides `.onion`: the suffix is what tells a reader this is an onion
* address at all, and the full value is available on the profile and invite
* screens. Pure logic, no Robolectric — same shape as `RosterIdTest`.
*/
class RosterOnionTest {
private val v3 =
"abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwxyz234567.onion"
@Test
fun a_v3_locator_keeps_its_suffix() {
val short = shortOnion(v3)
assertEquals(true, short.endsWith(".onion"))
assertEquals(v3.take(10), short.substringBefore("\u2026"))
assertEquals(v3.removeSuffix(".onion").takeLast(6), short.removeSuffix(".onion").substringAfter("\u2026"))
}
@Test
fun the_suffix_is_never_the_part_that_is_cut() {
// Even with an aggressive abbreviation the reader still sees `….onion`.
val body = v3.removeSuffix(".onion")
val short = shortOnion(v3, head = 3, tail = 2)
assertEquals(body.take(3) + "\u2026" + body.takeLast(2) + ".onion", short)
}
@Test
fun a_short_value_is_returned_unchanged() {
assertEquals("abc.onion", shortOnion("abc.onion"))
assertEquals("", shortOnion(""))
}
@Test
fun a_value_with_no_suffix_is_not_mangled() {
assertEquals("not-an-onion", shortOnion("not-an-onion"))
}
}