Implemented reordering bank accounts

This commit is contained in:
dankito 2020-09-28 04:02:47 +02:00
parent a6a5baaeb1
commit 85bf455c0c
16 changed files with 180 additions and 43 deletions

View File

@ -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<BankDataAdapterItem.ViewHolder>(), IDraggable {
open class BankDataAdapterItem(open val bank: TypedBankData) : AbstractItem<BankDataViewHolder>(), IDraggable {
override var isDraggable = true
@ -21,26 +18,8 @@ open class BankDataAdapterItem(open val bank: TypedBankData) : AbstractItem<Bank
override val layoutRes: Int
get() = R.layout.list_item_bank_data
override fun getViewHolder(v: View): ViewHolder {
return ViewHolder(v)
}
class ViewHolder(view: View) : FastAdapter.ViewHolder<BankDataAdapterItem>(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<Any>) {
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)
}
}

View File

@ -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<DraggableBankAccountViewHolder>(), 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)
}
}

View File

@ -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<TypedBankAccount>) : ListAdapter<TypedBankAccount>(accounts) {
open class IconedBankAccountsAdapter(accounts: List<TypedBankAccount>) : ListAdapter<TypedBankAccount>(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

View File

@ -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<BankDataAdapterItem>(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<Any>) {
bankIcon.setIcon(item.bank)
bankDisplayName.text = item.bank.displayName
}
override fun unbindView(item: BankDataAdapterItem) {
bankDisplayName.text = null
bankIcon.setImageURI(null)
}
}

View File

@ -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<DraggableBankAccountAdapterItem>(view) {
protected var accountDisplayName: TextView = view.findViewById(R.id.txtBankDisplayName)
override fun bindView(item: DraggableBankAccountAdapterItem, payloads: List<Any>) {
accountDisplayName.text = item.account.displayName
}
override fun unbindView(item: DraggableBankAccountAdapterItem) {
accountDisplayName.text = null
}
}

View File

@ -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

View File

@ -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)

View File

@ -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<IDrawerItem<*>> {
return bank.accounts.map { account ->
return bank.accountsSorted.map { account ->
SecondaryDrawerItem()
.withName(account.displayName)
.withLevel(AccountLevel)

View File

@ -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"
>
<net.dankito.banking.ui.android.views.FormEditText
@ -87,6 +87,29 @@
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_bank_settings_bank_accounts_section_margin_bottom"
>
<net.dankito.banking.ui.android.views.FormSectionTitle
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/accounts"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcyBankAccounts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"

View File

@ -41,8 +41,8 @@
<ImageView
android:id="@+id/imgDragHandle"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="@dimen/drag_handle_size"
android:layout_height="@dimen/drag_handle_size"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_draggable_bank_account_height"
android:padding="@dimen/list_item_draggable_bank_account_padding"
android:gravity="center_vertical"
>
<TextView
android:id="@+id/txtBankDisplayName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/imgDragHandle"
android:layout_toStartOf="@+id/imgDragHandle"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:textAlignment="gravity"
android:singleLine="true"
android:textSize="@dimen/list_item_draggable_bank_account_account_name_text_size"
android:ellipsize="marquee"
/>
<ImageView
android:id="@+id/imgDragHandle"
android:layout_width="@dimen/drag_handle_size"
android:layout_height="@dimen/drag_handle_size"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
app:srcCompat="@drawable/ic_baseline_drag_handle_24"
/>
</RelativeLayout>

View File

@ -19,6 +19,7 @@
<string name="online_banking_credentials_login_name">Login Name</string>
<string name="online_banking_credentials_password">Passwort</string>
<string name="accounts">Konten</string>
<string name="bank_credentials">Bankzugänge</string>
<string name="navigation_drawer_open">Seitenleiste öffnen</string>
@ -26,7 +27,6 @@
<string name="nav_header_title">@string/app_name</string>
<string name="nav_header_version_label">Version\u0020</string>
<string name="nav_header_desc">Navigationsbereich</string>
<string name="drawer_menu_bank_accounts_section_title">Konten</string>
<string name="drawer_menu_all_bank_accounts_title">Alle Konten</string>
<string name="drawer_menu_show_settings_dialog_title">Einstellungen</string>

View File

@ -152,12 +152,19 @@
<dimen name="list_item_bank_data_icon_margin_right">8dp</dimen>
<dimen name="list_item_bank_data_bank_name_text_size">16sp</dimen>
<dimen name="dialog_bank_settings_bank_accounts_section_margin_bottom">18dp</dimen>
<dimen name="dialog_bank_settings_delete_account_button_height">50dp</dimen>
<dimen name="list_item_draggable_bank_account_height">35dp</dimen>
<dimen name="list_item_draggable_bank_account_padding">2dp</dimen>
<dimen name="list_item_draggable_bank_account_account_name_text_size">16sp</dimen>
<dimen name="dialog_send_message_log_padding">4dp</dimen>
<dimen name="dialog_send_message_log_message_log_label_bottom_margin">8dp</dimen>
<dimen name="dialog_send_message_log_buttons_width">120dp</dimen>
<dimen name="drag_handle_size">24dp</dimen>
<dimen name="view_collapsible_text_collapse_expand_icon_size">36dp</dimen>
<dimen name="view_collapsible_text_collapse_expand_icon_margin_top">-8dp</dimen>

View File

@ -6,4 +6,6 @@
<item name="bank_data_item_id" type="id" />
<item name="draggable_bank_account_item_id" type="id" />
</resources>

View File

@ -19,6 +19,7 @@
<string name="online_banking_credentials_login_name">Login name</string>
<string name="online_banking_credentials_password">Password</string>
<string name="accounts">Accounts</string>
<string name="bank_credentials">Bank credentials</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
@ -26,7 +27,6 @@
<string name="nav_header_title">@string/app_name</string>
<string name="nav_header_version_label">Version\u0020</string>
<string name="nav_header_desc">Navigation header</string>
<string name="drawer_menu_bank_accounts_section_title">Accounts</string>
<string name="drawer_menu_all_bank_accounts_title">All accounts</string>
<string name="drawer_menu_show_settings_dialog_title">Settings</string>