diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt index 671355d0..5483ee52 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt @@ -25,6 +25,12 @@ open class BankSettingsDialog : SettingsDialogBase() { protected lateinit var bank: TypedBankData + protected lateinit var bankAccountsAdapter: FastAdapterRecyclerView + + protected var banksChangedListener = { _: List -> + updateBankAccountsAdapterItems() + } + fun show(bank: TypedBankData, activity: AppCompatActivity) { @@ -39,6 +45,8 @@ open class BankSettingsDialog : SettingsDialogBase() { setupUI(rootView) + presenter.addBanksChangedListener(banksChangedListener) + return rootView } @@ -52,16 +60,32 @@ open class BankSettingsDialog : SettingsDialogBase() { edtxtUserName.text = bank.userName edtxtPassword.text = bank.password - val items = bank.accountsSorted.map { DraggableBankAccountAdapterItem(it) } - val adapter = FastAdapterRecyclerView(rootView.rcyBankAccounts, items, true) - adapter.onClickListener = { navigationToBankAccountSettingsDialog(it.account) } - adapter.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBankAccounts(oldPosition, oldItem.account, newPosition, newItem.account) } + val items = createBankAccountsAdapterItems() + bankAccountsAdapter = FastAdapterRecyclerView(rootView.rcyBankAccounts, items, true) + bankAccountsAdapter.onClickListener = { navigationToBankAccountSettingsDialog(it.account) } + bankAccountsAdapter.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBankAccounts(oldPosition, oldItem.account, newPosition, newItem.account) } btnDeleteAccount.setOnClickListener { askUserToDeleteAccount() } } } + override fun onDestroy() { + presenter.removeBanksChangedListener(banksChangedListener) + + super.onDestroy() + } + + + protected open fun createBankAccountsAdapterItems(): List { + return bank.accountsSorted.map { DraggableBankAccountAdapterItem(it) } + } + + protected open fun updateBankAccountsAdapterItems() { + bankAccountsAdapter.setItems(createBankAccountsAdapterItems()) + } + + protected open fun navigationToBankAccountSettingsDialog(account: TypedBankAccount) { BankAccountSettingsDialog().show(account, requireActivity() as AppCompatActivity) } diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt index 878fc70b..d3b18d5e 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt @@ -17,6 +17,12 @@ open class SettingsDialog : SettingsDialogBase() { } + protected lateinit var banksAdapter: FastAdapterRecyclerView + + protected var banksChangedListener = { _: List -> + updateBanksAdapterItems() + } + fun show(activity: AppCompatActivity) { show(activity, DialogTag) @@ -28,6 +34,8 @@ open class SettingsDialog : SettingsDialogBase() { setupUI(rootView) + presenter.addBanksChangedListener(banksChangedListener) + return rootView } @@ -37,16 +45,32 @@ open class SettingsDialog : SettingsDialogBase() { setupToolbar(this, rootView.context.getString(R.string.dialog_settings_title), false) } - val items = presenter.allBanksSortedByDisplayIndex.map { BankDataAdapterItem(it) } - val adapter = FastAdapterRecyclerView(rootView.rcyBankCredentials, items, true) - adapter.onClickListener = { navigationToBankSettingsDialog(it.bank) } - adapter.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBanks(oldPosition, oldItem.bank, newPosition, newItem.bank) } + val items = createBanksAdapterItems() + banksAdapter = FastAdapterRecyclerView(rootView.rcyBankCredentials, items, true) + banksAdapter.onClickListener = { navigationToBankSettingsDialog(it.bank) } + banksAdapter.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBanks(oldPosition, oldItem.bank, newPosition, newItem.bank) } rootView.btnShowSendMessageLogDialog.setOnClickListener { presenter.showSendMessageLogDialog() } } } + override fun onDestroy() { + presenter.removeBanksChangedListener(banksChangedListener) + + super.onDestroy() + } + + + protected open fun createBanksAdapterItems(): List { + return presenter.allBanksSortedByDisplayIndex.map { BankDataAdapterItem(it) } + } + + protected open fun updateBanksAdapterItems() { + banksAdapter.setItems(createBanksAdapterItems()) + } + + protected open fun navigationToBankSettingsDialog(bank: TypedBankData) { BankSettingsDialog().show(bank, requireActivity() as AppCompatActivity) }