Started BankSettingsDialog with most important fields

This commit is contained in:
dankito 2020-09-12 23:55:46 +02:00
parent 731c2b7d51
commit f847e5e651
16 changed files with 384 additions and 20 deletions

View File

@ -17,7 +17,8 @@
<activity
android:name="net.dankito.banking.ui.android.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -25,6 +26,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,25 @@
package net.dankito.banking.ui.android.alerts
import android.content.Context
import androidx.appcompat.app.AlertDialog
import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.model.TypedCustomer
import net.dankito.banking.ui.presenter.BankingPresenter
open class AskDeleteAccountAlert {
open fun show(bank: TypedCustomer, presenter: BankingPresenter, context: Context, accountDeleted: (() -> Unit)? = null) {
AlertDialog.Builder(context)
.setTitle(context.getString(R.string.alert_ask_delete_account_title, bank.displayName))
.setMessage(context.getString(R.string.alert_ask_delete_account_message))
.setPositiveButton(R.string.delete) { dialog, _ ->
presenter.deleteAccount(bank)
dialog.dismiss()
accountDeleted?.invoke()
}
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
.show()
}
}

View File

@ -0,0 +1,24 @@
package net.dankito.banking.ui.android.alerts
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import net.dankito.banking.ui.android.R
open class AskDismissChangesAlert {
open fun show(dialog: DialogFragment) {
val context = dialog.requireContext()
AlertDialog.Builder(context)
.setTitle(context.getString(R.string.alert_ask_discard_changes_title))
.setMessage(context.getString(R.string.alert_ask_discard_changes_message))
.setPositiveButton(R.string.discard) { alert, _ ->
alert.dismiss()
dialog.dismiss()
}
.setNegativeButton(R.string.cancel) { alert, _ -> alert.dismiss() }
.show()
}
}

View File

@ -7,6 +7,7 @@ import net.dankito.banking.ui.android.dialogs.AddAccountDialog
import net.dankito.banking.ui.android.dialogs.EnterTanDialog
import net.dankito.banking.ui.android.dialogs.SendMessageLogDialog
import net.dankito.banking.ui.android.dialogs.TransferMoneyDialog
import net.dankito.banking.ui.android.dialogs.settings.BankSettingsDialog
import net.dankito.banking.ui.android.home.HomeFragment
import javax.inject.Singleton
@ -32,6 +33,8 @@ interface BankingComponent {
fun inject(transferMoneyDialog: TransferMoneyDialog)
fun inject(bankSettingsDialog: BankSettingsDialog)
fun inject(sendMessageLogDialog: SendMessageLogDialog)
}

View File

@ -0,0 +1,133 @@
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.edtxtCustomerId
import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtPassword
import kotlinx.android.synthetic.main.dialog_bank_settings.view.*
import net.dankito.banking.ui.android.R
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.TypedCustomer
import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.hideKeyboardDelayed
import javax.inject.Inject
open class BankSettingsDialog : DialogFragment() {
companion object {
const val DialogTag = "BankSettingsDialog"
}
protected lateinit var bank: TypedCustomer
@Inject
protected lateinit var presenter: BankingPresenter
init {
BankingComponent.component.inject(this)
}
fun show(bank: TypedCustomer, activity: AppCompatActivity, fullscreen: Boolean = false) {
this.bank = bank
val style = if (fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.FloatingDialog
setStyle(STYLE_NORMAL, style)
show(activity.supportFragmentManager, DialogTag)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.dialog_bank_settings, container, false)
setupUI(rootView)
return rootView
}
protected open fun setupUI(rootView: View) {
rootView.apply {
toolbar.apply {
title = bank.bankName
inflateMenu(R.menu.menu_bank_settings_dialog)
setOnMenuItemClickListener { item -> onOptionsItemSelected(item) }
setNavigationOnClickListener { askToDismissChanges() }
}
edtxtBankName.text = bank.displayName
edtxtCustomerId.text = bank.customerId
edtxtPassword.text = bank.password
btnDeleteAccount.setOnClickListener { askUserToDeleteAccount() }
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.mnitmSaveChanges -> saveChangesAndCloseDialog()
else -> super.onOptionsItemSelected(item)
}
}
protected val hasUnsavedChanges: Boolean
get() = didChange(edtxtBankName, bank.displayName)
|| didChange(edtxtCustomerId, bank.customerId)
|| didChange(edtxtPassword, bank.password)
protected open fun didChange(editedValue: FormEditText, originalValue: String): Boolean {
return editedValue.text != originalValue
}
protected open fun saveChangesAndCloseDialog(): Boolean {
if (hasUnsavedChanges) {
saveChanges()
}
closeDialog()
return true
}
protected open fun saveChanges() {
bank.userSetDisplayName = edtxtBankName.text
bank.customerId = edtxtCustomerId.text
bank.password = edtxtPassword.text
presenter.accountUpdated(bank)
}
protected open fun askToDismissChanges() {
if (hasUnsavedChanges) {
AskDismissChangesAlert().show(this)
}
else {
closeDialog()
}
}
protected open fun askUserToDeleteAccount() {
AskDeleteAccountAlert().show(bank, presenter, requireContext()) {
closeDialog()
}
}
protected open fun closeDialog() {
dismiss()
}
}

