From 006c50e38d54d7975a72055a4c0f9ba425ae5262 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 26 Mar 2024 14:42:26 +1030 Subject: [PATCH] Refactor QR in RecoveryPasswordActivity --- .../RecoveryPasswordActivity.kt | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt index a95cde5261..6f15f86ce8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/recoverypassword/RecoveryPasswordActivity.kt @@ -33,6 +33,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.res.painterResource @@ -166,28 +167,13 @@ fun RecoveryPasswordCell(seed: String = "", qrBitmap: Bitmap? = null, copySeed:( backgroundColor = LocalExtraColors.current.lightCell, elevation = 0.dp, modifier = Modifier - .align(Alignment.CenterHorizontally) - .padding(vertical = 24.dp) + .align(Alignment.CenterHorizontally) + .padding(vertical = 24.dp) ) { - Box { - qrBitmap?.let { - Image( - bitmap = it.asImageBitmap(), - contentDescription = "QR code of your recovery password", - colorFilter = ColorFilter.tint(LocalExtraColors.current.onLightCell) - ) - } - - Icon( - painter = painterResource(id = R.drawable.session_shield), - contentDescription = "", - tint = LocalExtraColors.current.onLightCell, - modifier = Modifier - .align(Alignment.Center) - .width(46.dp) - .height(56.dp) - .background(color = LocalExtraColors.current.lightCell) - .padding(horizontal = 3.dp, vertical = 1.dp) + qrBitmap?.let { + QrImage( + bitmap = it, + contentDescription = "QR code of your recovery password", ) } } @@ -213,6 +199,29 @@ fun RecoveryPasswordCell(seed: String = "", qrBitmap: Bitmap? = null, copySeed:( } } +@Composable +fun QrImage(bitmap: Bitmap, contentDescription: String, icon: Int = R.drawable.session_shield) { + Box { + Image( + bitmap = bitmap.asImageBitmap(), + contentDescription = contentDescription, + colorFilter = ColorFilter.tint(LocalExtraColors.current.onLightCell) + ) + + Icon( + painter = painterResource(id = icon), + contentDescription = "", + tint = LocalExtraColors.current.onLightCell, + modifier = Modifier + .align(Alignment.Center) + .width(46.dp) + .height(56.dp) + .background(color = LocalExtraColors.current.lightCell) + .padding(horizontal = 3.dp, vertical = 1.dp) + ) + } +} + private fun MutableState.toggle() { value = !value } @Composable