taler-android

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

PaymentSuccessFragment.kt (5686B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2020 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.merchantpos.payment
     18 
     19 import android.os.Bundle
     20 import androidx.compose.foundation.layout.Arrangement
     21 import androidx.compose.foundation.layout.Box
     22 import androidx.compose.foundation.layout.BoxWithConstraints
     23 import androidx.compose.foundation.layout.Column
     24 import androidx.compose.foundation.layout.fillMaxSize
     25 import androidx.compose.foundation.layout.fillMaxWidth
     26 import androidx.compose.foundation.layout.heightIn
     27 import androidx.compose.foundation.layout.padding
     28 import androidx.compose.foundation.layout.size
     29 import androidx.compose.material3.Button
     30 import androidx.compose.material3.MaterialTheme
     31 import androidx.compose.material3.Text
     32 import androidx.compose.runtime.Composable
     33 import androidx.compose.ui.Alignment
     34 import androidx.compose.ui.Modifier
     35 import androidx.compose.ui.platform.ComposeView
     36 import androidx.compose.ui.platform.ViewCompositionStrategy
     37 import androidx.compose.ui.res.painterResource
     38 import androidx.compose.ui.res.stringResource
     39 import androidx.compose.ui.text.font.FontWeight
     40 import androidx.compose.ui.text.style.TextAlign
     41 import androidx.compose.ui.unit.dp
     42 import androidx.fragment.app.Fragment
     43 import net.taler.merchantpos.R
     44 import net.taler.merchantpos.MainActivity
     45 import net.taler.merchantpos.compose.PosTheme
     46 import androidx.compose.foundation.Image
     47 import androidx.compose.ui.graphics.ColorFilter
     48 
     49 class PaymentSuccessFragment : Fragment() {
     50 
     51     override fun onCreateView(
     52         inflater: android.view.LayoutInflater,
     53         container: android.view.ViewGroup?,
     54         savedInstanceState: Bundle?,
     55     ) = ComposeView(requireContext()).apply {
     56         setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
     57         setContent {
     58             PaymentSuccessScreen(
     59                 onContinue = {
     60                     (requireActivity() as MainActivity).apply {
     61                         navigateBack()
     62                         navigateBack()
     63                     }
     64                 },
     65             )
     66         }
     67     }
     68 }
     69 
     70 @Composable
     71 private fun PaymentSuccessScreen(
     72     onContinue: () -> Unit,
     73 ) {
     74     PosTheme {
     75         BoxWithConstraints(
     76             modifier = Modifier.fillMaxSize(),
     77         ) {
     78             val verticalPadding = (maxHeight * 0.045f).coerceIn(16.dp, 32.dp)
     79             val heroSpacing = (maxHeight * 0.035f).coerceIn(12.dp, 24.dp)
     80             val iconSize = (maxHeight * 0.22f).coerceIn(84.dp, 164.dp)
     81             val buttonMinHeight = (maxHeight * 0.11f).coerceIn(52.dp, 72.dp)
     82             val buttonWidthFraction = if (maxWidth < 600.dp) 0.78f else 0.6f
     83             val titleStyle = when {
     84                 maxHeight < 560.dp -> MaterialTheme.typography.titleMedium
     85                 maxHeight < 720.dp -> MaterialTheme.typography.titleLarge
     86                 else -> MaterialTheme.typography.headlineMedium
     87             }
     88 
     89             Column(
     90                 modifier = Modifier
     91                     .fillMaxSize()
     92                     .padding(vertical = verticalPadding, horizontal = 24.dp),
     93                 horizontalAlignment = Alignment.CenterHorizontally,
     94                 verticalArrangement = Arrangement.SpaceBetween,
     95             ) {
     96                 Box(
     97                     modifier = Modifier
     98                         .fillMaxWidth()
     99                         .weight(1f),
    100                     contentAlignment = Alignment.Center,
    101                 ) {
    102                     Column(
    103                         horizontalAlignment = Alignment.CenterHorizontally,
    104                         verticalArrangement = Arrangement.spacedBy(heroSpacing),
    105                     ) {
    106                         Image(
    107                             painter = painterResource(R.drawable.ic_check_circle),
    108                             contentDescription = null,
    109                             modifier = Modifier.size(iconSize),
    110                             colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primary),
    111                         )
    112                         Text(
    113                             text = stringResource(R.string.payment_received),
    114                             modifier = Modifier.fillMaxWidth(),
    115                             style = titleStyle,
    116                             fontWeight = FontWeight.SemiBold,
    117                             color = MaterialTheme.colorScheme.primary,
    118                             textAlign = TextAlign.Center,
    119                         )
    120                     }
    121                 }
    122                 Button(
    123                     onClick = onContinue,
    124                     modifier = Modifier
    125                         .fillMaxWidth(buttonWidthFraction)
    126                         .heightIn(min = buttonMinHeight),
    127                 ) {
    128                     Text(
    129                         text = stringResource(R.string.payment_back_button),
    130                         fontWeight = FontWeight.SemiBold,
    131                     )
    132                 }
    133             }
    134         }
    135     }
    136 }
    137 
    138 @Composable
    139 internal fun PaymentSuccessScreenContent() {
    140     PaymentSuccessScreen(onContinue = {})
    141 }