View File

@ -2,7 +2,6 @@ package net.dankito.banking.ui.android.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
@ -19,6 +18,7 @@ import com.mikepenz.materialdrawer.util.getDrawerItem
import com.mikepenz.materialdrawer.util.removeItemByPosition
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.android.dialogs.settings.BankSettingsDialog
import net.dankito.banking.ui.android.extensions.withIcon
import net.dankito.banking.ui.model.TypedCustomer
import net.dankito.banking.ui.presenter.BankingPresenter
@ -144,8 +144,7 @@ open class DrawerView(
val accountItem = AccountDrawerItem()
.withName(customer.displayName)
.withLevel(AccountLevel)
// .withSecondaryIcon(GoogleMaterial.Icon.gmd_settings) // used when editing account is implemented
.withSecondaryIcon(GoogleMaterial.Icon.gmd_delete)
.withSecondaryIcon(R.drawable.ic_baseline_settings_24)
.withSecondaryIconColor(activity, R.color.primaryTextColor_Dark)
.withOnSecondaryIconClickedListener { closeDrawerAndEditAccount(customer) }
.withIcon(customer.iconUrl ?: "")
@ -183,17 +182,7 @@ open class DrawerView(
}
private fun editAccount(customer: TypedCustomer) {
// TODO: implement editing account (e.g. displayed name etc.)
AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.dialog_account_settings_ask_should_account_be_deleted_title, customer.displayName))
.setMessage(activity.getString(R.string.dialog_account_settings_ask_should_account_be_deleted_message))
.setPositiveButton(R.string.delete) { dialog, _ ->
dialog.dismiss()
presenter.deleteAccount(customer)
}
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
.show()
BankSettingsDialog().show(customer, activity, true)
}
private fun showAppVersion(navigationHeaderView: View?) {

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="@drawable/ic_baseline_close_24"
/>
</com.google.android.material.appbar.AppBarLayout>
<!-- dummy layout to fetch focus on start so that dialog doesn't start with keyboard displayed -->
<LinearLayout
android:orientation="vertical"
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
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
android:id="@+id/edtxtBankName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dialog_bank_settings_bank_name"
android:inputType="text"
/>
<net.dankito.banking.ui.android.views.FormSectionTitle
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/online_banking_credentials_section_title"
/>
<net.dankito.banking.ui.android.views.FormEditText
android:id="@+id/edtxtCustomerId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/online_banking_credentials_login_name"
android:inputType="text"
/>
<net.dankito.banking.ui.android.views.FormEditText
android:id="@+id/edtxtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/online_banking_credentials_password"
android:inputType="textPassword"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:id="@+id/btnDeleteAccount"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_bank_settings_delete_account_button_height"
style="?android:attr/buttonBarButtonStyle"
android:textColor="@color/destructiveColor"
android:text="@string/dialog_bank_settings_delete_account"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -203,7 +203,7 @@
android:layout_alignParentBottom="true"
android:background="@null"
app:srcCompat="@drawable/ic_baseline_info_24"
android:tint="@color/info_icon_color"
android:tint="@color/infoIconColor"
/>
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="@+id/mnitmSaveChanges"
android:icon="@drawable/ic_baseline_save_24"
android:title="@string/save"
app:showAsAction="always"
android:visible="true"
/>
</menu>

View File

@ -7,6 +7,9 @@
<string name="yes">Ja</string>
<string name="no">Nein</string>
<string name="fetch">Abrufen</string>
<string name="save">Speichern</string>
<string name="discard">Verwerfen</string>
<string name="delete">Löschen</string>
<string name="search">Suchen</string>
@ -97,8 +100,17 @@
<string name="dialog_enter_atc_atc_label">ATC:</string>
<string name="dialog_enter_atc_error_entered_atc_is_not_a_number">ATC muss eine Zahl sein.\n\nDer eingebene ATC Wert \'%s\' kann jedoch nicht in eine Zahl konvertiert werden.</string>
<string name="dialog_account_settings_ask_should_account_be_deleted_title">Konto \'%s\' wirklich löschen?</string>
<string name="dialog_account_settings_ask_should_account_be_deleted_message">Alle Daten zu diesem Konto werden lokal vollständig gelöscht.
<string name="dialog_bank_settings_title">Bank settings</string>
<string name="dialog_bank_settings_bank_name">Name</string>
<string name="dialog_bank_settings_delete_account">Konto löschen</string>
<string name="alert_ask_discard_changes_title">Nicht gespeicherte Änderungen</string>
<string name="alert_ask_discard_changes_message">Es wurden nicht alle Änderungen gespeichert. Sind Sie sich sicher, dass Sie sie verwerfen möchten?\n\n(TODO: Oder einfach: Änderungen verwerfen?)</string>
<string name="alert_ask_delete_account_title">Konto \'%s\' wirklich löschen?</string>
<string name="alert_ask_delete_account_message">Alle Daten zu diesem Konto werden lokal vollständig gelöscht.
\n\nZum Wiederherstellen müssen sie, falls dann noch möglich, erneut vom Bankserver abgeholt werden.</string>

View File

@ -30,6 +30,9 @@
<!-- darker_gray: #aaa -->
<color name="formSectionDivideColor">#e0e0e0</color>
<!-- colorError = #B00020 -->
<color name="destructiveColor">#ff3b30</color>
<color name="fabTextColor">#FFFFFF</color>
<!-- <color name="fabLabelBackgroundColor">@color/black_semi_transparent</color>-->

View File

@ -133,6 +133,8 @@
<dimen name="dialog_enter_atc_enter_value_field_value_margin_left">6dp</dimen>
<dimen name="dialog_enter_atc_buttons_width">120dp</dimen>
<dimen name="dialog_bank_settings_delete_account_button_height">50dp</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>

View File

@ -7,6 +7,9 @@
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="fetch">Fetch</string>
<string name="save">Save</string>
<string name="discard">Discard</string>
<string name="delete">Delete</string>
<string name="search">Search</string>
@ -97,8 +100,17 @@
<string name="dialog_enter_atc_atc_label">ATC:</string>
<string name="dialog_enter_atc_error_entered_atc_is_not_a_number">ATC has to be a number.\n\nBut entered ATC value \'%s\' cannot be converted to a number.</string>
<string name="dialog_account_settings_ask_should_account_be_deleted_title">Really delete account \'%s\'?</string>
<string name="dialog_account_settings_ask_should_account_be_deleted_message">All data for this account will locally be permanently deleted.
<string name="dialog_bank_settings_title">Bank settings</string>
<string name="dialog_bank_settings_bank_name">Name</string>
<string name="dialog_bank_settings_delete_account">Delete account</string>
<string name="alert_ask_discard_changes_title">Unsaved changed</string>
<string name="alert_ask_discard_changes_message">Changed data hasn\'t been saved. Are you sure you want to discard them?\n\n(TODO: Oder einfach: Discard changes?)</string>
<string name="alert_ask_delete_account_title">Really delete account \'%s\'?</string>
<string name="alert_ask_delete_account_message">All data for this account will locally be permanently deleted.
\n\nThey can only be restored, if then still possible, by retrieving it again from your bank server.</string>