Skip to content

Commit

Permalink
Merge pull request #913 from m-sameer/issue#895
Browse files Browse the repository at this point in the history
Fix #895: Add error text below password EditText in LoginActivity
  • Loading branch information
Saksham Handu authored Jan 2, 2019
2 parents 8813856 + 6c9a848 commit f4ec0b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
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();
}

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

0 comments on commit f4ec0b0

Please sign in to comment.