Implemented selecting account for which to show MessageLog
This commit is contained in:
parent
0a46dd931f
commit
f547b76c7b
|
@ -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<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) {
|
||||
derivedStateOf { displayedLogEntries.map {
|
||||
|
@ -34,27 +53,46 @@ 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) {
|
||||
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))
|
||||
|
||||
Text(account?.displayName ?: "")
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Spacer(Modifier.weight(0.1f))
|
||||
|
||||
TextButton({ clipboardManager.setText(AnnotatedString(displayedLogEntriesText))}) {
|
||||
Text("Kopieren", color = Colors.CodinuxSecondaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
Column(Modifier.verticalScroll().horizontalScroll()) {
|
||||
Column(Modifier.verticalScroll().horizontalScroll().padding(top = 8.dp)) {
|
||||
SelectionContainer(modifier = Modifier.fillMaxSize()) {
|
||||
Text(displayedLogEntriesText, fontFamily = FontFamily.Monospace)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue