diff --git a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java index fff6bd1e4..20275554d 100644 --- a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java +++ b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java @@ -175,36 +175,42 @@ public void onNext(Page 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; } /** diff --git a/app/src/main/java/org/mifos/mobilebanking/ui/activities/LoginActivity.java b/app/src/main/java/org/mifos/mobilebanking/ui/activities/LoginActivity.java index b867b5ee3..b3bae7f94 100644 --- a/app/src/main/java/org/mifos/mobilebanking/ui/activities/LoginActivity.java +++ b/app/src/main/java/org/mifos/mobilebanking/ui/activities/LoginActivity.java @@ -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 */ @@ -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); diff --git a/app/src/main/java/org/mifos/mobilebanking/ui/views/LoginView.java b/app/src/main/java/org/mifos/mobilebanking/ui/views/LoginView.java index 81615f5d3..6d84bc13b 100644 --- a/app/src/main/java/org/mifos/mobilebanking/ui/views/LoginView.java +++ b/app/src/main/java/org/mifos/mobilebanking/ui/views/LoginView.java @@ -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.