diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt index 9110e636..0275804f 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt @@ -81,6 +81,7 @@ class HomeFragment : Fragment() { initSearchView() + initLogicAfterUiInitialized() } } @@ -130,17 +131,21 @@ class HomeFragment : Fragment() { // TODO: this is such a bad code style (context as? MainActivity)?.presenter?.let { presenter -> this.presenter = presenter - - presenter.addAccountsChangedListener { handleAccountsChanged(it) } - - presenter.addSelectedBankAccountsChangedListener { handleSelectedBankAccountsChanged(it) } - - presenter.addRetrievedAccountTransactionsResponseListener { _, response -> - handleGetTransactionsResponse(response) - } } } + private fun initLogicAfterUiInitialized() { + presenter.addAccountsChangedListener { handleAccountsChanged(it) } + + presenter.addSelectedBankAccountsChangedListener { handleSelectedBankAccountsChanged(it) } + + presenter.addRetrievedAccountTransactionsResponseListener { _, response -> + handleGetTransactionsResponse(response) + } + + updateTransactionsToDisplayOnUiThread() + } + private fun handleAccountsChanged(accounts: List) { context?.asActivity()?.let { activity -> @@ -154,7 +159,7 @@ class HomeFragment : Fragment() { private fun handleSelectedBankAccountsChanged(selectedBankAccounts: List) { context?.asActivity()?.let { activity -> activity.runOnUiThread { - updateTransactionsToDisplay() + updateTransactionsToDisplayOnUiThread() } } } @@ -167,7 +172,7 @@ class HomeFragment : Fragment() { context?.asActivity()?.let { activity -> activity.runOnUiThread { if (response.isSuccessful) { - updateTransactionsToDisplay() + updateTransactionsToDisplayOnUiThread() } else { AlertDialog.Builder(activity) // TODO: may show account name in message @@ -199,7 +204,8 @@ class HomeFragment : Fragment() { override fun onQueryTextChange(query: String): Boolean { appliedTransactionsFilter = query - updateTransactionsToDisplay() + updateTransactionsToDisplayOnUiThread() + return true } @@ -209,7 +215,7 @@ class HomeFragment : Fragment() { } - private fun updateTransactionsToDisplay() { + private fun updateTransactionsToDisplayOnUiThread() { transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) // TODO: if transactions are filtered calculate and show balance of displayed transactions?