android: collapse the roster identity block into a dropdown
All checks were successful
android-ci / android (pull_request) Successful in 12m26s
All checks were successful
android-ci / android (pull_request) Successful in 12m26s
The identity card's full fingerprint wraps to several lines on a phone and pushes the friend list off the first screen. Collapse it: one line by default (label + `shortId(fingerprint)` + chevron), the full fingerprint and the full onion behind a tap, in the order they already had. The `sdk …` line and `keepAliveNote` stay outside the disclosure — the keep-alive denial is the only place that note appears, so hanging it off a collapsed block would hide it. `shortId` is a pure top-level function (`head … tail`, unchanged when the value is no longer than the abbreviation, empty stays empty) so the collapsed line is a slice of the value shown expanded, not a parallel encoding. The expand state is `rememberSaveable`: a rotation keeps what the user chose, and nothing about it belongs in the store. RosterIdTest covers the abbreviation on the JVM (7 cases: the 64-hex fingerprint, the head/tail boundary, custom head/tail, shorter-than-input, empty, single-char ellipsis).
This commit is contained in:
parent
a9117b8991
commit
b6447f76d6
2 changed files with 132 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ 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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.Card
|
||||
|
|
@ -27,6 +28,7 @@ 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.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
@ -51,6 +53,10 @@ fun RosterScreen(
|
|||
onOpenWallet: () -> 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) }
|
||||
|
||||
Scaffold(
|
||||
// The content root below consumes systemBars ∪ ime itself (see
|
||||
|
|
@ -79,11 +85,33 @@ fun RosterScreen(
|
|||
),
|
||||
) {
|
||||
Column(Modifier.padding(12.dp)) {
|
||||
Label("YOU (stable forever)")
|
||||
Mono(fingerprint)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Label("ONION (locator — rotates)")
|
||||
Mono(onion)
|
||||
// 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,
|
||||
)
|
||||
}
|
||||
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",
|
||||
|
|
@ -194,6 +222,21 @@ private fun FriendRow(f: FriendInfo, onClick: () -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue