From a8eb748f57faf9a01b05218be8b219e769366906 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 25 May 2020 01:03:51 +0200 Subject: [PATCH] Implemented automatically fetching account transactions after a successful cash transfer --- .../banking/ui/presenter/BankingPresenter.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 959077f8..b9bd7c6d 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -297,14 +297,18 @@ open class BankingPresenter( clientsForAccounts.keys.forEach { account -> account.bankAccounts.forEach { bankAccount -> if (bankAccount.supportsRetrievingAccountTransactions) { - val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.time - OneDayMillis) } // one day before last received transactions - - fetchAccountTransactionsAsync(bankAccount, fromDate, abortIfTanIsRequired, callback) + updateBankAccountTransactionsAsync(bankAccount, abortIfTanIsRequired, callback) } } } } + protected open fun updateBankAccountTransactionsAsync(bankAccount: BankAccount, abortIfTanIsRequired: Boolean, callback: (GetTransactionsResponse) -> Unit) { + val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.time - OneDayMillis) } // one day before last received transactions + + fetchAccountTransactionsAsync(bankAccount, fromDate, abortIfTanIsRequired, callback) + } + protected open fun retrievedAccountTransactions(bankAccount: BankAccount, startDate: Date, response: GetTransactionsResponse) { if (response.isSuccessful) { bankAccount.lastRetrievedTransactionsTimestamp = startDate @@ -361,7 +365,13 @@ open class BankingPresenter( open fun transferMoneyAsync(bankAccount: BankAccount, data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) { getClientForAccount(bankAccount.account)?.let { client -> - client.transferMoneyAsync(data, bankAccount, callback) + client.transferMoneyAsync(data, bankAccount) { response -> + if (response.isSuccessful) { + updateBankAccountTransactionsAsync(bankAccount, true) { } + } + + callback(response) + } } }