taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

PaytoQrCard.kt (3094B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2024 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.wallet.transfer
     18 
     19 import androidx.compose.foundation.layout.ColumnScope
     20 import androidx.compose.foundation.layout.Spacer
     21 import androidx.compose.foundation.layout.height
     22 import androidx.compose.material3.MaterialTheme
     23 import androidx.compose.material3.Text
     24 import androidx.compose.runtime.Composable
     25 import androidx.compose.ui.Modifier
     26 import androidx.compose.ui.platform.LocalContext
     27 import androidx.compose.ui.res.stringResource
     28 import androidx.compose.ui.unit.dp
     29 import androidx.core.content.ContextCompat
     30 import net.taler.lib.android.QrLogoSize
     31 import net.taler.wallet.R
     32 import net.taler.wallet.compose.ExpandableCard
     33 import net.taler.wallet.compose.QrCodeParams
     34 import net.taler.wallet.compose.QrCodeUriComposable
     35 import net.taler.wallet.withdraw.QrCodeSpec
     36 import net.taler.wallet.withdraw.QrCodeSpec.Type.EpcQr
     37 import net.taler.wallet.withdraw.QrCodeSpec.Type.SPC
     38 
     39 @Composable
     40 fun ColumnScope.PaytoQrCode(
     41     modifier: Modifier = Modifier,
     42     qrCode: QrCodeSpec,
     43 ) {
     44     val context = LocalContext.current
     45     QrCodeUriComposable(
     46         modifier = modifier,
     47         qrData = qrCode.qrContent,
     48         clipboardLabel = getQrCodeLabel(qrCode),
     49         showContents = true,
     50         shareAsQrCode = true,
     51         params = when(qrCode.type) {
     52             SPC -> QrCodeParams.Custom(
     53                 centerLogoSize = QrLogoSize.SMALL,
     54                 centerLogo = when (qrCode.type) {
     55                     SPC -> ContextCompat.getDrawable(context, R.drawable.ic_swiss_qr)
     56                     else -> null
     57                 },
     58             )
     59 
     60             EpcQr -> QrCodeParams.Custom()
     61             else -> QrCodeParams.Custom()
     62         },
     63     )
     64 }
     65 
     66 @Composable
     67 fun PaytoQrCard(
     68     expanded: Boolean,
     69     setExpanded: (expanded: Boolean) -> Unit,
     70     qrCode: QrCodeSpec,
     71 ) {
     72     ExpandableCard(
     73         expanded = expanded,
     74         setExpanded = setExpanded,
     75         header = {
     76             Text(getQrCodeLabel(qrCode),
     77                 style = MaterialTheme.typography.titleMedium)
     78         },
     79         content = {
     80             PaytoQrCode(qrCode = qrCode)
     81             Spacer(Modifier.height(8.dp))
     82         },
     83     )
     84 }
     85 
     86 @Composable
     87 fun getQrCodeLabel(qr: QrCodeSpec) = when(qr.type) {
     88     EpcQr -> stringResource(R.string.withdraw_manual_qr_epc)
     89     SPC -> stringResource(R.string.withdraw_manual_qr_spc)
     90     else -> stringResource(R.string.withdraw_manual_qr_unknown)
     91 }