Calmer key field once a key is present

Show "Sign in again" as an outlined button so it does not compete with
the filled "Switch to" button, and animate the key line in and out.
This commit is contained in:
2026-11-18 14:39:13 +02:00
parent 361d82a4ed
commit 430d7b8d59
@@ -14,6 +14,7 @@ import androidx.compose.foundation.clickable
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
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@@ -287,15 +288,17 @@ internal fun KeyField(key: String, modifier: Modifier = Modifier) {
modifier.padding(start = 16.dp, end = 16.dp, bottom = 16.dp), modifier.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
verticalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp),
) { ) {
if (hasKey) { // The line keeps its text while it animates out
val shownKey = rememberLast(key.takeIf { hasKey }).orEmpty()
AnimatedVisibility(visible = hasKey, enter = Motion.expandIn, exit = Motion.collapseOut) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Text( Text(
stringResource(R.string.key_status, key.take(4)), stringResource(R.string.key_status, shownKey.take(4)),
color = Palette.Fg2, color = Palette.Fg2,
fontSize = 13.sp, fontSize = 13.sp,
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
) )
TextButton(onClick = { copyKeyAddress(context, key) }) { TextButton(onClick = { copyKeyAddress(context, shownKey) }) {
Text(stringResource(R.string.key_copy)) Text(stringResource(R.string.key_copy))
} }
} }
@@ -304,22 +307,30 @@ internal fun KeyField(key: String, modifier: Modifier = Modifier) {
} }
} }
// Starts the browser sign-in; shows progress while the app waits for it // Starts the browser sign-in; shows progress while the app waits for it. Filled while there is
// no key yet; once there is one, signing in again is a rare action and must not compete with
// the filled "Switch to" button below the server list
@Composable @Composable
internal fun SignInButton(again: Boolean, modifier: Modifier = Modifier, shape: Shape = RoundedCornerShape(14.dp)) { internal fun SignInButton(again: Boolean, modifier: Modifier = Modifier, shape: Shape = RoundedCornerShape(14.dp)) {
val context = LocalContext.current val context = LocalContext.current
val signIn by SkysparkleSignIn.state.collectAsStateWithLifecycle() val signIn by SkysparkleSignIn.state.collectAsStateWithLifecycle()
val working = signIn == SkysparkleSignIn.State.Waiting || signIn == SkysparkleSignIn.State.Exchanging val working = signIn == SkysparkleSignIn.State.Waiting || signIn == SkysparkleSignIn.State.Exchanging
Button(onClick = { SkysparkleSignIn.start(context) }, enabled = !working, shape = shape, modifier = modifier) { val onClick = { SkysparkleSignIn.start(context) }
val content: @Composable RowScope.() -> Unit = {
if (working) { if (working) {
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp, color = LocalContentColor.current) CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp, color = LocalContentColor.current)
Spacer(Modifier.width(10.dp)) Spacer(Modifier.width(10.dp))
} }
Text( Text(
stringResource(if (working) R.string.sign_in_working else if (again) R.string.sign_in_again else R.string.sign_in), stringResource(if (working) R.string.sign_in_working else if (again) R.string.sign_in_again else R.string.sign_in),
fontWeight = FontWeight.Bold, fontWeight = if (again) null else FontWeight.Bold,
) )
} }
if (again) {
OutlinedButton(onClick = onClick, enabled = !working, shape = shape, modifier = modifier, content = content)
} else {
Button(onClick = onClick, enabled = !working, shape = shape, modifier = modifier, content = content)
}
} }
// The key is personal, so the clipboard is told to hide it from previews (Android 13+), // The key is personal, so the clipboard is told to hide it from previews (Android 13+),