-
Notifications
You must be signed in to change notification settings - Fork 159
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
3d99f48
1082f88
ba2627e
1bd5963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
<androidx.appcompat.widget.AppCompatEditText | ||
android:id="@+id/activity_signin_username_input" | ||
|
@@ -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"> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
@@ -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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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; | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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()) { | ||
|
@@ -261,4 +266,4 @@ private boolean checkNetworkConnection() { | |
return true; | ||
return false; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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 :)