Skip to content

Commit

Permalink
Fix openMF#895: Add error text below password EditText in LoginActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sameer committed Oct 28, 2018
1 parent aa20e9f commit 384fb03
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void detachView() {
*/
public void login(final String username, final String password) {
checkViewAttached();
if (isCredentialsValid(username, password)) {
if ((isUsernameValid(username) | isPasswordValid(password)) == 0) {
getMvpView().showProgress();
compositeDisposable.add(dataManager.login(username, password)
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -173,38 +173,42 @@ public void onNext(Page<Client> clientPage) {
);
}


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

private int isUsernameValid(final String username) {
final Resources resources = context.getResources();
final String correctUsername = username.replaceFirst("\\s++$", "").trim();
if (username == null || username.matches("\\s*") || username.isEmpty()) {
if (username.matches("\\s*") || username.isEmpty()) {
getMvpView().showUsernameError(context.getString(R.string.error_validation_blank,
context.getString(R.string.username)));
return false;
return 1;
} 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;
return 1;
} 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()) {
return 1;
}
return 0;
}

private int isPasswordValid(final String password) {
final Resources resources = context.getResources();
if (password == null || password.isEmpty()) {
getMvpView().showPasswordError(context.getString(R.string.error_validation_blank,
context.getString(R.string.password)));
return false;
return 1;
} 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;
return 1;
}

return true;
return 0;
}

/**
Expand Down

0 comments on commit 384fb03

Please sign in to comment.