Refactor QR in RecoveryPasswordActivity

This commit is contained in:
Andrew 2024-03-26 14:42:26 +10:30
parent 92c2d574ae
commit 006c50e38d

View File

@ -33,6 +33,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
@ -166,28 +167,13 @@ fun RecoveryPasswordCell(seed: String = "", qrBitmap: Bitmap? = null, copySeed:(
backgroundColor = LocalExtraColors.current.lightCell, backgroundColor = LocalExtraColors.current.lightCell,
elevation = 0.dp, elevation = 0.dp,
modifier = Modifier modifier = Modifier
.align(Alignment.CenterHorizontally) .align(Alignment.CenterHorizontally)
.padding(vertical = 24.dp) .padding(vertical = 24.dp)
) { ) {
Box { qrBitmap?.let {
qrBitmap?.let { QrImage(
Image( bitmap = it,
bitmap = it.asImageBitmap(), contentDescription = "QR code of your recovery password",
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)
) )
} }
} }
@ -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<Boolean>.toggle() { value = !value } private fun MutableState<Boolean>.toggle() { value = !value }
@Composable @Composable