Implemented updating BankAccess properties
This commit is contained in:
parent
a88ddbdd16
commit
3c2eb3d4d7
|
@ -26,6 +26,8 @@ interface BankingRepository {
|
||||||
|
|
||||||
suspend fun persistBank(bank: BankAccess): BankAccessEntity
|
suspend fun persistBank(bank: BankAccess): BankAccessEntity
|
||||||
|
|
||||||
|
suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?)
|
||||||
|
|
||||||
suspend fun deleteBank(bank: BankAccessEntity)
|
suspend fun deleteBank(bank: BankAccessEntity)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,10 @@ class InMemoryBankingRepository(
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun deleteBank(bank: BankAccessEntity) {
|
override suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
this.banks.remove(bank)
|
this.banks.remove(bank)
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,22 @@ open class SqliteBankingRepository : BankingRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, userSetDisplayName: String?) {
|
||||||
|
bankQueries.transaction {
|
||||||
|
if (bank.loginName != loginName) {
|
||||||
|
bankQueries.updateBankLoginName(loginName, bank.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bank.password != password) {
|
||||||
|
bankQueries.updateBankPassword(password, bank.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bank.userSetDisplayName != userSetDisplayName) {
|
||||||
|
bankQueries.updateBankUserSetDisplayName(userSetDisplayName, bank.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun deleteBank(bank: BankAccessEntity) {
|
override suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
bankQueries.transaction {
|
bankQueries.transaction {
|
||||||
accountTransactionQueries.deleteTransactionsByBankId(bankId = bank.id)
|
accountTransactionQueries.deleteTransactionsByBankId(bankId = bank.id)
|
||||||
|
|
|
@ -79,6 +79,22 @@ SELECT BankAccess.*
|
||||||
FROM BankAccess;
|
FROM BankAccess;
|
||||||
|
|
||||||
|
|
||||||
|
updateBankLoginName:
|
||||||
|
UPDATE BankAccess
|
||||||
|
SET loginName = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
updateBankPassword:
|
||||||
|
UPDATE BankAccess
|
||||||
|
SET password = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
updateBankUserSetDisplayName:
|
||||||
|
UPDATE BankAccess
|
||||||
|
SET userSetDisplayName = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
|
||||||
deleteBank {
|
deleteBank {
|
||||||
DELETE FROM TanMethod
|
DELETE FROM TanMethod
|
||||||
WHERE bankId = :bankId;
|
WHERE bankId = :bankId;
|
||||||
|
|
|
@ -28,15 +28,22 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
|
|
||||||
var showDeleteBankAccessConfirmationDialog by remember { mutableStateOf(false) }
|
var showDeleteBankAccessConfirmationDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val hasDataChanged by remember(enteredBankName, enteredLoginName, enteredPassword) {
|
||||||
|
|
||||||
val hasDataChanged by remember(enteredBankName) {
|
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
(enteredBankName != bank.bankName && (bank.userSetDisplayName == null || enteredBankName != bank.userSetDisplayName))
|
(enteredBankName != bank.bankName && (bank.userSetDisplayName == null || enteredBankName != bank.userSetDisplayName))
|
||||||
|| enteredLoginName != bank.loginName || enteredPassword != bank.password
|
|| (enteredLoginName != bank.loginName && enteredLoginName.isNotBlank())
|
||||||
|
|| (enteredPassword != bank.password && enteredPassword.isNotBlank())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
|
||||||
|
fun saveChanges() {
|
||||||
|
coroutineScope.launch {
|
||||||
|
DI.bankingService.updateBank(bank, enteredLoginName, enteredPassword, enteredBankName.takeUnless { it.isBlank() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (showDeleteBankAccessConfirmationDialog) {
|
if (showDeleteBankAccessConfirmationDialog) {
|
||||||
ConfirmDialog(
|
ConfirmDialog(
|
||||||
|
@ -53,7 +60,14 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FullscreenViewBase(bank.displayName, onClosed = onClosed) {
|
FullscreenViewBase(
|
||||||
|
bank.displayName,
|
||||||
|
confirmButtonTitle = "Speichern",
|
||||||
|
confirmButtonEnabled = hasDataChanged,
|
||||||
|
showDismissButton = true,
|
||||||
|
onConfirm = { saveChanges() },
|
||||||
|
onClosed = onClosed
|
||||||
|
) {
|
||||||
Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) {
|
Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) {
|
||||||
Column {
|
Column {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
|
|
|
@ -23,7 +23,10 @@ fun FullscreenViewBase(
|
||||||
title: String,
|
title: String,
|
||||||
confirmButtonTitle: String = "OK",
|
confirmButtonTitle: String = "OK",
|
||||||
confirmButtonEnabled: Boolean = true,
|
confirmButtonEnabled: Boolean = true,
|
||||||
|
dismissButtonTitle: String = "Abbrechen",
|
||||||
|
showDismissButton: Boolean = false,
|
||||||
showButtonBar: Boolean = true,
|
showButtonBar: Boolean = true,
|
||||||
|
onConfirm: (() -> Unit)? = null,
|
||||||
onClosed: () -> Unit,
|
onClosed: () -> Unit,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
|
@ -49,16 +52,18 @@ fun FullscreenViewBase(
|
||||||
|
|
||||||
if (showButtonBar) {
|
if (showButtonBar) {
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||||
// TextButton(onClick = onClosed, Modifier.width(Style.DialogButtonWidth)) {
|
if (showDismissButton) {
|
||||||
// Text("Abbrechen", color = Colors.CodinuxSecondaryColor)
|
TextButton(onClick = onClosed, Modifier.weight(1f)) {
|
||||||
// }
|
Text(dismissButtonTitle, color = Colors.CodinuxSecondaryColor)
|
||||||
//
|
}
|
||||||
// Spacer(Modifier.width(8.dp))
|
|
||||||
|
Spacer(Modifier.width(8.dp))
|
||||||
|
}
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.weight(1f),
|
||||||
enabled = confirmButtonEnabled,
|
enabled = confirmButtonEnabled,
|
||||||
onClick = { /* onConfirm?.invoke() ?: */ onClosed() }
|
onClick = { onConfirm?.invoke(); onClosed() }
|
||||||
) {
|
) {
|
||||||
Text(confirmButtonTitle, color = Colors.CodinuxSecondaryColor, textAlign = TextAlign.Center)
|
Text(confirmButtonTitle, color = Colors.CodinuxSecondaryColor, textAlign = TextAlign.Center)
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ class BankingService(
|
||||||
updateOnChanges(uiSettings)
|
updateOnChanges(uiSettings)
|
||||||
|
|
||||||
|
|
||||||
uiState.banks.value = getAllBanks()
|
updateBanksInUi(getAllBanks())
|
||||||
|
|
||||||
uiState.transactions.value = getAllAccountTransactionsAsViewModel()
|
uiState.transactions.value = getAllAccountTransactionsAsViewModel()
|
||||||
uiState.holdings.value = uiState.banks.value.flatMap { it.accounts }.flatMap { it.holdings }
|
uiState.holdings.value = uiState.banks.value.flatMap { it.accounts }.flatMap { it.holdings }
|
||||||
|
@ -93,13 +93,33 @@ class BankingService(
|
||||||
|
|
||||||
fun getAllBanks() = bankingRepository.getAllBanks()
|
fun getAllBanks() = bankingRepository.getAllBanks()
|
||||||
|
|
||||||
|
suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?) {
|
||||||
|
try {
|
||||||
|
bankingRepository.updateBank(bank, loginName, password, bankName)
|
||||||
|
|
||||||
|
if (bank.loginName != loginName) {
|
||||||
|
bank.loginName = loginName
|
||||||
|
}
|
||||||
|
if (bank.password != password) {
|
||||||
|
bank.password = password
|
||||||
|
}
|
||||||
|
if (bank.userSetDisplayName != bankName) {
|
||||||
|
bank.userSetDisplayName = bankName
|
||||||
|
}
|
||||||
|
|
||||||
|
updateBanksInUi(uiState.banks.value.toList()) // update displayed banks to reflect new value(s)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
// showAndLogError("Could not update bank $bank", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun deleteBank(bank: BankAccessEntity) {
|
suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
try {
|
try {
|
||||||
bankingRepository.deleteBank(bank)
|
bankingRepository.deleteBank(bank)
|
||||||
|
|
||||||
uiState.transactions.value = uiState.transactions.value.filterNot { it.bankId == bank.id }
|
uiState.transactions.value = uiState.transactions.value.filterNot { it.bankId == bank.id }
|
||||||
uiState.holdings.value = uiState.holdings.value.filterNot { it.bankId == bank.id }
|
uiState.holdings.value = uiState.holdings.value.filterNot { it.bankId == bank.id }
|
||||||
uiState.banks.value = uiState.banks.value.toMutableList().also { it.remove(bank) }
|
updateBanksInUi(uiState.banks.value.toMutableList().also { it.remove(bank) })
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
log.error(e) { "Could not delete bank ${bank.displayName}" }
|
log.error(e) { "Could not delete bank ${bank.displayName}" }
|
||||||
}
|
}
|
||||||
|
@ -157,9 +177,7 @@ class BankingService(
|
||||||
|
|
||||||
log.info { "Saved bank $newBankEntity with ${newBankEntity.accounts.flatMap { it.bookedTransactions }.size} transactions" }
|
log.info { "Saved bank $newBankEntity with ${newBankEntity.accounts.flatMap { it.bookedTransactions }.size} transactions" }
|
||||||
|
|
||||||
val banks = uiState.banks.value.toMutableList()
|
updateBanksInUi(uiState.banks.value.toMutableList().also { it.add(newBankEntity) })
|
||||||
banks.add(newBankEntity)
|
|
||||||
uiState.banks.value = banks
|
|
||||||
|
|
||||||
updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactions })
|
updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactions })
|
||||||
updateHoldingsInUi(newBankEntity.accounts.flatMap { it.holdings }, emptyList())
|
updateHoldingsInUi(newBankEntity.accounts.flatMap { it.holdings }, emptyList())
|
||||||
|
@ -264,6 +282,11 @@ class BankingService(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun updateBanksInUi(banks: List<BankAccessEntity>) {
|
||||||
|
uiState.banks.value = banks
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateTransactionsInUi(addedTransactions: List<AccountTransactionEntity>): List<AccountTransactionViewModel> {
|
private fun updateTransactionsInUi(addedTransactions: List<AccountTransactionEntity>): List<AccountTransactionViewModel> {
|
||||||
val transactionsViewModel = addedTransactions.map { AccountTransactionViewModel(it) }
|
val transactionsViewModel = addedTransactions.map { AccountTransactionViewModel(it) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue