Ensured that persisting methods get called off UI thread
This commit is contained in:
parent
0f672f414b
commit
29dbe70983
|
@ -79,7 +79,7 @@ open class BankingPresenter constructor(
|
||||||
|
|
||||||
override fun enterTan(customer: TypedCustomer, tanChallenge: TanChallenge, callback: (EnterTanResult) -> Unit) {
|
override fun enterTan(customer: TypedCustomer, tanChallenge: TanChallenge, callback: (EnterTanResult) -> Unit) {
|
||||||
if (saveAccountOnNextEnterTanInvocation) {
|
if (saveAccountOnNextEnterTanInvocation) {
|
||||||
persistAccount(customer)
|
persistAccountOffUiThread(customer)
|
||||||
saveAccountOnNextEnterTanInvocation = false
|
saveAccountOnNextEnterTanInvocation = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ open class BankingPresenter constructor(
|
||||||
|
|
||||||
callAccountsChangedListeners()
|
callAccountsChangedListeners()
|
||||||
|
|
||||||
persistAccount(account)
|
persistAccountOffUiThread(account)
|
||||||
|
|
||||||
if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) {
|
if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) {
|
||||||
response.bookedTransactionsOfLast90Days.keys.forEach { bankAccount ->
|
response.bookedTransactionsOfLast90Days.keys.forEach { bankAccount ->
|
||||||
|
@ -206,7 +206,7 @@ open class BankingPresenter constructor(
|
||||||
|
|
||||||
customer.iconUrl = iconFilePath
|
customer.iconUrl = iconFilePath
|
||||||
|
|
||||||
persistAccount(customer)
|
persistAccountOffUiThread(customer)
|
||||||
|
|
||||||
callAccountsChangedListeners()
|
callAccountsChangedListeners()
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,12 @@ open class BankingPresenter constructor(
|
||||||
|
|
||||||
|
|
||||||
open fun deleteAccount(customer: TypedCustomer) {
|
open fun deleteAccount(customer: TypedCustomer) {
|
||||||
|
asyncRunner.runAsync {
|
||||||
|
deleteAccountOffUiThread(customer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun deleteAccountOffUiThread(customer: TypedCustomer) {
|
||||||
val wasSelected = isSingleSelectedAccount(customer) or // either account or one of its bank accounts is currently selected
|
val wasSelected = isSingleSelectedAccount(customer) or // either account or one of its bank accounts is currently selected
|
||||||
(customer.accounts.firstOrNull { isSingleSelectedBankAccount(it) } != null)
|
(customer.accounts.firstOrNull { isSingleSelectedBankAccount(it) } != null)
|
||||||
|
|
||||||
|
@ -372,13 +378,13 @@ open class BankingPresenter constructor(
|
||||||
updateBalance(bankAccount, it)
|
updateBalance(bankAccount, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
persistAccountTransactions(bankAccount, response.bookedTransactions, response.unbookedTransactions)
|
persistAccountTransactionsOffUiThread(bankAccount, response.bookedTransactions, response.unbookedTransactions)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun updateBalance(bankAccount: TypedBankAccount, balance: BigDecimal) {
|
protected open fun updateBalance(bankAccount: TypedBankAccount, balance: BigDecimal) {
|
||||||
bankAccount.balance = balance
|
bankAccount.balance = balance
|
||||||
|
|
||||||
persistAccount(bankAccount.customer)
|
persistAccountOffUiThread(bankAccount.customer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,13 +400,13 @@ open class BankingPresenter constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun accountDisplayIndexUpdated(account: TypedCustomer) {
|
open fun accountDisplayIndexUpdated(account: TypedCustomer) {
|
||||||
persistAccount(account)
|
persistAccountAsync(account)
|
||||||
|
|
||||||
callAccountsChangedListeners()
|
callAccountsChangedListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun accountUpdated(bank: TypedCustomer) {
|
open fun accountUpdated(bank: TypedCustomer) {
|
||||||
persistAccount(bank)
|
persistAccountAsync(bank)
|
||||||
|
|
||||||
callAccountsChangedListeners()
|
callAccountsChangedListeners()
|
||||||
|
|
||||||
|
@ -408,16 +414,28 @@ open class BankingPresenter constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun accountUpdated(account: TypedBankAccount) {
|
open fun accountUpdated(account: TypedBankAccount) {
|
||||||
persistAccount(account.customer)
|
persistAccountAsync(account.customer)
|
||||||
|
|
||||||
callAccountsChangedListeners()
|
callAccountsChangedListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun persistAccount(customer: ICustomer<*, *>) {
|
protected open fun persistAccountAsync(customer: ICustomer<*, *>) {
|
||||||
|
asyncRunner.runAsync {
|
||||||
|
persistAccountOffUiThread(customer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 persistAccountOffUiThread(customer: ICustomer<*, *>) {
|
||||||
persister.saveOrUpdateAccount(customer as TypedCustomer, customers)
|
persister.saveOrUpdateAccount(customer as TypedCustomer, customers)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun persistAccountTransactions(bankAccount: TypedBankAccount, bookedTransactions: List<IAccountTransaction>, unbookedTransactions: List<Any>) {
|
/**
|
||||||
|
* 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>) {
|
||||||
persister.saveOrUpdateAccountTransactions(bankAccount, bookedTransactions)
|
persister.saveOrUpdateAccountTransactions(bankAccount, bookedTransactions)
|
||||||
|
|
||||||
// TODO: someday also persist unbooked transactions
|
// TODO: someday also persist unbooked transactions
|
||||||
|
|
Loading…
Reference in New Issue