Skip to content

Commit 4d89c76

Browse files
committed
Update recovery key UI. Closes #4063
1 parent c240b5d commit 4d89c76

File tree

1 file changed

+41
-17
lines changed
  • features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/setup/views

1 file changed

+41
-17
lines changed

features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/setup/views/RecoveryKeyView.kt

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package io.element.android.features.securebackup.impl.setup.views
99

1010
import androidx.compose.foundation.background
1111
import androidx.compose.foundation.layout.Arrangement
12+
import androidx.compose.foundation.layout.Box
1213
import androidx.compose.foundation.layout.Column
1314
import androidx.compose.foundation.layout.Row
1415
import androidx.compose.foundation.layout.fillMaxWidth
@@ -24,8 +25,10 @@ import androidx.compose.ui.Alignment
2425
import androidx.compose.ui.ExperimentalComposeUiApi
2526
import androidx.compose.ui.Modifier
2627
import androidx.compose.ui.autofill.AutofillType
28+
import androidx.compose.ui.draw.alpha
2729
import androidx.compose.ui.draw.clip
2830
import androidx.compose.ui.res.stringResource
31+
import androidx.compose.ui.text.font.FontFamily
2932
import androidx.compose.ui.text.input.ImeAction
3033
import androidx.compose.ui.text.input.KeyboardType
3134
import androidx.compose.ui.text.input.VisualTransformation
@@ -88,35 +91,31 @@ private fun RecoveryKeyStaticContent(
8891
state: RecoveryKeyViewState,
8992
onClick: (() -> Unit)?,
9093
) {
91-
Row(
94+
Box(
9295
modifier = Modifier
9396
.fillMaxWidth()
94-
.clip(RoundedCornerShape(14.dp))
97+
.clip(RoundedCornerShape(10.dp))
9598
.background(
9699
color = ElementTheme.colors.bgSubtleSecondary,
97-
shape = RoundedCornerShape(14.dp)
98100
)
99101
.clickableIfNotNull(onClick)
100-
.padding(horizontal = 16.dp, vertical = 16.dp),
101-
horizontalArrangement = Arrangement.spacedBy(8.dp)
102+
.padding(horizontal = 16.dp, vertical = 11.dp),
103+
contentAlignment = Alignment.Center,
102104
) {
103105
if (state.formattedRecoveryKey != null) {
104-
Text(
105-
text = state.formattedRecoveryKey,
106-
modifier = Modifier.weight(1f),
107-
)
108-
Icon(
109-
imageVector = CompoundIcons.Copy(),
110-
contentDescription = stringResource(id = CommonStrings.action_copy),
111-
tint = ElementTheme.colors.iconSecondary,
106+
RecoveryKeyWithCopy(
107+
recoveryKey = state.formattedRecoveryKey,
108+
alpha = 1f,
112109
)
113110
} else {
111+
// Use an invisible recovery key to ensure that the Box size is correct.
112+
val fakeFormattedRecoveryKey = List(12) { "XXXX" }.joinToString(" ")
113+
RecoveryKeyWithCopy(
114+
recoveryKey = fakeFormattedRecoveryKey,
115+
alpha = 0f,
116+
)
114117
Row(
115118
verticalAlignment = Alignment.CenterVertically,
116-
horizontalArrangement = Arrangement.Center,
117-
modifier = Modifier
118-
.fillMaxWidth()
119-
.padding(vertical = 11.dp)
120119
) {
121120
if (state.inProgress) {
122121
CircularProgressIndicator(
@@ -144,6 +143,31 @@ private fun RecoveryKeyStaticContent(
144143
}
145144
}
146145

146+
@Composable
147+
private fun RecoveryKeyWithCopy(
148+
recoveryKey: String,
149+
alpha: Float,
150+
) {
151+
Row(
152+
modifier = Modifier
153+
.fillMaxWidth()
154+
.alpha(alpha),
155+
horizontalArrangement = Arrangement.spacedBy(8.dp),
156+
) {
157+
Text(
158+
text = recoveryKey,
159+
color = ElementTheme.colors.textSecondary,
160+
style = ElementTheme.typography.fontBodyLgRegular.copy(fontFamily = FontFamily.Monospace),
161+
modifier = Modifier.weight(1f),
162+
)
163+
Icon(
164+
imageVector = CompoundIcons.Copy(),
165+
contentDescription = stringResource(id = CommonStrings.action_copy),
166+
tint = ElementTheme.colors.iconSecondary,
167+
)
168+
}
169+
}
170+
147171
@OptIn(ExperimentalComposeUiApi::class)
148172
@Composable
149173
private fun RecoveryKeyFormContent(

0 commit comments

Comments
 (0)