From f547b76c7b1a98f5ae2dc15518a2f99ca4b28c92 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 12:52:52 +0200 Subject: [PATCH] Implemented selecting account for which to show MessageLog --- .../banking/ui/screens/FeedbackScreen.kt | 72 ++++++++++++++----- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FeedbackScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FeedbackScreen.kt index 743dcc9..52333c1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FeedbackScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/FeedbackScreen.kt @@ -5,26 +5,45 @@ import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.runtime.* +import androidx.compose.ui.Alignment 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 kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import net.codinux.banking.ui.IOorDefault +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import net.codinux.banking.client.model.BankAccount +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.ui.composables.BankIcon import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.extensions.horizontalScroll import net.codinux.banking.ui.extensions.verticalScroll +import net.codinux.banking.ui.forms.Select import net.codinux.banking.ui.model.Config.NewLine @Composable fun FeedbackScreen(onClosed: () -> Unit) { + val banks = DI.uiState.banks.collectAsState().value + val messageLog by remember { mutableStateOf(DI.bankingService.getMessageLog()) } - val displayedLogEntries by remember { derivedStateOf { messageLog.sortedBy { it.messageNumber } } } + val accountsWithMessageLog: List by remember(messageLog) { derivedStateOf { + listOf(null) + messageLog.mapNotNull { it.account }.toSet().toList() + } } + + var selectedAccount by remember { mutableStateOf(null) } + + val bankOfSelectedAccount by remember(selectedAccount) { + // TODO: MessageLogEntries of added accounts contain a BankAccount instead of a BankAccountEntity object + derivedStateOf { banks.firstOrNull { it.id == (selectedAccount as? BankAccountEntity)?.bankId } } + } + + val displayedLogEntries by remember(messageLog, selectedAccount) { derivedStateOf { + messageLog.filter { selectedAccount == null || it.account == selectedAccount }.sortedBy { it.messageNumber } + } } val displayedLogEntriesText by remember(displayedLogEntries) { derivedStateOf { displayedLogEntries.map { @@ -34,24 +53,43 @@ fun FeedbackScreen(onClosed: () -> Unit) { val clipboardManager = LocalClipboardManager.current - val coroutineScope = rememberCoroutineScope() - - coroutineScope.launch(Dispatchers.IOorDefault) { - - } - FullscreenViewBase("Feedback", onClosed = onClosed) { Column(Modifier.fillMaxWidth()) { - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - TextButton({ clipboardManager.setText(AnnotatedString(displayedLogEntriesText))}) { - Text("Kopieren", color = Colors.CodinuxSecondaryColor) + if (messageLog.isEmpty()) { + Row(Modifier.fillMaxSize().padding(24.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) { + Text("Sie haben noch keine Aktion wie das Abrufen der Kontoumsätze ausgeführt, deshalb gibt es noch kein Nachrichtenprotokoll zu diesen Aktionen", textAlign = TextAlign.Center) } - } + } else { + Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { + Select( + "Konto", + accountsWithMessageLog, + selectedAccount, + { account -> selectedAccount = account }, + { account -> account?.displayName ?: "Alle Konten" }, + Modifier.weight(0.9f), + leadingIcon = bankOfSelectedAccount?.let { { BankIcon(bankOfSelectedAccount) } }, + dropDownItemContent = { account -> + Row(verticalAlignment = Alignment.CenterVertically) { + BankIcon(banks.firstOrNull { it.id == (account as? BankAccountEntity)?.bankId }, Modifier.padding(end = 6.dp)) - Column(Modifier.verticalScroll().horizontalScroll()) { - SelectionContainer(modifier = Modifier.fillMaxSize()) { - Text(displayedLogEntriesText, fontFamily = FontFamily.Monospace) + Text(account?.displayName ?: "") + } + }, + ) + + Spacer(Modifier.weight(0.1f)) + + TextButton({ clipboardManager.setText(AnnotatedString(displayedLogEntriesText))}) { + Text("Kopieren", color = Colors.CodinuxSecondaryColor) + } + } + + Column(Modifier.verticalScroll().horizontalScroll().padding(top = 8.dp)) { + SelectionContainer(modifier = Modifier.fillMaxSize()) { + Text(displayedLogEntriesText, fontFamily = FontFamily.Monospace) + } } } }