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

Fix #895: Add error text below password EditText in LoginActivity #913

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -175,36 +175,42 @@ public void onNext(Page<Client> clientPage) {


private boolean isCredentialsValid(final String username, final String password) {

boolean credentialValid = true;
final Resources resources = context.getResources();
final String correctUsername = username.replaceFirst("\\s++$", "").trim();
if (username == null || username.matches("\\s*") || username.isEmpty()) {
getMvpView().showUsernameError(context.getString(R.string.error_validation_blank,
context.getString(R.string.username)));
return false;
credentialValid = false;
} else if (username.length() < 5) {
getMvpView().showUsernameError(context.getString(R.string.error_validation_minimum_chars
, resources.getString(R.string.username), resources.getInteger(R.integer.
username_minimum_length)));
return false;
credentialValid = false;
} else if (correctUsername.contains(" ")) {
getMvpView().showUsernameError(context.getString(
R.string.error_validation_cannot_contain_spaces,
resources.getString(R.string.username),
context.getString(R.string.not_contain_username)));
return false;
} else if (password == null || password.isEmpty()) {
credentialValid = false;
} else {
getMvpView().clearUsernameError();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@m-sameer Add else and hide errors there. See #907 for reference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@m-sameer Remove this
and add else there remove the error.


if (password == null || password.isEmpty()) {
getMvpView().showPasswordError(context.getString(R.string.error_validation_blank,
context.getString(R.string.password)));
return false;
credentialValid = false;
} else if (password.length() < 6) {
getMvpView().showPasswordError(context.getString(R.string.error_validation_minimum_chars
, resources.getString(R.string.password), resources.getInteger(R.integer.
password_minimum_length)));
return false;
credentialValid = false;
} else {
getMvpView().clearPasswordError();
}

return true;
return credentialValid;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public void showPasswordError(String error) {
tilPassword.setError(error);
}

@Override
public void clearUsernameError() {
tilUsername.setErrorEnabled(false);
}

@Override
public void clearPasswordError() {
tilPassword.setErrorEnabled(false);
}

/**
* Called when Login Button is clicked, used for logging in the user
*/
Expand All @@ -119,8 +129,6 @@ public void onLoginClicked() {

final String username = tilUsername.getEditText().getEditableText().toString();
final String password = tilPassword.getEditText().getEditableText().toString();
tilUsername.setErrorEnabled(false);
tilPassword.setErrorEnabled(false);

if (Network.isConnected(this)) {
loginPresenter.login(username, password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public interface LoginView extends MVPView {

void showPasswordError(String error);

void clearUsernameError();

void clearPasswordError();

/**
* Should be called when the client is fetched successfully from API.
Expand Down