aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/compose
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/compose')
-rw-r--r--wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt45
-rw-r--r--wallet/src/main/java/net/taler/wallet/compose/ShareButton.kt71
-rw-r--r--wallet/src/main/java/net/taler/wallet/compose/Utils.kt11
3 files changed, 117 insertions, 10 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..5359f1a 100644
--- a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt
@@ -21,13 +21,17 @@ 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.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.ButtonColors
+import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
@@ -36,11 +40,13 @@ import androidx.compose.material.icons.filled.ContentCopy
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.Color
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 +64,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),
)
@@ -78,12 +90,23 @@ fun ColumnScope.QrCodeUriComposable(
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(backgroundColor = Color.Transparent)
+ )
+ ShareButton(
+ content = talerUri,
+ colors = ButtonDefaults.buttonColors(backgroundColor = Color.Transparent)
+ )
+ }
}
@Composable
@@ -100,14 +123,16 @@ 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))
+ Icon(Icons.Default.ContentCopy, buttonText)
Text(
modifier = Modifier.padding(start = 8.dp),
text = buttonText,
diff --git a/wallet/src/main/java/net/taler/wallet/compose/ShareButton.kt b/wallet/src/main/java/net/taler/wallet/compose/ShareButton.kt
new file mode 100644
index 0000000..0ac7048
--- /dev/null
+++ b/wallet/src/main/java/net/taler/wallet/compose/ShareButton.kt
@@ -0,0 +1,71 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2023 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.compose
+
+import android.content.Intent
+import android.content.Intent.ACTION_SEND
+import android.content.Intent.EXTRA_TEXT
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material.Button
+import androidx.compose.material.ButtonColors
+import androidx.compose.material.ButtonDefaults
+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.Share
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment.Companion.CenterVertically
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
+import androidx.core.content.ContextCompat.startActivity
+import net.taler.wallet.R
+
+@Composable
+fun ShareButton(
+ content: String,
+ modifier: Modifier = Modifier,
+ buttonText: String = stringResource(R.string.share),
+ colors: ButtonColors = ButtonDefaults.buttonColors(),
+) {
+ val context = LocalContext.current
+ Button(
+ modifier = modifier,
+ colors = colors,
+ onClick = {
+ val sendIntent: Intent = Intent().apply {
+ action = ACTION_SEND
+ putExtra(EXTRA_TEXT, content)
+ type = "text/plain"
+ }
+ val shareIntent = Intent.createChooser(sendIntent, null)
+ startActivity(context, shareIntent, null)
+ },
+ ) {
+ Row(verticalAlignment = CenterVertically) {
+ Icon(Icons.Default.Share, buttonText)
+ Text(
+ modifier = Modifier.padding(start = 8.dp),
+ text = buttonText,
+ style = MaterialTheme.typography.body1,
+ )
+ }
+ }
+}
diff --git a/wallet/src/main/java/net/taler/wallet/compose/Utils.kt b/wallet/src/main/java/net/taler/wallet/compose/Utils.kt
index 21b04ed..8e3a032 100644
--- a/wallet/src/main/java/net/taler/wallet/compose/Utils.kt
+++ b/wallet/src/main/java/net/taler/wallet/compose/Utils.kt
@@ -16,6 +16,7 @@
package net.taler.wallet.compose
+import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
@@ -24,6 +25,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.flowWithLifecycle
+import com.google.accompanist.themeadapter.material.MdcTheme
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlin.coroutines.CoroutineContext
@@ -51,3 +53,12 @@ fun <T : R, R> Flow<T>.collectAsStateLifecycleAware(
fun <T> StateFlow<T>.collectAsStateLifecycleAware(
context: CoroutineContext = EmptyCoroutineContext,
): State<T> = collectAsStateLifecycleAware(initial = value, context = context)
+
+@Composable
+fun TalerSurface(content: @Composable () -> Unit) {
+ MdcTheme {
+ Surface {
+ content()
+ }
+ }
+}