Implemented standard views for a form to make more pleasant and consistent forms

This commit is contained in:
dankito 2020-09-12 23:37:45 +02:00
parent 4709038f8a
commit 731c2b7d51
12 changed files with 207 additions and 73 deletions

View File

@ -70,14 +70,14 @@ open class AddAccountDialog : DialogFragment() {
protected open fun setupUI(rootView: View) { protected open fun setupUI(rootView: View) {
rootView.apply { rootView.apply {
initBankListAutocompletion(edtxtBank) initBankListAutocompletion(edtxtBank.actualEditText)
edtxtCustomerId.addTextChangedListener(otherEditTextChangedWatcher) edtxtCustomerId.actualEditText.addTextChangedListener(otherEditTextChangedWatcher)
edtxtPin.addTextChangedListener(otherEditTextChangedWatcher) edtxtPassword.actualEditText.addTextChangedListener(otherEditTextChangedWatcher)
addAccountIfEnterPressed(edtxtBank) addAccountIfEnterPressed(edtxtBank.actualEditText)
addAccountIfEnterPressed(edtxtCustomerId) addAccountIfEnterPressed(edtxtCustomerId.actualEditText)
addAccountIfEnterPressed(edtxtPin) addAccountIfEnterPressed(edtxtPassword.actualEditText)
btnAddAccount.setOnClickListener { addAccount() } btnAddAccount.setOnClickListener { addAccount() }
btnCancel.setOnClickListener { dismiss() } btnCancel.setOnClickListener { dismiss() }
@ -114,13 +114,13 @@ open class AddAccountDialog : DialogFragment() {
protected open fun addAccount() { protected open fun addAccount() {
selectedBank?.let { selectedBank -> // should always be non-null at this stage selectedBank?.let { selectedBank -> // should always be non-null at this stage
val customerId = edtxtCustomerId.text.toString() val customerId = edtxtCustomerId.text
val pin = edtxtPin.text.toString() val password = edtxtPassword.text
btnAddAccount.isEnabled = false btnAddAccount.isEnabled = false
pgrbrAddAccount.visibility = View.VISIBLE pgrbrAddAccount.visibility = View.VISIBLE
presenter.addAccountAsync(selectedBank, customerId, pin) { response -> presenter.addAccountAsync(selectedBank, customerId, password) { response ->
context?.asActivity()?.runOnUiThread { context?.asActivity()?.runOnUiThread {
btnAddAccount.isEnabled = true btnAddAccount.isEnabled = true
pgrbrAddAccount.visibility = View.GONE pgrbrAddAccount.visibility = View.GONE
@ -192,7 +192,7 @@ open class AddAccountDialog : DialogFragment() {
protected open fun bankSelected(bank: BankInfo) { protected open fun bankSelected(bank: BankInfo) {
selectedBank = bank selectedBank = bank
edtxtBank.setText(bank.name) edtxtBank.text = bank.name
edtxtCustomerId.requestFocus() edtxtCustomerId.requestFocus()
@ -217,8 +217,8 @@ open class AddAccountDialog : DialogFragment() {
protected open fun checkIfRequiredDataEnteredOnUiThread() { protected open fun checkIfRequiredDataEnteredOnUiThread() {
val requiredDataEntered = selectedBank != null val requiredDataEntered = selectedBank != null
&& selectedBank?.supportsFinTs3_0 == true && selectedBank?.supportsFinTs3_0 == true
&& edtxtCustomerId.text.toString().isNotEmpty() && edtxtCustomerId.text.isNotEmpty()
&& edtxtPin.text.toString().isNotEmpty() && edtxtPassword.text.isNotEmpty()
btnAddAccount.isEnabled = requiredDataEntered btnAddAccount.isEnabled = requiredDataEntered
} }

View File

@ -4,6 +4,10 @@ import android.view.KeyEvent
import android.widget.EditText import android.widget.EditText
val EditText.textString: String
get() = this.text.toString()
fun EditText.addEnterPressedListener(enterPressed: () -> Boolean) { fun EditText.addEnterPressedListener(enterPressed: () -> Boolean) {
this.setOnKeyListener { _, keyCode, event -> this.setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {

View File

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

View File

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

View File

@ -6,68 +6,40 @@
android:padding="@dimen/dialog_add_account_padding" android:padding="@dimen/dialog_add_account_padding"
> >
<com.google.android.material.textfield.TextInputLayout <net.dankito.banking.ui.android.views.FormEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_bank"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edtxtBank" android:id="@+id/edtxtBank"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height" android:layout_height="wrap_content"
android:hint="@string/dialog_add_account_enter_bank"
android:selectAllOnFocus="true" android:selectAllOnFocus="true"
android:inputType="text" android:inputType="text"
/> />
</com.google.android.material.textfield.TextInputLayout>
<net.dankito.banking.ui.android.views.FormSectionTitle
<TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dialog_add_account_customer_id_and_password_hint_top_margin" android:text="@string/online_banking_credentials_section_title"
android:layout_marginBottom="@dimen/dialog_add_account_customer_id_and_password_hint_bottom_margin"
android:textStyle="bold"
android:textSize="@dimen/dialog_add_account_customer_id_and_password_hint_text_size"
android:text="@string/dialog_add_account_customer_id_and_password_hint"
/> />
<com.google.android.material.textfield.TextInputLayout <net.dankito.banking.ui.android.views.FormEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin"
android:hint="@string/dialog_add_account_enter_online_banking_login_name"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edtxtCustomerId" android:id="@+id/edtxtCustomerId"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height" android:layout_height="wrap_content"
android:hint="@string/online_banking_credentials_login_name"
android:inputType="text" android:inputType="text"
/> />
</com.google.android.material.textfield.TextInputLayout>
<net.dankito.banking.ui.android.views.FormEditText
<com.google.android.material.textfield.TextInputLayout android:id="@+id/edtxtPassword"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_add_account_field_bottom_margin" android:hint="@string/online_banking_credentials_password"
android:hint="@string/dialog_add_account_enter_online_banking_password"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edtxtPin"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_add_account_edit_text_height"
android:inputType="textPassword" android:inputType="textPassword"
/> />
</com.google.android.material.textfield.TextInputLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/lytButtonBar" android:id="@+id/lytButtonBar"

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/form_section_height"
android:layout_marginTop="@dimen/form_section_margin_top"
android:layout_marginBottom="@dimen/form_section_margin_bottom"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</com.google.android.material.textfield.TextInputLayout>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/txtvwSectionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/form_section_title_margin_top"
android:layout_marginBottom="@dimen/form_section_title_margin_bottom"
android:textSize="@dimen/form_section_title_text_size"
android:textColor="@color/colorPrimary"
/>
</LinearLayout>

View File

@ -11,6 +11,10 @@
<string name="search">Suchen</string> <string name="search">Suchen</string>
<string name="online_banking_credentials_section_title">Online-Banking Zugangsdaten</string>
<string name="online_banking_credentials_login_name">Login Name</string>
<string name="online_banking_credentials_password">Passwort</string>
<string name="navigation_drawer_open">Seitenleiste öffnen</string> <string name="navigation_drawer_open">Seitenleiste öffnen</string>
<string name="navigation_drawer_close">Seitenleiste schließen</string> <string name="navigation_drawer_close">Seitenleiste schließen</string>
<string name="nav_header_title">@string/app_name</string> <string name="nav_header_title">@string/app_name</string>
@ -35,9 +39,6 @@
<string name="fragment_home_transfer_money_with_same_data">Neue Überweisung mit gleichen Daten</string> <string name="fragment_home_transfer_money_with_same_data">Neue Überweisung mit gleichen Daten</string>
<string name="dialog_add_account_enter_bank">Bank (Suche auch mittels Bankleitzahl oder Ort):</string> <string name="dialog_add_account_enter_bank">Bank (Suche auch mittels Bankleitzahl oder Ort):</string>
<string name="dialog_add_account_customer_id_and_password_hint">Online-Banking Zugangsdaten</string>
<string name="dialog_add_account_enter_online_banking_login_name">Login Name</string>
<string name="dialog_add_account_enter_online_banking_password">Passwort</string>
<string name="dialog_add_account_add">Hinzufügen</string> <string name="dialog_add_account_add">Hinzufügen</string>
<string name="dialog_add_account_bank_does_not_support_fints_3_error_message">%s untersützt FinTS 3.0 nicht und kann deshalb mit dieser App nicht verwendet werden.</string> <string name="dialog_add_account_bank_does_not_support_fints_3_error_message">%s untersützt FinTS 3.0 nicht und kann deshalb mit dieser App nicht verwendet werden.</string>
<string name="dialog_add_account_message_could_not_add_account">Konto konnte nicht hinzugefügt werden.\n\nFehlermeldung Ihrer Bank:\n\n%s</string> <string name="dialog_add_account_message_could_not_add_account">Konto konnte nicht hinzugefügt werden.\n\nFehlermeldung Ihrer Bank:\n\n%s</string>

View File

@ -9,4 +9,21 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="FormEditText">
<attr name="android:text" />
<attr name="android:hint" />
<attr name="android:inputType" />
<attr name="android:selectAllOnFocus" />
</declare-styleable>
<declare-styleable name="FormSectionTitle">
<attr name="android:text" />
</declare-styleable>
</resources> </resources>

View File

@ -27,6 +27,9 @@
<color name="info_icon_color">#007aff</color> <color name="info_icon_color">#007aff</color>
<!-- darker_gray: #aaa -->
<color name="formSectionDivideColor">#e0e0e0</color>
<color name="fabTextColor">#FFFFFF</color> <color name="fabTextColor">#FFFFFF</color>
<!-- <color name="fabLabelBackgroundColor">@color/black_semi_transparent</color>--> <!-- <color name="fabLabelBackgroundColor">@color/black_semi_transparent</color>-->

View File

@ -14,6 +14,14 @@
<dimen name="fab_margin_bottom_without_toolbar">16dp</dimen> <dimen name="fab_margin_bottom_without_toolbar">16dp</dimen>
<dimen name="fab_margin_bottom_with_toolbar">42dp</dimen> <dimen name="fab_margin_bottom_with_toolbar">42dp</dimen>
<dimen name="form_padding">12dp</dimen>
<dimen name="form_section_height">60dp</dimen>
<dimen name="form_section_margin_top">6dp</dimen>
<dimen name="form_section_margin_bottom">6dp</dimen>
<dimen name="form_section_title_text_size">15sp</dimen>
<dimen name="form_section_title_margin_top">18dp</dimen>
<dimen name="form_section_title_margin_bottom">8dp</dimen>
<dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen> <dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen>
<dimen name="fragment_account_transaction_transactions_summary_height">24dp</dimen> <dimen name="fragment_account_transaction_transactions_summary_height">24dp</dimen>
@ -34,9 +42,6 @@
<dimen name="dialog_add_account_label_height">24dp</dimen> <dimen name="dialog_add_account_label_height">24dp</dimen>
<dimen name="dialog_add_account_edit_text_height">40dp</dimen> <dimen name="dialog_add_account_edit_text_height">40dp</dimen>
<dimen name="dialog_add_account_field_bottom_margin">10dp</dimen> <dimen name="dialog_add_account_field_bottom_margin">10dp</dimen>
<dimen name="dialog_add_account_customer_id_and_password_hint_text_size">15sp</dimen>
<dimen name="dialog_add_account_customer_id_and_password_hint_top_margin">6dp</dimen>
<dimen name="dialog_add_account_customer_id_and_password_hint_bottom_margin">6dp</dimen>
<dimen name="dialog_add_account_buttons_width">120dp</dimen> <dimen name="dialog_add_account_buttons_width">120dp</dimen>
<dimen name="dialog_add_account_progress_bar_height">40dp</dimen> <dimen name="dialog_add_account_progress_bar_height">40dp</dimen>
<dimen name="dialog_add_account_progress_bar_width">40dp</dimen> <dimen name="dialog_add_account_progress_bar_width">40dp</dimen>

View File

@ -11,6 +11,10 @@
<string name="search">Search</string> <string name="search">Search</string>
<string name="online_banking_credentials_section_title">Online banking login data</string>
<string name="online_banking_credentials_login_name">Login name</string>
<string name="online_banking_credentials_password">Password</string>
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="nav_header_title">@string/app_name</string> <string name="nav_header_title">@string/app_name</string>
@ -35,9 +39,6 @@
<string name="fragment_home_transfer_money_with_same_data">New transfer with same data</string> <string name="fragment_home_transfer_money_with_same_data">New transfer with same data</string>
<string name="dialog_add_account_enter_bank">Bank (find also by bank code or city):</string> <string name="dialog_add_account_enter_bank">Bank (find also by bank code or city):</string>
<string name="dialog_add_account_customer_id_and_password_hint">Online banking login data</string>
<string name="dialog_add_account_enter_online_banking_login_name">Login name</string>
<string name="dialog_add_account_enter_online_banking_password">Password</string>
<string name="dialog_add_account_add">Add</string> <string name="dialog_add_account_add">Add</string>
<string name="dialog_add_account_bank_does_not_support_fints_3_error_message">%s does not support FinTS 3.0 and therefore cannot be used in this application.</string> <string name="dialog_add_account_bank_does_not_support_fints_3_error_message">%s does not support FinTS 3.0 and therefore cannot be used in this application.</string>
<string name="dialog_add_account_message_could_not_add_account">Could not add account.\n\nError message from your bank:\n\n%s</string> <string name="dialog_add_account_message_could_not_add_account">Could not add account.\n\nError message from your bank:\n\n%s</string>