Update recovery key UI. Closes #4063

This commit is contained in:
Benoit Marty 2024-12-18 16:07:02 +01:00
parent 6284a70b00
commit 923797d08c

View file

@ -9,6 +9,7 @@ package io.element.android.features.securebackup.impl.setup.views
import androidx.compose.foundation.background import androidx.compose.foundation.background
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.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@ -24,8 +25,10 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillType import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
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.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.input.VisualTransformation
@ -88,35 +91,31 @@ private fun RecoveryKeyStaticContent(
state: RecoveryKeyViewState, state: RecoveryKeyViewState,
onClick: (() -> Unit)?, onClick: (() -> Unit)?,
) { ) {
Row( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clip(RoundedCornerShape(14.dp)) .clip(RoundedCornerShape(10.dp))
.background( .background(
color = ElementTheme.colors.bgSubtleSecondary, color = ElementTheme.colors.bgSubtleSecondary,
shape = RoundedCornerShape(14.dp)
) )
.clickableIfNotNull(onClick) .clickableIfNotNull(onClick)
.padding(horizontal = 16.dp, vertical = 16.dp), .padding(horizontal = 16.dp, vertical = 11.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp) contentAlignment = Alignment.Center,
) { ) {
if (state.formattedRecoveryKey != null) { if (state.formattedRecoveryKey != null) {
Text( RecoveryKeyWithCopy(
text = state.formattedRecoveryKey, recoveryKey = state.formattedRecoveryKey,
modifier = Modifier.weight(1f), alpha = 1f,
)
Icon(
imageVector = CompoundIcons.Copy(),
contentDescription = stringResource(id = CommonStrings.action_copy),
tint = ElementTheme.colors.iconSecondary,
) )
} else { } else {
// Use an invisible recovery key to ensure that the Box size is correct.
val fakeFormattedRecoveryKey = List(12) { "XXXX" }.joinToString(" ")
RecoveryKeyWithCopy(
recoveryKey = fakeFormattedRecoveryKey,
alpha = 0f,
)
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 11.dp)
) { ) {
if (state.inProgress) { if (state.inProgress) {
CircularProgressIndicator( CircularProgressIndicator(
@ -144,6 +143,31 @@ private fun RecoveryKeyStaticContent(
} }
} }
@Composable
private fun RecoveryKeyWithCopy(
recoveryKey: String,
alpha: Float,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.alpha(alpha),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = recoveryKey,
color = ElementTheme.colors.textSecondary,
style = ElementTheme.typography.fontBodyLgRegular.copy(fontFamily = FontFamily.Monospace),
modifier = Modifier.weight(1f),
)
Icon(
imageVector = CompoundIcons.Copy(),
contentDescription = stringResource(id = CommonStrings.action_copy),
tint = ElementTheme.colors.iconSecondary,
)
}
}
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
private fun RecoveryKeyFormContent( private fun RecoveryKeyFormContent(