DonauStatementScreen.kt (3435B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2026 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.fillMaxSize 20 import androidx.compose.foundation.layout.padding 21 import androidx.compose.material3.Text 22 import androidx.compose.runtime.Composable 23 import androidx.compose.runtime.LaunchedEffect 24 import androidx.compose.runtime.getValue 25 import androidx.compose.runtime.livedata.observeAsState 26 import androidx.compose.runtime.mutableIntStateOf 27 import androidx.compose.runtime.saveable.rememberSaveable 28 import androidx.compose.runtime.setValue 29 import androidx.compose.ui.Modifier 30 import androidx.compose.ui.res.stringResource 31 import net.taler.wallet.R 32 import net.taler.wallet.compose.EmptyComposable 33 import net.taler.wallet.compose.ErrorComposable 34 import net.taler.wallet.compose.GlobalScaffold 35 import net.taler.wallet.compose.LoadingScreen 36 import net.taler.wallet.compose.TalerSurface 37 import net.taler.wallet.compose.collectAsStateLifecycleAware 38 import net.taler.wallet.main.MainViewModel 39 40 @Composable 41 fun DonauStatementScreen( 42 model: MainViewModel, 43 host: String, 44 onNavigateBack: () -> Unit, 45 ) { 46 val donauManager = model.donauManager 47 val status by donauManager.donauStatementsStatus.collectAsStateLifecycleAware() 48 val devMode by model.devMode.observeAsState(false) 49 50 LaunchedEffect(host) { 51 donauManager.getDonauStatements(host) 52 } 53 54 TalerSurface { 55 GlobalScaffold( 56 model = model, 57 modifier = Modifier.fillMaxSize(), 58 onNavigateBack = onNavigateBack, 59 title = { Text(stringResource(R.string.donau_statement_title)) }, 60 ) { paddingValues -> 61 when (val s = status) { 62 is GetDonauStatementsStatus.None, 63 is GetDonauStatementsStatus.Loading -> LoadingScreen(Modifier.padding(paddingValues)) 64 65 is GetDonauStatementsStatus.Error -> ErrorComposable( 66 error = s.error, 67 modifier = Modifier 68 .fillMaxSize() 69 .padding(paddingValues), 70 devMode = devMode, 71 ) 72 73 is GetDonauStatementsStatus.Success -> if (s.statements.isEmpty()) { 74 EmptyComposable(Modifier.padding(paddingValues)) 75 } else { 76 var selectedIndex by rememberSaveable { mutableIntStateOf(0) } 77 DonauStatementComposable( 78 modifier = Modifier.padding(paddingValues), 79 statements = s.statements, 80 selectedIndex = selectedIndex, 81 ) { index -> 82 selectedIndex = index 83 } 84 } 85 } 86 } 87 } 88 }