From 384fb03401bb36003641c3466b2c38bded8c1742 Mon Sep 17 00:00:00 2001 From: Mohammad Sameer <mhdsmr2@gmail.com> Date: Sun, 28 Oct 2018 21:17:30 +0530 Subject: [PATCH] Fix #895: Add error text below password EditText in LoginActivity --- .../presenters/LoginPresenter.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) 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 1716ab929..9de55ad57 100644 --- a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java +++ b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java @@ -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()) @@ -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; } /**