Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing the way error is shown from editText to editTextLayout #876

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions org.envirocar.app/res/layout/activity_signin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@
android:id="@+id/activity_signin_username_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the layout_height is changed to wrap_content because the layout needs to be big enough, to show the error.
more information: https://stackoverflow.com/a/44831214
see the below comments on this answer :)

android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signin_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signin_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to them which doesn't have any end icon so after making their height wrap_content, they all still have a similar height. As the height changes to wrap_content after an error is shown, via this they all have same height even before error shows.


<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signin_username_input"
Expand All @@ -91,14 +92,15 @@
android:id="@+id/activity_signin_password_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signin_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signin_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signin_username_input_layout"
app:layout_constraintWidth_max="500dp"
app:endIconMode="password_toggle"
app:errorIconDrawable="@null"
app:endIconDrawable="@drawable/custom_password_eye"
app:endIconTint="@color/white_cario">

Expand Down
67 changes: 43 additions & 24 deletions org.envirocar.app/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@
android:id="@+id/activity_signup_username_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signup_username_input"
Expand All @@ -78,7 +79,7 @@
android:layout_height="match_parent"
android:layout_below="@+id/activity_login_logo"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/ic_action_user"
android:drawableStart="@drawable/ic_action_user"
android:hint="@string/username"
android:inputType="textPersonName" />

Expand All @@ -88,20 +89,21 @@
android:id="@+id/activity_signup_email_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_username_input_layout"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signup_email_input"
style="@style/envirocar.login.edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="@drawable/ic_action_mail"
android:drawableStart="@drawable/ic_action_mail"
android:hint="@string/email"
android:inputType="textPersonName" />

Expand All @@ -111,7 +113,7 @@
android:id="@+id/activity_signup_password_1_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
Expand All @@ -120,7 +122,8 @@
app:layout_constraintWidth_max="500dp"
app:endIconMode="password_toggle"
app:endIconDrawable="@drawable/custom_password_eye"
app:endIconTint="@color/white_cario">
app:endIconTint="@color/white_cario"
app:errorIconDrawable="@null">


<androidx.appcompat.widget.AppCompatEditText
Expand All @@ -137,7 +140,7 @@
android:id="@+id/activity_signup_password_2_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
Expand Down Expand Up @@ -166,18 +169,26 @@
android:buttonTint="@color/white_cario"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_password_2_layout" />

<TextView
android:id="@+id/activity_signup_tou_text"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_signup_tou_text_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/signup_acknowledge_tou_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario"
app:layout_constraintBottom_toTopOf="@id/activity_signup_tou_checkbox"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toEndOf="@id/activity_signup_tou_checkbox"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_checkbox" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_checkbox"
app:layout_constraintWidth_max="500dp" >
<TextView
android:id="@+id/activity_signup_tou_text"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/signup_acknowledge_tou_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario" />

</com.google.android.material.textfield.TextInputLayout>

<CheckBox
android:id="@+id/activity_signup_ps_checkbox"
Expand All @@ -186,19 +197,27 @@
android:layout_marginTop="20dp"
android:buttonTint="@color/white_cario"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_text" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_text_layout" />

<TextView
android:id="@+id/activity_signup_ps_text"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_signup_ps_text_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/signup_acknowledge_ps_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario"
app:layout_constraintBottom_toTopOf="@+id/activity_signup_ps_checkbox"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toEndOf="@id/activity_signup_ps_checkbox"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_checkbox" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_checkbox"
app:layout_constraintWidth_max="500dp">
<TextView
android:id="@+id/activity_signup_ps_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/signup_acknowledge_ps_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario" />

</com.google.android.material.textfield.TextInputLayout>

<androidx.cardview.widget.CardView
android:id="@+id/activity_signup_register_button"
Expand All @@ -212,7 +231,7 @@
app:cardElevation="10dp"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_text">
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_text_layout">

<TextView
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;

import org.envirocar.app.BaseApplicationComponent;
import org.envirocar.app.R;
Expand Down Expand Up @@ -85,6 +86,10 @@ public static void startActivity(Context context) {
protected EditText usernameEditText;
@BindView(R.id.activity_login_password_input)
protected EditText passwordEditText;
@BindView(R.id.activity_signin_username_input_layout)
protected TextInputLayout usernameEditTextLayout;
@BindView(R.id.activity_signin_password_input_layout)
protected TextInputLayout passwordEditTextLayout;
@BindView(R.id.activity_login_logo)
protected ImageView logoImageView;

Expand Down Expand Up @@ -155,22 +160,22 @@ protected void onLoginClicked() {
View focusView = null;

// Reset errors
this.usernameEditText.setError(null);
this.passwordEditText.setError(null);
this.usernameEditTextLayout.setError(null);
this.passwordEditTextLayout.setError(null);

// Store values at the time of the login attempt
String username = usernameEditText.getText().toString().trim();
String password = passwordEditText.getText().toString();

// check for valid password
if (password == null || password.isEmpty() || password.equals("")) {
this.passwordEditText.setError(getString(R.string.error_field_required), errorPassword);
if (password == null || password.isEmpty()) {
Copy link
Contributor Author

@cdhiraj40 cdhiraj40 Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password.equals("") was removed cause password.isEmpty() was already checking the same here.
the same reason for below removal of username.equals("")

this.passwordEditTextLayout.setError(getString(R.string.error_field_required));
focusView = this.passwordEditText;
}

// check for valid username
if (username == null || username.isEmpty() || username.equals("")) {
this.usernameEditText.setError(getString(R.string.error_field_required), errorUsername);
if (username == null || username.isEmpty()) {
this.usernameEditTextLayout.setError(getString(R.string.error_field_required));
focusView = this.usernameEditText;
}

Expand Down Expand Up @@ -226,8 +231,8 @@ public void onError(Throwable e) {
if (e instanceof LoginException) {
switch (((LoginException) e).getType()) {
case USERNAME_OR_PASSWORD_INCORRECT:
usernameEditText.setError(getString(R.string.error_invalid_credentials), errorUsername);
passwordEditText.setError(getString(R.string.error_invalid_credentials), errorPassword);
usernameEditTextLayout.setError(getString(R.string.error_invalid_credentials));
passwordEditTextLayout.setError(getString(R.string.error_invalid_credentials));
break;
case MAIL_NOT_CONFIREMED:
// show alert dialog
Expand All @@ -240,10 +245,10 @@ public void onError(Throwable e) {
.show();
break;
case UNABLE_TO_COMMUNICATE_WITH_SERVER:
passwordEditText.setError(getString(R.string.error_host_not_found), errorPassword);
passwordEditTextLayout.setError(getString(R.string.error_host_not_found));
break;
default:
passwordEditText.setError(getString(R.string.logbook_invalid_input), errorPassword);
passwordEditTextLayout.setError(getString(R.string.logbook_invalid_input));
break;
}
} else if (!checkNetworkConnection()) {
Expand All @@ -261,4 +266,4 @@ private boolean checkNetworkConnection() {
return true;
return false;
}
}
}
Loading