diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index b654e094..87209d7e 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -19,6 +19,7 @@ import net.dankito.banking.ui.android.adapter.AccountTransactionAdapter import net.dankito.banking.ui.android.di.BankingComponent import net.dankito.banking.ui.android.extensions.addHorizontalItemDivider import net.dankito.banking.ui.android.extensions.showAmount +import net.dankito.banking.ui.model.TransactionsRetrievalState import net.dankito.banking.ui.model.TypedBankAccount import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.responses.GetTransactionsResponse @@ -93,6 +94,8 @@ class HomeFragment : Fragment() { setFetchAllTransactionsView() } + rootView.btnRetrieveTransactions.setOnClickListener { fetchTransactions() } + return rootView } @@ -235,7 +238,6 @@ class HomeFragment : Fragment() { private fun updateTransactionsToDisplayOnUiThread() { transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) - // TODO: if transactions are filtered calculate and show balance of displayed transactions? mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedBankAccounts) mnitmBalance.isVisible = presenter.doSelectedBankAccountsSupportRetrievingBalance @@ -247,15 +249,35 @@ class HomeFragment : Fragment() { else transactionAdapter.items.map { it.amount }.sum() txtTransactionsBalance.showAmount(presenter, sumOfDisplayedTransactions) + setRecyclerViewAndNoTransactionsFetchedView() + setFetchAllTransactionsView() } + private fun setRecyclerViewAndNoTransactionsFetchedView() { + val transactionsRetrievalState = presenter.selectedBankAccountsTransactionRetrievalState + val haveTransactionsBeenRetrieved = transactionsRetrievalState == TransactionsRetrievalState.RetrievedTransactions + + rcyvwAccountTransactions.visibility = if (haveTransactionsBeenRetrieved) View.VISIBLE else View.GONE + lytNoTransactionsFetched.visibility = if (haveTransactionsBeenRetrieved) View.GONE else View.VISIBLE + btnRetrieveTransactions.visibility = if (transactionsRetrievalState == TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions) View.GONE else View.VISIBLE + + val transactionsRetrievalStateMessageId = when (transactionsRetrievalState) { + TransactionsRetrievalState.AccountDoesNotSupportFetchingTransactions -> R.string.fragment_home_transactions_retrieval_state_account_does_not_support_retrieving_transactions + TransactionsRetrievalState.NoTransactionsInRetrievedPeriod -> R.string.fragment_home_transactions_retrieval_state_no_transactions_in_retrieved_period + TransactionsRetrievalState.NeverRetrievedTransactions -> R.string.fragment_home_transactions_retrieval_state_never_retrieved_transactions + else -> null + } + txtNoTransactionsFetchedMessage.text = transactionsRetrievalStateMessageId?.let { requireContext().getString(transactionsRetrievalStateMessageId) } ?: "" + } + private fun setFetchAllTransactionsView() { accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedBankAccountsForWhichNotAllTransactionsHaveBeenFetched var floatingActionMenuBottomMarginResourceId = R.dimen.fab_margin_bottom_without_toolbar - if (doNotShowFetchAllTransactionsOverlay || accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty()) { + if (doNotShowFetchAllTransactionsOverlay || accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty() + || presenter.selectedBankAccountsTransactionRetrievalState != TransactionsRetrievalState.RetrievedTransactions) { lytFetchAllTransactionsOverlay.visibility = View.GONE } else { @@ -268,14 +290,22 @@ class HomeFragment : Fragment() { } } - private fun fetchAllTransactions() { - accountsForWhichNotAllTransactionsHaveBeenFetched.forEach { account -> - presenter.fetchAllAccountTransactionsAsync(account) { - requireActivity().runOnUiThread { - updateAccountsTransactions() - } + + private fun fetchTransactions() { + presenter.selectedBankAccounts.forEach { account -> + if (account.haveAllTransactionsBeenFetched) { + presenter.updateBankAccountTransactionsAsync(account) + } + else { + presenter.fetchAllAccountTransactionsAsync(account) } } } + private fun fetchAllTransactions() { + accountsForWhichNotAllTransactionsHaveBeenFetched.forEach { account -> + presenter.fetchAllAccountTransactionsAsync(account) + } + } + } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml b/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml index a460fbaa..72a9af38 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/fragment_home.xml @@ -12,7 +12,7 @@ app:layout_constraintTop_toTopOf="parent" > - @@ -59,10 +60,47 @@ android:id="@+id/rcyvwAccountTransactions" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_below="@+id/lytTransactionsSummary" + android:layout_alignParentBottom="true" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + + + + +