From ce0cdd7d951c3a0d78627049a9dffcde9f6ccd0a Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 8 Sep 2024 21:19:47 +0200 Subject: [PATCH] Showing a loading indicator --- .../banking/ui/screens/ExportScreen.kt | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt index 8b94648..d22e33c 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt @@ -1,10 +1,8 @@ package net.codinux.banking.ui.screens -import androidx.compose.foundation.ScrollState -import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.selection.SelectionContainer -import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.runtime.* @@ -12,6 +10,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.style.TextAlign import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -25,6 +24,8 @@ import net.codinux.banking.ui.service.BankDataImporterAndExporter fun ExportScreen(onClosed: () -> Unit) { var transactions: Collection + var isLoadingExportedData by remember { mutableStateOf(true) } + var exportedDataText by remember { mutableStateOf("") } val importerExporter = BankDataImporterAndExporter() @@ -34,10 +35,13 @@ fun ExportScreen(onClosed: () -> Unit) { val coroutineScope = rememberCoroutineScope() coroutineScope.launch(Dispatchers.IOorDefault) { - transactions = DI.bankingService.getAllAccountTransactions() // a only very bit problematic: if in the meantime new transactions are retrieved, then this transactions property doesn't contain the newly retrieved transactions + transactions = DI.bankingService.getAllAccountTransactions() // only a bit problematic: if in the meantime new transactions are retrieved, then this transactions property doesn't contain the newly retrieved transactions + + val initiallyExportedData = importerExporter.exportTransactionsAsCsv(transactions, ',') withContext(Dispatchers.Main) { - exportedDataText = importerExporter.exportTransactionsAsCsv(transactions, ',') + exportedDataText = initiallyExportedData + isLoadingExportedData = false } } @@ -51,9 +55,17 @@ fun ExportScreen(onClosed: () -> Unit) { } } - Column(Modifier.verticalScroll(ScrollState(0), enabled = true).horizontalScroll(ScrollState(0), enabled = true)) { - SelectionContainer { - Text(exportedDataText, fontFamily = FontFamily.Monospace) + Column(Modifier.fillMaxSize().verticalScroll(ScrollState(0), enabled = true).horizontalScroll(ScrollState(0), enabled = true)) { + if (isLoadingExportedData == false) { + SelectionContainer { + Text(exportedDataText, fontFamily = FontFamily.Monospace) + } + } else { + Spacer(Modifier.weight(1f)) + + Text("Daten werden geladen ...", Modifier.fillMaxWidth(), textAlign = TextAlign.Center) // centering text does not work, no matter what i tried + + Spacer(Modifier.weight(1f)) } } }