From 731c2b7d51316aabadff3fe1a3431edd625de51c Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 12 Sep 2020 23:37:45 +0200 Subject: [PATCH] Implemented standard views for a form to make more pleasant and consistent forms --- .../ui/android/dialogs/AddAccountDialog.kt | 24 +++--- .../android/extensions/EditTextExtensions.kt | 4 + .../banking/ui/android/views/FormEditText.kt | 55 ++++++++++++++ .../ui/android/views/FormSectionTitle.kt | 40 ++++++++++ .../main/res/layout/dialog_add_account.xml | 76 ++++++------------- .../main/res/layout/view_form_edit_text.xml | 17 +++++ .../res/layout/view_form_section_title.xml | 19 +++++ .../src/main/res/values-de/strings.xml | 7 +- .../src/main/res/values/attrs.xml | 17 +++++ .../src/main/res/values/colors.xml | 3 + .../src/main/res/values/dimens.xml | 11 ++- .../src/main/res/values/strings.xml | 7 +- 12 files changed, 207 insertions(+), 73 deletions(-) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormEditText.kt create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormSectionTitle.kt create mode 100644 ui/BankingAndroidApp/src/main/res/layout/view_form_edit_text.xml create mode 100644 ui/BankingAndroidApp/src/main/res/layout/view_form_section_title.xml diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/AddAccountDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/AddAccountDialog.kt index b160319c..9df384af 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/AddAccountDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/AddAccountDialog.kt @@ -70,14 +70,14 @@ open class AddAccountDialog : DialogFragment() { protected open fun setupUI(rootView: View) { rootView.apply { - initBankListAutocompletion(edtxtBank) + initBankListAutocompletion(edtxtBank.actualEditText) - edtxtCustomerId.addTextChangedListener(otherEditTextChangedWatcher) - edtxtPin.addTextChangedListener(otherEditTextChangedWatcher) + edtxtCustomerId.actualEditText.addTextChangedListener(otherEditTextChangedWatcher) + edtxtPassword.actualEditText.addTextChangedListener(otherEditTextChangedWatcher) - addAccountIfEnterPressed(edtxtBank) - addAccountIfEnterPressed(edtxtCustomerId) - addAccountIfEnterPressed(edtxtPin) + addAccountIfEnterPressed(edtxtBank.actualEditText) + addAccountIfEnterPressed(edtxtCustomerId.actualEditText) + addAccountIfEnterPressed(edtxtPassword.actualEditText) btnAddAccount.setOnClickListener { addAccount() } btnCancel.setOnClickListener { dismiss() } @@ -114,13 +114,13 @@ open class AddAccountDialog : DialogFragment() { protected open fun addAccount() { selectedBank?.let { selectedBank -> // should always be non-null at this stage - val customerId = edtxtCustomerId.text.toString() - val pin = edtxtPin.text.toString() + val customerId = edtxtCustomerId.text + val password = edtxtPassword.text btnAddAccount.isEnabled = false pgrbrAddAccount.visibility = View.VISIBLE - presenter.addAccountAsync(selectedBank, customerId, pin) { response -> + presenter.addAccountAsync(selectedBank, customerId, password) { response -> context?.asActivity()?.runOnUiThread { btnAddAccount.isEnabled = true pgrbrAddAccount.visibility = View.GONE @@ -192,7 +192,7 @@ open class AddAccountDialog : DialogFragment() { protected open fun bankSelected(bank: BankInfo) { selectedBank = bank - edtxtBank.setText(bank.name) + edtxtBank.text = bank.name edtxtCustomerId.requestFocus() @@ -217,8 +217,8 @@ open class AddAccountDialog : DialogFragment() { protected open fun checkIfRequiredDataEnteredOnUiThread() { val requiredDataEntered = selectedBank != null && selectedBank?.supportsFinTs3_0 == true - && edtxtCustomerId.text.toString().isNotEmpty() - && edtxtPin.text.toString().isNotEmpty() + && edtxtCustomerId.text.isNotEmpty() + && edtxtPassword.text.isNotEmpty() btnAddAccount.isEnabled = requiredDataEntered } diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/EditTextExtensions.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/EditTextExtensions.kt index 162c65aa..5bceda8e 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/EditTextExtensions.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/EditTextExtensions.kt @@ -4,6 +4,10 @@ import android.view.KeyEvent import android.widget.EditText +val EditText.textString: String + get() = this.text.toString() + + fun EditText.addEnterPressedListener(enterPressed: () -> Boolean) { this.setOnKeyListener { _, keyCode, event -> if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) { diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormEditText.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormEditText.kt new file mode 100644 index 00000000..4820903f --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormEditText.kt @@ -0,0 +1,55 @@ +package net.dankito.banking.ui.android.views + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.inputmethod.EditorInfo +import android.widget.EditText +import com.google.android.material.textfield.TextInputLayout +import kotlinx.android.synthetic.main.view_form_edit_text.view.* +import net.dankito.banking.ui.android.R +import net.dankito.banking.ui.android.extensions.textString + + +open class FormEditText @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : TextInputLayout(context, attrs, defStyleAttr) { + + + init { + setupUi(context, attrs) + } + + private fun setupUi(context: Context, attrs: AttributeSet?) { + val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + val rootView = inflater.inflate(R.layout.view_form_edit_text, this, true) + + rootView.apply { + + context.theme.obtainStyledAttributes( + attrs, + R.styleable.FormEditText, + 0, 0).apply { + + try { + textInputLayout.hint = getString(R.styleable.FormEditText_android_hint) + + textInputEditText.setText(getString(R.styleable.FormEditText_android_text)) + textInputEditText.inputType = getInt(R.styleable.FormEditText_android_inputType, EditorInfo.TYPE_TEXT_VARIATION_NORMAL) + textInputEditText.setSelectAllOnFocus(getBoolean(R.styleable.FormEditText_android_selectAllOnFocus, false)) + } finally { + recycle() + } + } + } + } + + + open var text: String + get() = textInputEditText.textString + set(value) = textInputEditText.setText(value) + + open val actualEditText: EditText + get() = textInputEditText + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormSectionTitle.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormSectionTitle.kt new file mode 100644 index 00000000..1dcf1a2b --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/FormSectionTitle.kt @@ -0,0 +1,40 @@ +package net.dankito.banking.ui.android.views + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import kotlinx.android.synthetic.main.view_form_section_title.view.* +import net.dankito.banking.ui.android.R + + +open class FormSectionTitle @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : LinearLayout(context, attrs, defStyleAttr) { + + + init { + setupUi(context, attrs) + } + + private fun setupUi(context: Context, attrs: AttributeSet?) { + val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + val rootView = inflater.inflate(R.layout.view_form_section_title, this, true) + + rootView.apply { + + context.theme.obtainStyledAttributes( + attrs, + R.styleable.FormEditText, + 0, 0).apply { + + try { + txtvwSectionTitle.text = getString(R.styleable.FormEditText_android_text) + } finally { + recycle() + } + } + } + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/dialog_add_account.xml b/ui/BankingAndroidApp/src/main/res/layout/dialog_add_account.xml index 260fa99e..5d268483 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/dialog_add_account.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/dialog_add_account.xml @@ -6,67 +6,39 @@ android:padding="@dimen/dialog_add_account_padding" > - - - - - - - - - - - - - + - + - - + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/layout/view_form_section_title.xml b/ui/BankingAndroidApp/src/main/res/layout/view_form_section_title.xml new file mode 100644 index 00000000..57233feb --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/layout/view_form_section_title.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml index a628ea1f..9b0c2340 100644 --- a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml @@ -11,6 +11,10 @@ Suchen + Online-Banking Zugangsdaten + Login Name + Passwort + Seitenleiste öffnen Seitenleiste schließen @string/app_name @@ -35,9 +39,6 @@ Neue Überweisung mit gleichen Daten Bank (Suche auch mittels Bankleitzahl oder Ort): - Online-Banking Zugangsdaten - Login Name - Passwort Hinzufügen %s untersützt FinTS 3.0 nicht und kann deshalb mit dieser App nicht verwendet werden. Konto konnte nicht hinzugefügt werden.\n\nFehlermeldung Ihrer Bank:\n\n%s diff --git a/ui/BankingAndroidApp/src/main/res/values/attrs.xml b/ui/BankingAndroidApp/src/main/res/values/attrs.xml index 76ce3c7d..3c037cdc 100644 --- a/ui/BankingAndroidApp/src/main/res/values/attrs.xml +++ b/ui/BankingAndroidApp/src/main/res/values/attrs.xml @@ -9,4 +9,21 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values/colors.xml b/ui/BankingAndroidApp/src/main/res/values/colors.xml index a35a041a..b4441d89 100644 --- a/ui/BankingAndroidApp/src/main/res/values/colors.xml +++ b/ui/BankingAndroidApp/src/main/res/values/colors.xml @@ -27,6 +27,9 @@ #007aff + + #e0e0e0 + #FFFFFF diff --git a/ui/BankingAndroidApp/src/main/res/values/dimens.xml b/ui/BankingAndroidApp/src/main/res/values/dimens.xml index c6b002a5..0cf38bd1 100644 --- a/ui/BankingAndroidApp/src/main/res/values/dimens.xml +++ b/ui/BankingAndroidApp/src/main/res/values/dimens.xml @@ -14,6 +14,14 @@ 16dp 42dp + 12dp + 60dp + 6dp + 6dp + 15sp + 18dp + 8dp + 4dp 24dp @@ -34,9 +42,6 @@ 24dp 40dp 10dp - 15sp - 6dp - 6dp 120dp 40dp 40dp diff --git a/ui/BankingAndroidApp/src/main/res/values/strings.xml b/ui/BankingAndroidApp/src/main/res/values/strings.xml index c15d8e9e..e72dd2a8 100644 --- a/ui/BankingAndroidApp/src/main/res/values/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values/strings.xml @@ -11,6 +11,10 @@ Search + Online banking login data + Login name + Password + Open navigation drawer Close navigation drawer @string/app_name @@ -35,9 +39,6 @@ New transfer with same data Bank (find also by bank code or city): - Online banking login data - Login name - Password Add %s does not support FinTS 3.0 and therefore cannot be used in this application. Could not add account.\n\nError message from your bank:\n\n%s