From ab77084575b76f9cbd517ff5817a2a5655133136 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 3 Jan 2023 12:41:07 -0300 Subject: [wallet] Add share button to Peer-Pull (and adapt to new API) #0007471 --- .../wallet/peer/OutgoingPullResultComposable.kt | 63 +++++----------------- .../main/java/net/taler/wallet/peer/PeerManager.kt | 2 + 2 files changed, 15 insertions(+), 50 deletions(-) (limited to 'wallet') diff --git a/wallet/src/main/java/net/taler/wallet/peer/OutgoingPullResultComposable.kt b/wallet/src/main/java/net/taler/wallet/peer/OutgoingPullResultComposable.kt index 2c4001f..72cf571 100644 --- a/wallet/src/main/java/net/taler/wallet/peer/OutgoingPullResultComposable.kt +++ b/wallet/src/main/java/net/taler/wallet/peer/OutgoingPullResultComposable.kt @@ -17,11 +17,8 @@ package net.taler.wallet.peer import android.content.res.Configuration.UI_MODE_NIGHT_YES -import androidx.compose.foundation.Image -import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ColumnScope -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size @@ -29,28 +26,21 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.Button import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.Icon -import androidx.compose.material.IconButton import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.material.Text -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.asImageBitmap -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import net.taler.common.QrCodeManager import net.taler.wallet.R import net.taler.wallet.backend.TalerErrorInfo -import net.taler.wallet.compose.copyToClipBoard +import net.taler.wallet.compose.QrCodeUriComposable +import net.taler.wallet.compose.TalerSurface import net.taler.wallet.compose.getQrCodeSize import org.json.JSONObject @@ -95,42 +85,15 @@ private fun ColumnScope.PeerPullCreatingComposable() { @Composable private fun ColumnScope.PeerPullResponseComposable(state: OutgoingResponse) { - val qrCodeSize = getQrCodeSize() - Image( - modifier = Modifier - .size(qrCodeSize) - .align(CenterHorizontally), - bitmap = state.qrCode.asImageBitmap(), - contentDescription = stringResource(id = R.string.button_scan_qr_code), - ) - Text( - modifier = Modifier.padding(horizontal = 16.dp), - style = MaterialTheme.typography.body1, - text = stringResource(id = R.string.receive_peer_invoice_uri), - ) - val scrollState = rememberScrollState() - Text( - modifier = Modifier - .horizontalScroll(scrollState) - .padding(16.dp), - fontFamily = FontFamily.Monospace, - style = MaterialTheme.typography.body1, - text = state.talerUri, - ) - val context = LocalContext.current - IconButton( - modifier = Modifier - .align(CenterHorizontally), - onClick = { copyToClipBoard(context, "Invoice", state.talerUri) }, + QrCodeUriComposable( + talerUri = state.talerUri, + clipBoardLabel = "Invoice", ) { - Row(verticalAlignment = Alignment.CenterVertically) { - Icon(Icons.Default.ContentCopy, stringResource(R.string.copy)) - Text( - modifier = Modifier.padding(start = 8.dp), - text = stringResource(R.string.copy), - style = MaterialTheme.typography.body1, - ) - } + Text( + modifier = Modifier.padding(horizontal = 16.dp), + style = MaterialTheme.typography.body1, + text = stringResource(id = R.string.receive_peer_invoice_uri), + ) } } @@ -154,10 +117,10 @@ fun PeerPullCreatingPreview() { } } -@Preview +@Preview(uiMode = UI_MODE_NIGHT_YES) @Composable fun PeerPullResponsePreview() { - Surface { + TalerSurface { val talerUri = "https://example.org/foo/bar/can/be/very/long/url/so/fit/it/on/screen" val response = OutgoingResponse(talerUri, QrCodeManager.makeQrCode(talerUri)) OutgoingPullResultComposable(response) {} @@ -167,7 +130,7 @@ fun PeerPullResponsePreview() { @Preview(widthDp = 720, uiMode = UI_MODE_NIGHT_YES) @Composable fun PeerPullResponseLandscapePreview() { - Surface { + TalerSurface { val talerUri = "https://example.org/foo/bar/can/be/very/long/url/so/fit/it/on/screen" val response = OutgoingResponse(talerUri, QrCodeManager.makeQrCode(talerUri)) OutgoingPullResultComposable(response) {} diff --git a/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt b/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt index 5f26119..e49f368 100644 --- a/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt +++ b/wallet/src/main/java/net/taler/wallet/peer/PeerManager.kt @@ -53,11 +53,13 @@ class PeerManager( fun initiatePullPayment(amount: Amount, summary: String, exchange: ExchangeItem) { _outgoingPullState.value = OutgoingCreating scope.launch(Dispatchers.IO) { + val expiry = Timestamp.fromMillis(System.currentTimeMillis() + DAYS.toMillis(3)) api.request("initiatePeerPullPayment", InitiatePeerPullPaymentResponse.serializer()) { put("exchangeBaseUrl", exchange.exchangeBaseUrl) put("partialContractTerms", JSONObject().apply { put("amount", amount.toJSONString()) put("summary", summary) + put("purse_expiration", JSONObject(Json.encodeToString(expiry))) }) }.onSuccess { val qrCode = QrCodeManager.makeQrCode(it.talerUri) -- cgit v1.2.3