Showing a loading indicator
This commit is contained in:
parent
9c2653944d
commit
ce0cdd7d95
|
@ -1,10 +1,8 @@
|
||||||
package net.codinux.banking.ui.screens
|
package net.codinux.banking.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.ScrollState
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.horizontalScroll
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.TextButton
|
import androidx.compose.material.TextButton
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
@ -12,6 +10,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
@ -25,6 +24,8 @@ import net.codinux.banking.ui.service.BankDataImporterAndExporter
|
||||||
fun ExportScreen(onClosed: () -> Unit) {
|
fun ExportScreen(onClosed: () -> Unit) {
|
||||||
var transactions: Collection<AccountTransactionEntity>
|
var transactions: Collection<AccountTransactionEntity>
|
||||||
|
|
||||||
|
var isLoadingExportedData by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
var exportedDataText by remember { mutableStateOf("") }
|
var exportedDataText by remember { mutableStateOf("") }
|
||||||
|
|
||||||
val importerExporter = BankDataImporterAndExporter()
|
val importerExporter = BankDataImporterAndExporter()
|
||||||
|
@ -34,10 +35,13 @@ fun ExportScreen(onClosed: () -> Unit) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IOorDefault) {
|
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) {
|
withContext(Dispatchers.Main) {
|
||||||
exportedDataText = importerExporter.exportTransactionsAsCsv(transactions, ',')
|
exportedDataText = initiallyExportedData
|
||||||
|
isLoadingExportedData = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +55,18 @@ fun ExportScreen(onClosed: () -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(Modifier.verticalScroll(ScrollState(0), enabled = true).horizontalScroll(ScrollState(0), enabled = true)) {
|
Column(Modifier.fillMaxSize().verticalScroll(ScrollState(0), enabled = true).horizontalScroll(ScrollState(0), enabled = true)) {
|
||||||
|
if (isLoadingExportedData == false) {
|
||||||
SelectionContainer {
|
SelectionContainer {
|
||||||
Text(exportedDataText, fontFamily = FontFamily.Monospace)
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue