Fixed that mnitmSearchTransactions may is not initialized yet when AccountChangedListener gets called

This commit is contained in:
dankl 2020-01-19 17:08:37 +01:00 committed by dankito
parent 69f058b753
commit 709066c816
1 changed files with 18 additions and 12 deletions

View File

@ -81,6 +81,7 @@ class HomeFragment : Fragment() {
initSearchView() initSearchView()
initLogicAfterUiInitialized()
} }
} }
@ -130,7 +131,10 @@ class HomeFragment : Fragment() {
// TODO: this is such a bad code style // TODO: this is such a bad code style
(context as? MainActivity)?.presenter?.let { presenter -> (context as? MainActivity)?.presenter?.let { presenter ->
this.presenter = presenter this.presenter = presenter
}
}
private fun initLogicAfterUiInitialized() {
presenter.addAccountsChangedListener { handleAccountsChanged(it) } presenter.addAccountsChangedListener { handleAccountsChanged(it) }
presenter.addSelectedBankAccountsChangedListener { handleSelectedBankAccountsChanged(it) } presenter.addSelectedBankAccountsChangedListener { handleSelectedBankAccountsChanged(it) }
@ -138,7 +142,8 @@ class HomeFragment : Fragment() {
presenter.addRetrievedAccountTransactionsResponseListener { _, response -> presenter.addRetrievedAccountTransactionsResponseListener { _, response ->
handleGetTransactionsResponse(response) handleGetTransactionsResponse(response)
} }
}
updateTransactionsToDisplayOnUiThread()
} }
@ -154,7 +159,7 @@ class HomeFragment : Fragment() {
private fun handleSelectedBankAccountsChanged(selectedBankAccounts: List<BankAccount>) { private fun handleSelectedBankAccountsChanged(selectedBankAccounts: List<BankAccount>) {
context?.asActivity()?.let { activity -> context?.asActivity()?.let { activity ->
activity.runOnUiThread { activity.runOnUiThread {
updateTransactionsToDisplay() updateTransactionsToDisplayOnUiThread()
} }
} }
} }
@ -167,7 +172,7 @@ class HomeFragment : Fragment() {
context?.asActivity()?.let { activity -> context?.asActivity()?.let { activity ->
activity.runOnUiThread { activity.runOnUiThread {
if (response.isSuccessful) { if (response.isSuccessful) {
updateTransactionsToDisplay() updateTransactionsToDisplayOnUiThread()
} }
else { else {
AlertDialog.Builder(activity) // TODO: may show account name in message AlertDialog.Builder(activity) // TODO: may show account name in message
@ -199,7 +204,8 @@ class HomeFragment : Fragment() {
override fun onQueryTextChange(query: String): Boolean { override fun onQueryTextChange(query: String): Boolean {
appliedTransactionsFilter = query appliedTransactionsFilter = query
updateTransactionsToDisplay() updateTransactionsToDisplayOnUiThread()
return true return true
} }
@ -209,7 +215,7 @@ class HomeFragment : Fragment() {
} }
private fun updateTransactionsToDisplay() { private fun updateTransactionsToDisplayOnUiThread() {
transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter)
// TODO: if transactions are filtered calculate and show balance of displayed transactions? // TODO: if transactions are filtered calculate and show balance of displayed transactions?