Implemented selecting account for which to show MessageLog

This commit is contained in:
dankito 2024-10-15 12:52:52 +02:00
parent 0a46dd931f
commit f547b76c7b
1 changed files with 55 additions and 17 deletions

View File

@ -5,26 +5,45 @@ import androidx.compose.foundation.text.selection.SelectionContainer
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.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier 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 kotlinx.coroutines.Dispatchers import androidx.compose.ui.text.style.TextAlign
import kotlinx.coroutines.launch import androidx.compose.ui.unit.dp
import net.codinux.banking.ui.IOorDefault 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.Colors
import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.DI
import net.codinux.banking.ui.extensions.horizontalScroll import net.codinux.banking.ui.extensions.horizontalScroll
import net.codinux.banking.ui.extensions.verticalScroll import net.codinux.banking.ui.extensions.verticalScroll
import net.codinux.banking.ui.forms.Select
import net.codinux.banking.ui.model.Config.NewLine import net.codinux.banking.ui.model.Config.NewLine
@Composable @Composable
fun FeedbackScreen(onClosed: () -> Unit) { fun FeedbackScreen(onClosed: () -> Unit) {
val banks = DI.uiState.banks.collectAsState().value
val messageLog by remember { mutableStateOf(DI.bankingService.getMessageLog()) } val messageLog by remember { mutableStateOf(DI.bankingService.getMessageLog()) }
val displayedLogEntries by remember { derivedStateOf { messageLog.sortedBy { it.messageNumber } } } val accountsWithMessageLog: List<BankAccount?> by remember(messageLog) { derivedStateOf {
listOf<BankAccount?>(null) + messageLog.mapNotNull { it.account }.toSet().toList()
} }
var selectedAccount by remember { mutableStateOf<BankAccount?>(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) { val displayedLogEntriesText by remember(displayedLogEntries) {
derivedStateOf { displayedLogEntries.map { derivedStateOf { displayedLogEntries.map {
@ -34,24 +53,43 @@ fun FeedbackScreen(onClosed: () -> Unit) {
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
val coroutineScope = rememberCoroutineScope()
coroutineScope.launch(Dispatchers.IOorDefault) {
}
FullscreenViewBase("Feedback", onClosed = onClosed) { FullscreenViewBase("Feedback", onClosed = onClosed) {
Column(Modifier.fillMaxWidth()) { Column(Modifier.fillMaxWidth()) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { if (messageLog.isEmpty()) {
TextButton({ clipboardManager.setText(AnnotatedString(displayedLogEntriesText))}) { Row(Modifier.fillMaxSize().padding(24.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) {
Text("Kopieren", color = Colors.CodinuxSecondaryColor) 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()) { Text(account?.displayName ?: "")
SelectionContainer(modifier = Modifier.fillMaxSize()) { }
Text(displayedLogEntriesText, fontFamily = FontFamily.Monospace) },
)
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)
}
} }
} }
} }