diff --git a/ui/BankingAndroidApp/src/main/AndroidManifest.xml b/ui/BankingAndroidApp/src/main/AndroidManifest.xml index e5795f4a..41002078 100644 --- a/ui/BankingAndroidApp/src/main/AndroidManifest.xml +++ b/ui/BankingAndroidApp/src/main/AndroidManifest.xml @@ -17,7 +17,8 @@ + android:theme="@style/AppTheme" + > @@ -25,6 +26,7 @@ + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDeleteAccountAlert.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDeleteAccountAlert.kt new file mode 100644 index 00000000..da431b05 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDeleteAccountAlert.kt @@ -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() + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDismissChangesAlert.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDismissChangesAlert.kt new file mode 100644 index 00000000..6e01711d --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/alerts/AskDismissChangesAlert.kt @@ -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() + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingComponent.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingComponent.kt index 8ee28f5d..a5e97066 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingComponent.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingComponent.kt @@ -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) } \ No newline at end of file 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 new file mode 100644 index 00000000..9480da08 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt @@ -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() + } +} \ No newline at end of file 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 988ed5c6..0a7e04e3 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 @@ -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?) { diff --git a/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_close_24.xml b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_close_24.xml new file mode 100644 index 00000000..16d6d37d --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_close_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_save_24.xml b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_save_24.xml new file mode 100644 index 00000000..1a8d86d2 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_save_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_settings_24.xml b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_settings_24.xml new file mode 100644 index 00000000..41a82ede --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_settings_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml b/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml new file mode 100644 index 00000000..027fc0c9 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/layout/dialog_bank_settings.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +