From 85bf455c0cbe56439b53780089c15bf6d07360ae Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 28 Sep 2020 04:02:47 +0200 Subject: [PATCH] Implemented reordering bank accounts --- .../ui/android/adapter/BankDataAdapterItem.kt | 29 ++------------ .../DraggableBankAccountAdapterItem.kt | 25 ++++++++++++ ...dapter.kt => IconedBankAccountsAdapter.kt} | 6 +-- .../adapter/viewholder/BankDataViewHolder.kt | 28 +++++++++++++ .../DraggableBankAccountViewHolder.kt | 23 +++++++++++ .../ui/android/dialogs/TransferMoneyDialog.kt | 4 +- .../dialogs/settings/BankSettingsDialog.kt | 23 ++++++++--- .../banking/ui/android/views/DrawerView.kt | 4 +- .../main/res/layout/dialog_bank_settings.xml | 25 +++++++++++- .../main/res/layout/list_item_bank_data.xml | 4 +- .../list_item_draggable_bank_account.xml | 39 +++++++++++++++++++ ....xml => list_item_iconed_bank_account.xml} | 0 .../src/main/res/values-de/strings.xml | 2 +- .../src/main/res/values/dimens.xml | 7 ++++ .../src/main/res/values/ids.xml | 2 + .../src/main/res/values/strings.xml | 2 +- 16 files changed, 180 insertions(+), 43 deletions(-) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/DraggableBankAccountAdapterItem.kt rename ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/{BankAccountsAdapter.kt => IconedBankAccountsAdapter.kt} (78%) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/BankDataViewHolder.kt create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/DraggableBankAccountViewHolder.kt create mode 100644 ui/BankingAndroidApp/src/main/res/layout/list_item_draggable_bank_account.xml rename ui/BankingAndroidApp/src/main/res/layout/{list_item_bank_account.xml => list_item_iconed_bank_account.xml} (100%) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankDataAdapterItem.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankDataAdapterItem.kt index 7a6b3e2d..84afc7ed 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankDataAdapterItem.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankDataAdapterItem.kt @@ -1,17 +1,14 @@ package net.dankito.banking.ui.android.adapter import android.view.View -import android.widget.ImageView -import android.widget.TextView -import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.drag.IDraggable import com.mikepenz.fastadapter.items.AbstractItem import net.dankito.banking.ui.android.R -import net.dankito.banking.ui.android.extensions.setIcon +import net.dankito.banking.ui.android.adapter.viewholder.BankDataViewHolder import net.dankito.banking.ui.model.TypedBankData -open class BankDataAdapterItem(open val bank: TypedBankData) : AbstractItem(), IDraggable { +open class BankDataAdapterItem(open val bank: TypedBankData) : AbstractItem(), IDraggable { override var isDraggable = true @@ -21,26 +18,8 @@ open class BankDataAdapterItem(open val bank: TypedBankData) : AbstractItem(view) { - - protected var bankIcon: ImageView = view.findViewById(R.id.imgBankIcon) - protected var bankDisplayName: TextView = view.findViewById(R.id.txtBankDisplayName) - - - override fun bindView(item: BankDataAdapterItem, payloads: List) { - bankIcon.setIcon(item.bank) - bankDisplayName.text = item.bank.displayName - } - - override fun unbindView(item: BankDataAdapterItem) { - bankDisplayName.text = null - bankIcon.setImageURI(null) - } + override fun getViewHolder(v: View): BankDataViewHolder { + return BankDataViewHolder(v) } } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/DraggableBankAccountAdapterItem.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/DraggableBankAccountAdapterItem.kt new file mode 100644 index 00000000..1eb9022e --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/DraggableBankAccountAdapterItem.kt @@ -0,0 +1,25 @@ +package net.dankito.banking.ui.android.adapter + +import android.view.View +import com.mikepenz.fastadapter.drag.IDraggable +import com.mikepenz.fastadapter.items.AbstractItem +import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.android.adapter.viewholder.DraggableBankAccountViewHolder +import net.dankito.banking.ui.model.TypedBankAccount + + +open class DraggableBankAccountAdapterItem(open val account: TypedBankAccount) : AbstractItem(), IDraggable { + + override var isDraggable = true + + override val type: Int + get() = R.id.draggable_bank_account_item_id + + override val layoutRes: Int + get() = R.layout.list_item_draggable_bank_account + + override fun getViewHolder(v: View): DraggableBankAccountViewHolder { + return DraggableBankAccountViewHolder(v) + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankAccountsAdapter.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/IconedBankAccountsAdapter.kt similarity index 78% rename from ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankAccountsAdapter.kt rename to ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/IconedBankAccountsAdapter.kt index 33eef006..715cbf6e 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/BankAccountsAdapter.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/IconedBankAccountsAdapter.kt @@ -4,21 +4,21 @@ import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import kotlinx.android.synthetic.main.list_item_bank_account.view.* +import kotlinx.android.synthetic.main.list_item_iconed_bank_account.view.* import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.extensions.setIcon import net.dankito.banking.ui.model.TypedBankAccount import net.dankito.utils.android.ui.adapter.ListAdapter -open class BankAccountsAdapter(accounts: List) : ListAdapter(accounts) { +open class IconedBankAccountsAdapter(accounts: List) : ListAdapter(accounts) { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? { val item = getItem(position) val inflater = parent?.context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater - val view = convertView ?: inflater?.inflate(R.layout.list_item_bank_account, parent, false) + val view = convertView ?: inflater?.inflate(R.layout.list_item_iconed_bank_account, parent, false) view?.let { view.txtBankAccountDisplayName.text = item.displayName diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/BankDataViewHolder.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/BankDataViewHolder.kt new file mode 100644 index 00000000..8f166ee3 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/BankDataViewHolder.kt @@ -0,0 +1,28 @@ +package net.dankito.banking.ui.android.adapter.viewholder + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import com.mikepenz.fastadapter.FastAdapter +import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.android.adapter.BankDataAdapterItem +import net.dankito.banking.ui.android.extensions.setIcon + + +open class BankDataViewHolder(view: View) : FastAdapter.ViewHolder(view) { + + protected var bankIcon: ImageView = view.findViewById(R.id.imgBankIcon) + protected var bankDisplayName: TextView = view.findViewById(R.id.txtBankDisplayName) + + + override fun bindView(item: BankDataAdapterItem, payloads: List) { + bankIcon.setIcon(item.bank) + bankDisplayName.text = item.bank.displayName + } + + override fun unbindView(item: BankDataAdapterItem) { + bankDisplayName.text = null + bankIcon.setImageURI(null) + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/DraggableBankAccountViewHolder.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/DraggableBankAccountViewHolder.kt new file mode 100644 index 00000000..0e33ab52 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/adapter/viewholder/DraggableBankAccountViewHolder.kt @@ -0,0 +1,23 @@ +package net.dankito.banking.ui.android.adapter.viewholder + +import android.view.View +import android.widget.TextView +import com.mikepenz.fastadapter.FastAdapter +import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.android.adapter.DraggableBankAccountAdapterItem + + +open class DraggableBankAccountViewHolder(view: View) : FastAdapter.ViewHolder(view) { + + protected var accountDisplayName: TextView = view.findViewById(R.id.txtBankDisplayName) + + + override fun bindView(item: DraggableBankAccountAdapterItem, payloads: List) { + accountDisplayName.text = item.account.displayName + } + + override fun unbindView(item: DraggableBankAccountAdapterItem) { + accountDisplayName.text = null + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt index 3576efe6..5cd4bf45 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt @@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.dialog_transfer_money.* import kotlinx.android.synthetic.main.dialog_transfer_money.view.* import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.di.BankingComponent -import net.dankito.banking.ui.android.adapter.BankAccountsAdapter +import net.dankito.banking.ui.android.adapter.IconedBankAccountsAdapter import net.dankito.banking.ui.android.adapter.presenter.RecipientPresenter import net.dankito.banking.ui.android.extensions.addEnterPressedListener import net.dankito.banking.ui.android.extensions.closePopupOnBackButtonPress @@ -114,7 +114,7 @@ open class TransferMoneyDialog : DialogFragment() { if (accountsSupportingTransferringMoney.size > 1) { rootView.lytSelectBankAccount.visibility = View.VISIBLE - val adapter = BankAccountsAdapter(accountsSupportingTransferringMoney) + val adapter = IconedBankAccountsAdapter(accountsSupportingTransferringMoney) rootView.spnBankAccounts.adapter = adapter rootView.spnBankAccounts.onItemSelectedListener = ListItemSelectedListener(adapter) { selectedBankAccount -> this.account = selectedBankAccount 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 02b67c91..9b44bef4 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 @@ -3,19 +3,17 @@ package net.dankito.banking.ui.android.dialogs.settings import android.os.Bundle import android.view.* import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.DialogFragment import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtBankName import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtUserName import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtPassword import kotlinx.android.synthetic.main.dialog_bank_settings.view.* +import kotlinx.android.synthetic.main.dialog_bank_settings.view.toolbar import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.android.adapter.DraggableBankAccountAdapterItem +import net.dankito.banking.ui.android.adapter.FastAdapterRecyclerView import net.dankito.banking.ui.android.alerts.AskDeleteAccountAlert -import net.dankito.banking.ui.android.alerts.AskDismissChangesAlert -import net.dankito.banking.ui.android.di.BankingComponent -import net.dankito.banking.ui.android.views.FormEditText +import net.dankito.banking.ui.model.TypedBankAccount import net.dankito.banking.ui.model.TypedBankData -import net.dankito.banking.ui.presenter.BankingPresenter -import javax.inject.Inject open class BankSettingsDialog : SettingsDialogBase() { @@ -54,11 +52,24 @@ 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.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBankAccounts(oldPosition, oldItem.account, newPosition, newItem.account) } + btnDeleteAccount.setOnClickListener { askUserToDeleteAccount() } } } + protected open fun reorderedBankAccounts(oldPosition: Int, oldItem: TypedBankAccount, newPosition: Int, newItem: TypedBankAccount) { + oldItem.displayIndex = oldPosition + newItem.displayIndex = newPosition + + presenter.accountUpdated(oldItem) + presenter.accountUpdated(newItem) + } + + override val hasUnsavedChanges: Boolean get() = didChange(edtxtBankName, bank.displayName) || didChange(edtxtUserName, bank.userName) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/DrawerView.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/DrawerView.kt index 0a86f2c4..5850a818 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/DrawerView.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/DrawerView.kt @@ -77,7 +77,7 @@ open class DrawerView( slider.apply { addItems( SectionDrawerItem() - .withName(R.string.drawer_menu_bank_accounts_section_title) + .withName(R.string.accounts) .withIdentifier(AccountsSectionHeaderId) .withDivider(false) , @@ -163,7 +163,7 @@ open class DrawerView( } private fun createBankAccountsDrawerItems(bank: TypedBankData): List> { - return bank.accounts.map { account -> + return bank.accountsSorted.map { account -> SecondaryDrawerItem() .withName(account.displayName) .withLevel(AccountLevel) diff --git a/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml b/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml index 36f05516..f46f8768 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml @@ -43,6 +43,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" + android:padding="@dimen/form_padding" > @@ -50,7 +51,6 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/form_padding" > + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/list_item_bank_account.xml b/ui/BankingAndroidApp/src/main/res/layout/list_item_iconed_bank_account.xml similarity index 100% rename from ui/BankingAndroidApp/src/main/res/layout/list_item_bank_account.xml rename to ui/BankingAndroidApp/src/main/res/layout/list_item_iconed_bank_account.xml diff --git a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml index 8b22211d..b339e015 100644 --- a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml @@ -19,6 +19,7 @@ Login Name Passwort + Konten Bankzugänge Seitenleiste öffnen @@ -26,7 +27,6 @@ @string/app_name Version\u0020 Navigationsbereich - Konten Alle Konten Einstellungen diff --git a/ui/BankingAndroidApp/src/main/res/values/dimens.xml b/ui/BankingAndroidApp/src/main/res/values/dimens.xml index bd6b8854..b3547390 100644 --- a/ui/BankingAndroidApp/src/main/res/values/dimens.xml +++ b/ui/BankingAndroidApp/src/main/res/values/dimens.xml @@ -152,12 +152,19 @@ 8dp 16sp + 18dp 50dp + 35dp + 2dp + 16sp + 4dp 8dp 120dp + 24dp + 36dp -8dp diff --git a/ui/BankingAndroidApp/src/main/res/values/ids.xml b/ui/BankingAndroidApp/src/main/res/values/ids.xml index b7733f8d..50943bac 100644 --- a/ui/BankingAndroidApp/src/main/res/values/ids.xml +++ b/ui/BankingAndroidApp/src/main/res/values/ids.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values/strings.xml b/ui/BankingAndroidApp/src/main/res/values/strings.xml index fdd7b8e9..270fc9bf 100644 --- a/ui/BankingAndroidApp/src/main/res/values/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values/strings.xml @@ -19,6 +19,7 @@ Login name Password + Accounts Bank credentials Open navigation drawer @@ -26,7 +27,6 @@ @string/app_name Version\u0020 Navigation header - Accounts All accounts Settings