taler-android

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

DonauStatementComposable.kt (5388B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2025 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.donau
     18 
     19 import androidx.compose.foundation.layout.Column
     20 import androidx.compose.foundation.layout.fillMaxSize
     21 import androidx.compose.foundation.layout.padding
     22 import androidx.compose.foundation.rememberScrollState
     23 import androidx.compose.foundation.verticalScroll
     24 import androidx.compose.material3.MaterialTheme
     25 import androidx.compose.material3.ScrollableTabRow
     26 import androidx.compose.material3.Tab
     27 import androidx.compose.material3.Text
     28 import androidx.compose.runtime.Composable
     29 import androidx.compose.runtime.getValue
     30 import androidx.compose.runtime.mutableIntStateOf
     31 import androidx.compose.runtime.remember
     32 import androidx.compose.runtime.setValue
     33 import androidx.compose.ui.Alignment.Companion.CenterHorizontally
     34 import androidx.compose.ui.Modifier
     35 import androidx.compose.ui.res.stringResource
     36 import androidx.compose.ui.text.style.TextAlign
     37 import androidx.compose.ui.tooling.preview.Preview
     38 import androidx.compose.ui.unit.dp
     39 import net.taler.common.Amount
     40 import net.taler.wallet.BottomInsetsSpacer
     41 import net.taler.wallet.R
     42 import net.taler.wallet.compose.QrCodeParams
     43 import net.taler.wallet.compose.QrCodeUriComposable
     44 import net.taler.wallet.compose.TalerSurface
     45 import net.taler.wallet.transactions.AmountType
     46 import net.taler.wallet.transactions.TransactionAmountComposable
     47 import net.taler.wallet.transactions.TransactionInfoComposable
     48 
     49 @Composable
     50 fun DonauStatementComposable(
     51     statements: List<DonauStatement>,
     52     selectedIndex: Int,
     53     modifier: Modifier = Modifier,
     54     onSelectIndex: (index: Int) -> Unit,
     55 ) {
     56     val statement = remember(selectedIndex) {
     57         statements[selectedIndex]
     58     }
     59 
     60     // TODO: create common instruction + QR composable
     61     Column(
     62         modifier = modifier
     63             .fillMaxSize()
     64             .verticalScroll(rememberScrollState()),
     65         horizontalAlignment = CenterHorizontally,
     66     ) {
     67         // only show tab row if more than one year
     68         if (statements.size > 1) ScrollableTabRow(
     69             selectedTabIndex = selectedIndex,
     70             edgePadding = 8.dp,
     71         ) {
     72             statements.forEachIndexed { i, statement ->
     73                 Tab(
     74                     selected = selectedIndex == i,
     75                     onClick = { onSelectIndex(i) },
     76                     text = {
     77                         Text(statement.year.toString())
     78                     }
     79                 )
     80             }
     81         }
     82 
     83         Text(
     84             modifier = Modifier.padding(16.dp),
     85             style = MaterialTheme.typography.titleLarge,
     86             text = stringResource(R.string.donau_statement_instruction),
     87             textAlign = TextAlign.Center,
     88         )
     89 
     90         QrCodeUriComposable(
     91             modifier = Modifier
     92                 .padding(horizontal = 16.dp)
     93                 .padding(bottom = 8.dp),
     94             qrData = statement.uri,
     95             clipboardLabel = "Donau",
     96             buttonText = stringResource(id = R.string.copy),
     97             params = QrCodeParams.Taler,
     98             shareAsQrCode = true,
     99         )
    100 
    101         TransactionAmountComposable(
    102             label = stringResource(id = R.string.amount_total),
    103             amount = statement.total,
    104             amountType = AmountType.Neutral,
    105         )
    106 
    107         TransactionInfoComposable(
    108             label = stringResource(R.string.donau_statement_legal_domain),
    109             info = statement.legalDomain,
    110         )
    111 
    112         val host = statement.host
    113         if (host != null) TransactionInfoComposable(
    114             label = stringResource(R.string.donau_statement_tax_authority),
    115             info = host,
    116             marquee = true,
    117         )
    118 
    119         BottomInsetsSpacer()
    120     }
    121 }
    122 
    123 @Preview
    124 @Composable
    125 fun DonauStatementComposablePreview() {
    126     TalerSurface {
    127         var selectedIndex by remember { mutableIntStateOf(0) }
    128         DonauStatementComposable(
    129             statements = listOf(
    130                 DonauStatement(
    131                     total = Amount.fromJSONString("KUDOS:0.1"),
    132                     year = 2025,
    133                     legalDomain = "Gnuland",
    134                     uri = "donau://donau.test.taler.net/",
    135                     donationStatementSig = "123456",
    136                     donauPub = "123456",
    137                 ),
    138                 DonauStatement(
    139                     total = Amount.fromJSONString("KUDOS:100.0"),
    140                     year = 2024,
    141                     legalDomain = "Gnuland",
    142                     uri = "donau://donau.test.taler.net/",
    143                     donationStatementSig = "123456",
    144                     donauPub = "123456",
    145                 ),
    146             ),
    147             selectedIndex = selectedIndex,
    148             onSelectIndex = { selectedIndex = it },
    149         )
    150     }
    151 }