Implemented passing only new transactions to persister.saveOrUpdateAccountTransactions(). Had to call saveOrUpdateAccountTransactions() therefore also in receivedAccountsTransactionChunk listener

This commit is contained in:
dankito 2020-09-16 15:12:17 +02:00
parent 0e0a7b5207
commit 28537668ff
2 changed files with 21 additions and 10 deletions

View File

@ -54,6 +54,9 @@ interface IAccountTransaction {
var technicalId: String var technicalId: String
open val transactionIdentifier: String
get() = buildTransactionIdentifier()
val showOtherPartyName: Boolean val showOtherPartyName: Boolean
get() = otherPartyName.isNullOrBlank() == false /* && type != "ENTGELTABSCHLUSS" && type != "AUSZAHLUNG" */ // TODO get() = otherPartyName.isNullOrBlank() == false /* && type != "ENTGELTABSCHLUSS" && type != "AUSZAHLUNG" */ // TODO

View File

@ -360,25 +360,35 @@ open class BankingPresenter(
protected open fun receivedAccountsTransactionChunk(bankAccount: TypedBankAccount, accountTransactionsChunk: List<IAccountTransaction>) { protected open fun receivedAccountsTransactionChunk(bankAccount: TypedBankAccount, accountTransactionsChunk: List<IAccountTransaction>) {
if (accountTransactionsChunk.isNotEmpty()) { if (accountTransactionsChunk.isNotEmpty()) {
bankAccount.addBookedTransactions(accountTransactionsChunk) asyncRunner.runAsync { // don't block retrieving next chunk by blocked saving to db / json
updateAccountTransactions(bankAccount, accountTransactionsChunk)
callRetrievedAccountTransactionsResponseListener(GetTransactionsResponse(bankAccount, true, null, accountTransactionsChunk)) callRetrievedAccountTransactionsResponseListener(GetTransactionsResponse(bankAccount, true, null, accountTransactionsChunk))
}
} }
} }
protected open fun updateAccountTransactionsAndBalances(response: GetTransactionsResponse) { protected open fun updateAccountTransactionsAndBalances(response: GetTransactionsResponse) {
val bankAccount = response.bankAccount val bankAccount = response.bankAccount
bankAccount.addBookedTransactions(response.bookedTransactions) updateAccountTransactions(bankAccount, response.bookedTransactions, response.unbookedTransactions)
bankAccount.addUnbookedTransactions(response.unbookedTransactions)
response.balance?.let { response.balance?.let {
updateBalance(bankAccount, it) updateBalance(bankAccount, it)
} }
}
persistAccountTransactionsOffUiThread(bankAccount, response.bookedTransactions, response.unbookedTransactions) protected open fun updateAccountTransactions(bankAccount: TypedBankAccount, bookedTransactions: List<IAccountTransaction>, unbookedTransactions: List<Any>? = null) {
val knownAccountTransactions = bankAccount.bookedTransactions.map { it.transactionIdentifier }
val newBookedTransactions = bookedTransactions.filterNot { knownAccountTransactions.contains(it.transactionIdentifier) }
bankAccount.addBookedTransactions(newBookedTransactions)
unbookedTransactions?.let {
bankAccount.addUnbookedTransactions(unbookedTransactions)
}
persistAccountTransactionsOffUiThread(bankAccount, newBookedTransactions)
} }
protected open fun updateBalance(bankAccount: TypedBankAccount, balance: BigDecimal) { protected open fun updateBalance(bankAccount: TypedBankAccount, balance: BigDecimal) {
@ -435,10 +445,8 @@ open class BankingPresenter(
/** /**
* Ensure that this method only gets called off UI thread (at least for Android Room db) as otherwise it may blocks UI thread. * Ensure that this method only gets called off UI thread (at least for Android Room db) as otherwise it may blocks UI thread.
*/ */
protected open fun persistAccountTransactionsOffUiThread(bankAccount: TypedBankAccount, bookedTransactions: List<IAccountTransaction>, unbookedTransactions: List<Any>) { protected open fun persistAccountTransactionsOffUiThread(bankAccount: TypedBankAccount, bookedTransactions: List<IAccountTransaction>) {
persister.saveOrUpdateAccountTransactions(bankAccount, bookedTransactions) persister.saveOrUpdateAccountTransactions(bankAccount, bookedTransactions)
// TODO: someday also persist unbooked transactions
} }