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 cd0655fe..5ad2332b 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 @@ -7,6 +7,7 @@ import android.view.* import android.view.inputmethod.EditorInfo import android.widget.EditText import android.widget.ImageButton +import androidx.appcompat.widget.Toolbar import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat @@ -22,6 +23,7 @@ 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.android.views.InfoPopupWindow +import net.dankito.banking.ui.model.SelectedAccountType import net.dankito.banking.ui.model.TransactionsRetrievalState import net.dankito.banking.ui.model.TypedBankAccount import net.dankito.banking.ui.model.parameters.TransferMoneyData @@ -253,6 +255,8 @@ class HomeFragment : Fragment() { private fun updateTransactionsToDisplayOnUiThread() { + setToolbarTitle() + transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) mnitmBalance.title = presenter.formatAmount(presenter.balanceOfSelectedAccounts) @@ -271,6 +275,20 @@ class HomeFragment : Fragment() { setFetchAllTransactionsView() } + private fun setToolbarTitle() { + // TODO: also set selected account's icon + + if (presenter.allBanks.isNotEmpty()) { + activity?.findViewById(R.id.toolbar)?.let { toolbar -> + toolbar.title = when (presenter.selectedAccountType) { + SelectedAccountType.AllAccounts -> context?.getString(R.string.drawer_menu_all_bank_accounts_title) + SelectedAccountType.SingleBank -> presenter.getSingleSelectedBank()?.displayName + SelectedAccountType.SingleAccount -> presenter.getSingleSelectedAccount()?.displayName + } + } + } + } + private fun setRecyclerViewAndNoTransactionsFetchedView() { val transactionsRetrievalState = presenter.selectedAccountsTransactionRetrievalState val haveTransactionsBeenRetrieved = transactionsRetrievalState == TransactionsRetrievalState.RetrievedTransactions diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 2291574e..2e76f849 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -91,7 +91,8 @@ open class BankingPresenter( protected var _selectedAccounts = mutableListOf() - protected var selectedAccountType = SelectedAccountType.AllAccounts + open var selectedAccountType = SelectedAccountType.AllAccounts + protected set protected var saveAccountOnNextEnterTanInvocation = false @@ -858,11 +859,32 @@ open class BankingPresenter( && _selectedAccounts.map { it.bank }.toSet().containsExactly(bank) } + open fun getSingleSelectedBank(): TypedBankData? { + val selectedBanks = _selectedAccounts.map { it.bank }.toSet() + + if (selectedBanks.size == 1) { + return selectedBanks.first() as? TypedBankData + } + + return null + } + open fun isSingleSelectedAccount(account: TypedBankAccount): Boolean { return selectedAccountType == SelectedAccountType.SingleAccount && _selectedAccounts.containsExactly(account) } + open fun getSingleSelectedAccount(): TypedBankAccount? { + val selectedAccounts = _selectedAccounts.toSet() + + if (selectedAccounts.size == 1) { + return selectedAccounts.first() + } + + return null + } + + open fun selectedAllAccounts() { selectedAccountType = SelectedAccountType.AllAccounts