Implemented updating lists on changes
This commit is contained in:
parent
b7133ba7d5
commit
95215edc7c
|
@ -25,6 +25,12 @@ open class BankSettingsDialog : SettingsDialogBase() {
|
|||
|
||||
protected lateinit var bank: TypedBankData
|
||||
|
||||
protected lateinit var bankAccountsAdapter: FastAdapterRecyclerView<DraggableBankAccountAdapterItem>
|
||||
|
||||
protected var banksChangedListener = { _: List<TypedBankData> ->
|
||||
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<DraggableBankAccountAdapterItem> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,12 @@ open class SettingsDialog : SettingsDialogBase() {
|
|||
}
|
||||
|
||||
|
||||
protected lateinit var banksAdapter: FastAdapterRecyclerView<BankDataAdapterItem>
|
||||
|
||||
protected var banksChangedListener = { _: List<TypedBankData> ->
|
||||
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<BankDataAdapterItem> {
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue