diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/persistence/IBankingPersistence.kt b/BankingUiCommon/src/main/java/net/dankito/banking/persistence/IBankingPersistence.kt index 8bc002eb..826aabf3 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/persistence/IBankingPersistence.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/persistence/IBankingPersistence.kt @@ -7,6 +7,8 @@ interface IBankingPersistence { fun saveOrUpdateAccount(account: Account, allAccounts: List) + fun deleteAccount(account: Account, allAccounts: List) + fun readPersistedAccounts(): List } \ No newline at end of file diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 444e8a37..16e584d3 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -158,6 +158,21 @@ open class BankingPresenter( } } + open fun deleteAccount(account: Account) { + val wasSelected = isSingleSelectedAccount(account) or // either account or one of its bank accounts is currently selected + (account.bankAccounts.firstOrNull { isSingleSelectedBankAccount(it) } != null) + + clientsForAccounts.remove(account) + + persister.deleteAccount(account, accounts) + + callAccountsChangedListeners() + + if (wasSelected) { + selectedAllBankAccounts() + } + } + open fun getAccountTransactionsAsync(account: Account, callback: (GetTransactionsResponse) -> Unit) { diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/IDrawerItemExtensions.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/IDrawerItemExtensions.kt index 8c902c0c..a2f97271 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/IDrawerItemExtensions.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/extensions/IDrawerItemExtensions.kt @@ -3,13 +3,14 @@ package net.dankito.banking.fints4java.android.ui.extensions import android.content.Context import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.materialdrawer.iconics.withIcon -import com.mikepenz.materialdrawer.model.AbstractBadgeableDrawerItem +import com.mikepenz.materialdrawer.model.BaseDescribeableDrawerItem +import com.mikepenz.materialdrawer.model.BaseViewHolder import com.mikepenz.materialdrawer.model.interfaces.withIconColor import net.dankito.utils.android.extensions.createColorStateList -fun > AbstractBadgeableDrawerItem.withIcon( - context: Context, icon: IIcon, iconColorId: Int): AbstractBadgeableDrawerItem { +fun BaseDescribeableDrawerItem.withIcon(context: Context, icon: IIcon, iconColorId: Int) + : BaseDescribeableDrawerItem { withIcon(icon) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/AccountDrawerItem.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/AccountDrawerItem.kt new file mode 100644 index 00000000..1935d5bd --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/AccountDrawerItem.kt @@ -0,0 +1,6 @@ +package net.dankito.banking.fints4java.android.ui.views + + +class AccountDrawerItem : SecondaryIconDrawerItem() { + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/DrawerView.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/DrawerView.kt index 491b82e2..d300a352 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/DrawerView.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/DrawerView.kt @@ -2,7 +2,10 @@ package net.dankito.banking.fints4java.android.ui.views import android.view.View import android.widget.TextView +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.GravityCompat +import androidx.drawerlayout.widget.DrawerLayout import com.mikepenz.iconics.typeface.library.fontawesome.FontAwesome import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.materialdrawer.model.PrimaryDrawerItem @@ -112,10 +115,15 @@ open class DrawerView( }.flatten() } - private fun createAccountDrawerItem(account: Account): PrimaryDrawerItem { - return PrimaryDrawerItem() + private fun createAccountDrawerItem(account: Account): IDrawerItem<*> { + + return AccountDrawerItem() .withName(account.displayName) .withLevel(AccountLevel) +// .withSecondaryIcon(GoogleMaterial.Icon.gmd_settings) // used when editing account is implemented + .withSecondaryIcon(GoogleMaterial.Icon.gmd_delete) + .withSecondaryIconColor(activity, R.color.primaryTextColor_Dark) + .withOnSecondaryIconClickedListener { closeDrawerAndEditAccount(account) } .withIcon(activity, FontAwesome.Icon.faw_piggy_bank, R.color.primaryTextColor_Dark) .withSelected(presenter.isSingleSelectedAccount(account)) .withOnDrawerItemClickListener { _, _, _ -> itemClicked { presenter.selectedAccount(account) } } @@ -137,6 +145,25 @@ open class DrawerView( return false } + private fun closeDrawerAndEditAccount(account: Account) { + closeDrawer() + + editAccount(account) + } + + private fun editAccount(account: Account) { + // TODO: implement editing account (e.g. displayed name etc.) + + AlertDialog.Builder(activity) + .setMessage(activity.getString(R.string.dialog_edit_account_ask_should_account_be_deleted, account.displayName)) + .setPositiveButton(R.string.delete) { dialog, _ -> + dialog.dismiss() + presenter.deleteAccount(account) + } + .setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() } + .show() + } + private fun showAppVersion(navigationHeaderView: View?) { try { val packageInfo = activity.packageManager.getPackageInfo(activity.packageName, 0) @@ -147,4 +174,9 @@ open class DrawerView( } } + private fun closeDrawer() { + val drawerLayout = activity.findViewById(R.id.drawer_layout) + drawerLayout.closeDrawer(GravityCompat.START) + } + } \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/SecondaryIconDrawerItem.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/SecondaryIconDrawerItem.kt new file mode 100644 index 00000000..931ddf80 --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/SecondaryIconDrawerItem.kt @@ -0,0 +1,122 @@ +package net.dankito.banking.fints4java.android.ui.views + +import android.content.Context +import android.content.res.ColorStateList +import android.graphics.Bitmap +import android.graphics.drawable.Drawable +import android.net.Uri +import android.view.View +import android.widget.ImageView +import androidx.annotation.DrawableRes +import androidx.annotation.LayoutRes +import com.mikepenz.iconics.typeface.IIcon +import com.mikepenz.materialdrawer.holder.ImageHolder +import com.mikepenz.materialdrawer.iconics.IconicsImageHolder +import com.mikepenz.materialdrawer.model.BaseDescribeableDrawerItem +import com.mikepenz.materialdrawer.model.BaseViewHolder +import net.dankito.banking.fints4java.android.R +import net.dankito.utils.android.extensions.createColorStateList + + +open class SecondaryIconDrawerItem> : BaseDescribeableDrawerItem() { + + var secondaryIcon: ImageHolder? = null + + var secondaryIconColor: ColorStateList? = null + + var onSecondaryIconClicked: (() -> Unit)? = null + + + override val type: Int + get() = R.id.material_drawer_item_secondary_icon + + override val layoutRes: Int + @LayoutRes + get() = R.layout.material_drawer_item_secondary_icon + + + override fun bindView(holder: ViewHolder, payloads: List) { + super.bindView(holder, payloads) + + bindViewHelper(holder) + + if (secondaryIcon == null) { + holder.btnSecondaryIcon.visibility = View.GONE + } + else { + val context = holder.itemView.context + val secondaryIconColor = this.secondaryIconColor ?: getIconColor(context) + val secondaryIcon = ImageHolder.decideIcon(secondaryIcon, context, secondaryIconColor, isIconTinted, 1) + + holder.btnSecondaryIcon.setImageDrawable(secondaryIcon) + + holder.btnSecondaryIcon.setOnClickListener { onSecondaryIconClicked?.invoke() } + + holder.btnSecondaryIcon.visibility = View.VISIBLE + } + + //call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required) + onPostBindView(this, holder.itemView) + } + + override fun getViewHolder(v: View): ViewHolder { + return ViewHolder(v) + } + + open class ViewHolder(view: View) : BaseViewHolder(view) { + internal val btnSecondaryIcon = view.findViewById(R.id.btnSecondaryIcon) + } + + + open fun withSecondaryIconColor(iconColor: ColorStateList): Item { + this.secondaryIconColor = iconColor + return this as Item + } + + open fun withSecondaryIconColor(context: Context, iconColorResId: Int): Item { + return withSecondaryIconColor(context.createColorStateList(iconColorResId)) + } + + + open fun withSecondaryIcon(icon: Drawable?): Item { + this.secondaryIcon = ImageHolder(icon) + return this as Item + } + + open fun withSecondaryIcon(icon: Bitmap): Item { + this.secondaryIcon = ImageHolder(icon) + return this as Item + } + + open fun withSecondaryIcon(@DrawableRes imageRes: Int): Item { + this.secondaryIcon = ImageHolder(imageRes) + return this as Item + } + + open fun withSecondaryIcon(url: String): Item { + this.secondaryIcon = ImageHolder(url) + return this as Item + } + + open fun withSecondaryIcon(uri: Uri): Item { + this.secondaryIcon = ImageHolder(uri) + return this as Item + } + + open fun withSecondaryIcon(icon: ImageHolder?): Item { + this.secondaryIcon = icon + return this as Item + } + + open fun withSecondaryIcon(icon: IIcon): Item { + this.secondaryIcon = IconicsImageHolder(icon) + return this as Item + } + + + open fun withOnSecondaryIconClickedListener(clickListener: () -> Unit): Item { + this.onSecondaryIconClicked = clickListener + return this as Item + } + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_add_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_add_white_48dp.png deleted file mode 100755 index 0fdced8f..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_add_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png deleted file mode 100755 index ae11b916..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png deleted file mode 100755 index 8c04514d..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_add_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_add_white_48dp.png deleted file mode 100755 index 67bb598e..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_add_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png deleted file mode 100755 index db384dee..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png deleted file mode 100755 index f4e3df5c..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_add_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_add_white_48dp.png deleted file mode 100755 index d64c22e9..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_add_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png deleted file mode 100755 index 874a0eb6..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png deleted file mode 100755 index b3cc107a..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_add_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_add_white_48dp.png deleted file mode 100755 index 7e699137..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_add_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png deleted file mode 100755 index d63a3b23..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png deleted file mode 100755 index d003ced7..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_add_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_add_white_48dp.png deleted file mode 100755 index 165c907d..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_add_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png deleted file mode 100755 index e23861fb..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png deleted file mode 100755 index c99e6a07..00000000 Binary files a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png and /dev/null differ diff --git a/fints4javaAndroidApp/src/main/res/layout/material_drawer_item_secondary_icon.xml b/fints4javaAndroidApp/src/main/res/layout/material_drawer_item_secondary_icon.xml new file mode 100755 index 00000000..962dff5c --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/layout/material_drawer_item_secondary_icon.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/values-de/strings.xml b/fints4javaAndroidApp/src/main/res/values-de/strings.xml index 90b3c54b..e3af86eb 100644 --- a/fints4javaAndroidApp/src/main/res/values-de/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values-de/strings.xml @@ -7,6 +7,7 @@ Ja Nein Abrufen + Löschen Suchen @@ -84,4 +85,7 @@ ATC: ATC muss eine Zahl sein.\n\nDer eingebene ATC Wert \'%s\' kann jedoch nicht in eine Zahl konvertiert werden. + Möchten Sie das Konto \'%s\' wirklich löschen? + \n\nDies kann nicht rückgängig gemacht werden und die hierzu gespeicherten Daten gehen unwiederbringlich verloren. + diff --git a/fints4javaAndroidApp/src/main/res/values/colors.xml b/fints4javaAndroidApp/src/main/res/values/colors.xml index 0eca02c5..81fdad27 100644 --- a/fints4javaAndroidApp/src/main/res/values/colors.xml +++ b/fints4javaAndroidApp/src/main/res/values/colors.xml @@ -10,6 +10,8 @@ #303030 #FFFFFF + + @color/primaryTextColor_Dark #43A047 #E53935 diff --git a/fints4javaAndroidApp/src/main/res/values/ids.xml b/fints4javaAndroidApp/src/main/res/values/ids.xml new file mode 100644 index 00000000..f0a94555 --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/values/ids.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml index 47c6e526..800a18f0 100644 --- a/fints4javaAndroidApp/src/main/res/values/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Yes No Fetch + Delete Search @@ -84,4 +85,7 @@ ATC: ATC has to be a number.\n\nBut entered ATC value \'%s\' cannot be converted to a number. + Really delete account \'%s\'? + \n\nThis cannot be undone and data will be lost. + diff --git a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/BankingPersistenceJson.kt b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/BankingPersistenceJson.kt index 6fb5bf88..b33574f0 100644 --- a/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/BankingPersistenceJson.kt +++ b/persistence/json/BankingPersistenceJson/src/main/kotlin/net/dankito/banking/persistence/BankingPersistenceJson.kt @@ -21,6 +21,10 @@ open class BankingPersistenceJson( serializer.serializeObject(allAccounts, jsonFile) } + override fun deleteAccount(account: Account, allAccounts: List) { + serializer.serializeObject(allAccounts, jsonFile) + } + override fun readPersistedAccounts(): List { return serializer.deserializeListOr(jsonFile, Account::class.java, listOf()) }