diff options
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt')
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt | 75 |
1 files changed, 52 insertions, 23 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt index 3f8ecd1..4991094 100644 --- a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt +++ b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt @@ -21,26 +21,31 @@ import android.content.ClipboardManager import android.content.Context import androidx.compose.foundation.Image import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState -import androidx.compose.material.Button -import androidx.compose.material.Icon -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonColors +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.produceState -import androidx.compose.ui.Alignment +import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.Dp @@ -58,12 +63,18 @@ fun ColumnScope.QrCodeUriComposable( inBetween: (@Composable ColumnScope.() -> Unit)? = null, ) { val qrCodeSize = getQrCodeSize() - val qrState = produceState<ImageBitmap?>(null) { + val qrPlaceHolder = if (LocalInspectionMode.current) { + QrCodeManager.makeQrCode(talerUri, qrCodeSize.value.toInt()).asImageBitmap() + } else null + val qrState = produceState(qrPlaceHolder) { value = QrCodeManager.makeQrCode(talerUri, qrCodeSize.value.toInt()).asImageBitmap() } qrState.value?.let { qrCode -> Image( - modifier = Modifier.size(qrCodeSize), + modifier = Modifier + .size(qrCodeSize) + .align(CenterHorizontally) + .padding(vertical = 8.dp), bitmap = qrCode, contentDescription = stringResource(id = R.string.button_scan_qr_code), ) @@ -74,16 +85,33 @@ fun ColumnScope.QrCodeUriComposable( Text( modifier = Modifier.horizontalScroll(scrollState), fontFamily = FontFamily.Monospace, - style = MaterialTheme.typography.body1, + style = MaterialTheme.typography.bodyLarge, text = talerUri, ) } - CopyToClipboardButton( - modifier = Modifier, - label = clipBoardLabel, - content = talerUri, - buttonText = buttonText, - ) + Row( + modifier = Modifier + .padding(horizontal = 16.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly, + ) { + CopyToClipboardButton( + label = clipBoardLabel, + content = talerUri, + buttonText = buttonText, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + contentColor = MaterialTheme.colorScheme.onPrimaryContainer + ) + ) + ShareButton( + content = talerUri, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + contentColor = MaterialTheme.colorScheme.onPrimaryContainer + ) + ) + } } @Composable @@ -100,20 +128,21 @@ fun CopyToClipboardButton( content: String, modifier: Modifier = Modifier, buttonText: String = stringResource(R.string.copy), + colors: ButtonColors = ButtonDefaults.buttonColors(), ) { val context = LocalContext.current Button( modifier = modifier, + colors = colors, onClick = { copyToClipBoard(context, label, content) }, ) { - Row(verticalAlignment = Alignment.CenterVertically) { - Icon(Icons.Default.ContentCopy, stringResource(R.string.copy)) - Text( - modifier = Modifier.padding(start = 8.dp), - text = buttonText, - style = MaterialTheme.typography.body1, - ) - } + Icon( + Icons.Default.ContentCopy, + buttonText, + modifier = Modifier.size(ButtonDefaults.IconSize), + ) + Spacer(Modifier.size(ButtonDefaults.IconSpacing)) + Text(buttonText) } } |