From 38ec02d0c7c29a65a1d6155dfc3167c3921b537e Mon Sep 17 00:00:00 2001 From: Preyea Regmi Date: Thu, 4 Jun 2020 12:24:27 +0545 Subject: [PATCH] Forgot pass fixes --- .idea/caches/build_file_checksums.ser | Bin 659 -> 659 bytes .../profilechange/ChangePasswordLiveData.java | 80 +++++ .../ChangePasswordV2Presenter.java | 315 +++++++----------- .../ChangePasswordV2PresenterInterface.java | 15 +- .../ChangePasswordViewModelFactory.java | 28 ++ .../UserPasswordChangeV2Activity.java | 164 +++++---- .../layout/activity_change_password_v2.xml | 158 +++------ 7 files changed, 366 insertions(+), 394 deletions(-) create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordLiveData.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/ChangePasswordViewModelFactory.java diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 4634a0f697c0300e8d0ef88e5873706bc2fbf587..713e280d2f8643adb6d61e53675017300dbf0c1e 100644 GIT binary patch delta 15 XcmbQtI+=CC43^rtWg#2qd}jmzFbf8T delta 15 XcmbQtI+=CC43n~`OXLcF{B3Y diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordLiveData.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordLiveData.java new file mode 100644 index 00000000..515ad7c1 --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordLiveData.java @@ -0,0 +1,80 @@ +package com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; + +import com.gmeremit.online.gmeremittance_native.common.model.FormInputStateDTO; + +import io.reactivex.Observable; + +public class ChangePasswordLiveData { + + private MutableLiveData> currentPasswordInputLiveData; + private MutableLiveData> newPasswordInputLiveData; + private MutableLiveData> confirmPasswordInputLiveData; + private MutableLiveData allFormValidLiveData; + + public ChangePasswordLiveData() { + currentPasswordInputLiveData = new MutableLiveData<>(); + newPasswordInputLiveData = new MutableLiveData<>(); + confirmPasswordInputLiveData = new MutableLiveData<>(); + allFormValidLiveData = new MutableLiveData<>(); + } + + + public LiveData> getCurrentPasswordInputLiveData() { + return currentPasswordInputLiveData; + } + + public void setCurrentPasswordInputLiveData(FormInputStateDTO currentPasswordInputLiveData) { + this.currentPasswordInputLiveData.setValue(currentPasswordInputLiveData); + } + + public LiveData> getNewPasswordInputLiveData() { + return newPasswordInputLiveData; + } + + public void setNewPasswordInputLiveData(FormInputStateDTO newPasswordInputLiveData) { + this.newPasswordInputLiveData.setValue(newPasswordInputLiveData); + } + + public LiveData> getConfirmPasswordInputLiveData() { + return confirmPasswordInputLiveData; + } + + public void setConfirmPasswordInputLiveData(FormInputStateDTO confirmPasswordInputLiveData) { + this.confirmPasswordInputLiveData.setValue(confirmPasswordInputLiveData); + } + + public LiveData getAllFormValidLiveData() { + return allFormValidLiveData; + } + + public void setAllFormValidLiveData(FormInputStateDTO allFormValidLiveData) { + this.allFormValidLiveData.setValue(allFormValidLiveData); + } + + public static class ChangePasswordViewBindings { + private Observable currentPasswordInputLiveData; + private Observable newPasswordInputLiveData; + private Observable confirmPasswordInputLiveData; + + public ChangePasswordViewBindings(Observable currentPasswordInputLiveData, Observable newPasswordInputLiveData, Observable confirmPasswordInputLiveData) { + this.currentPasswordInputLiveData = currentPasswordInputLiveData; + this.newPasswordInputLiveData = newPasswordInputLiveData; + this.confirmPasswordInputLiveData = confirmPasswordInputLiveData; + } + + public Observable getCurrentPasswordInputLiveData() { + return currentPasswordInputLiveData; + } + + public Observable getNewPasswordInputLiveData() { + return newPasswordInputLiveData; + } + + public Observable getConfirmPasswordInputLiveData() { + return confirmPasswordInputLiveData; + } + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2Presenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2Presenter.java index 811ddad6..3ee5b683 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2Presenter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2Presenter.java @@ -1,173 +1,150 @@ package com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange; +import androidx.appcompat.app.AppCompatActivity; + import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.base.BasePresenter; +import com.gmeremit.online.gmeremittance_native.base.BaseViewModel; +import com.gmeremit.online.gmeremittance_native.common.model.FormInputStateDTO; import com.gmeremit.online.gmeremittance_native.profile.gateway.profilechange.ChangePasswordV2Gateway; import com.gmeremit.online.gmeremittance_native.profile.model.ChangePasswordActivityV2APIResponse; import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; +import com.gmeremit.online.gmeremittance_native.security.GMEAuthManager; import com.gmeremit.online.gmeremittance_native.utils.Constants; import com.gmeremit.online.gmeremittance_native.utils.Utils; import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObserverResponse; import com.gmeremit.online.gmeremittance_native.security.utils.SecurityUtils; +import io.reactivex.CompletableObserver; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.disposables.Disposable; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; -public class ChangePasswordV2Presenter extends BasePresenter implements ChangePasswordV2InteractorInterface, ChangePasswordV2PresenterInterface { +public class ChangePasswordV2Presenter extends BaseViewModel implements ChangePasswordV2InteractorInterface, ChangePasswordV2PresenterInterface { private final ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view; private final ChangePasswordV2Gateway gateway; - private String encCurrentPassword; - private String encNewPassword; - private String encConfirmPassword; + private final ChangePasswordLiveData changePasswordLiveData; + private final CompositeDisposable useCaseCompositeDisposable; + private final CompositeDisposable viewEventCompositeDisposable; + private final ChangePasswordValidator changePasswordValidator; - public ChangePasswordV2Presenter(ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view,ChangePasswordV2Gateway gateway) { + public ChangePasswordV2Presenter(ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view, ChangePasswordV2Gateway gateway) { this.view = view; this.gateway = gateway; - - this.encCurrentPassword = ""; - this.encNewPassword = ""; - this.encConfirmPassword = ""; + this.changePasswordValidator = new ChangePasswordValidator(); + changePasswordLiveData = new ChangePasswordLiveData(); + useCaseCompositeDisposable = new CompositeDisposable(); + viewEventCompositeDisposable = new CompositeDisposable(); } - @Deprecated @Override - public boolean validateData(String currentPass, String newPwd, String pwdConfrimString) { - boolean currentPwdValidation = true; - boolean confirmPwdValidation = true; - boolean newPwdValidation = true; - - if (currentPass.trim().length() < 1) { - this.view.setCurrentPasswordError(getStringfromStringId(R.string.password_empty_error)); - currentPwdValidation = false; - } - - if (!Utils.hasSpecialCharacters(newPwd)) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_symbol_required_error)); - newPwdValidation = false; - } - if (!Utils.hasNumbers(newPwd)) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_number_required_error)); - newPwdValidation = false; - } - if (newPwd.length() > 1 && newPwd.length() < 9) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_length_error)); - newPwdValidation = false; - } - if (!Utils.hasAtleastOnCapitalLetter(newPwd)) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_capital_letter_required_error)); - newPwdValidation = false; - } - if (newPwd.trim().length() < 1) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_empty_error)); - newPwdValidation = false; - } - - if (!newPwd.equals(pwdConfrimString)) { - this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_password_mismatch_error)); - confirmPwdValidation = false; - } - if (pwdConfrimString == null || pwdConfrimString.trim().length() < 1) { - this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_passowrd_empty_error)); - confirmPwdValidation = false; - } - + public ChangePasswordLiveData getChangePasswordRelatedViewEvents(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings) { + bindView(viewBindings); + return changePasswordLiveData; + } - if (currentPwdValidation) { - view.setCurrentPasswordError(null); - } - if (confirmPwdValidation) { - view.setConfirmPasswordError(null); + private void bindView(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings) { + viewEventCompositeDisposable.add( + Observable.combineLatest( + viewBindings.getCurrentPasswordInputLiveData().map(this.changePasswordValidator::isCurrentPasswordValid), + viewBindings.getNewPasswordInputLiveData().map(this.changePasswordValidator::isNewPasswordValid), + viewBindings.getConfirmPasswordInputLiveData().map(this.changePasswordValidator::isConfirmPasswordValid), + (isCurrentPassValid, isNewPasswordValid, isConfirmPasswordValid) -> + isCurrentPassValid && isNewPasswordValid && isConfirmPasswordValid) + .subscribeWith(new DisposableObserver() { + @Override + public void onNext(Boolean result) { + changePasswordLiveData.setAllFormValidLiveData(new FormInputStateDTO(result, "")); + } + + @Override + public void onError(Throwable e) { + changePasswordLiveData.setAllFormValidLiveData(new FormInputStateDTO(false, "")); + } + + @Override + public void onComplete() { + + } + })); + } - } + @Override + public void onViewReady() { - if (newPwdValidation) { - view.setNewPasswordError(null); + } - } + @Override + public void onViewNotReady() { - return currentPwdValidation && confirmPwdValidation && newPwdValidation; } + @Override - public boolean validateAll() { - boolean currentPwdValidation = true; - boolean confirmPwdValidation = true; - boolean newPwdValidation = true; - - if (encCurrentPassword == null || encCurrentPassword.trim().length() < 1) { - this.view.setCurrentPasswordError(getStringfromStringId(R.string.password_empty_error)); - currentPwdValidation = false; - } + public void changePassword() { + useCaseCompositeDisposable.add( + this.gateway.performChangePassRequest(this.gateway.getAuth(), this.gateway.getUserID(), this.changePasswordValidator.currentPassword, this.changePasswordValidator.newPassword, this.changePasswordValidator.confirmPassword) + .doOnSubscribe(d -> view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doFinally(() -> view.showProgressBar(false, "")) + .subscribeWith(new ChangePasswordObserver(this.changePasswordValidator.newPassword))); + } - if (encNewPassword == null || encNewPassword.trim().length() < 1) { - this.view.setNewPasswordError(getStringfromStringId(R.string.password_empty_error)); - newPwdValidation = false; - } - if (encConfirmPassword == null || encConfirmPassword.trim().length() < 1) { - this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_passowrd_empty_error)); - confirmPwdValidation = false; - } + private class ChangePasswordValidator { - if (currentPwdValidation) { - view.setCurrentPasswordError(null); - } - if (confirmPwdValidation) { - view.setConfirmPasswordError(null); + private String currentPassword; + private String newPassword; + private String confirmPassword; - } + boolean isCurrentPasswordValid(CharSequence password) { + if (password != null && password.length() > 0) { + this.currentPassword = password.toString(); + changePasswordLiveData.setCurrentPasswordInputLiveData(new FormInputStateDTO<>(true, null)); + return true; + } else { + this.currentPassword = null; + changePasswordLiveData.setCurrentPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); + return false; + } - if (newPwdValidation) { - view.setNewPasswordError(null); } - return currentPwdValidation && confirmPwdValidation && newPwdValidation; - } - @Override - public void changePassword(String currentPass, String newPass) { + boolean isNewPasswordValid(CharSequence password) { + if (password != null && password.length() > 0) { + this.newPassword = password.toString(); + changePasswordLiveData.setNewPasswordInputLiveData(new FormInputStateDTO<>(true, null)); + return true; + } else { + this.newPassword = null; + changePasswordLiveData.setNewPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); + return false; + } - this.gateway.performChangePassRequest(this.gateway.getAuth(), this.gateway.getUserID(), this.encCurrentPassword, this.encNewPassword, this.encConfirmPassword) - .doOnSubscribe(d -> view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new ChangePasswordObserver(this.encNewPassword)); - } + } - @Override - public void updateCurrentPassword(String encCurrentPassword) { - this.encCurrentPassword = encCurrentPassword; - } - @Override - public void updateNewPassword(String encNewPassword) { - this.encNewPassword = encNewPassword; - } - - @Override - public void updateConfirmPassword(String encConfirmPassword) { - this.encConfirmPassword = encConfirmPassword; - } + boolean isConfirmPasswordValid(CharSequence password) { + if (password != null && password.length() > 0) { + this.confirmPassword = password.toString(); + changePasswordLiveData.setConfirmPasswordInputLiveData(new FormInputStateDTO<>(true, null)); + return true; + } else { + this.currentPassword = null; + changePasswordLiveData.setConfirmPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); + return false; + } - private void encryptPassword(String newPassword, String pwdChangeMessage) { - SecurityUtils.generateKey() - .flatMap(key -> Observable.zip( - SecurityUtils.encryptUsingAES(newPassword, key).subscribeOn(Schedulers.io()), - encryptToKeyStore(key).subscribeOn(Schedulers.io()), - Observable.just(pwdChangeMessage), - FingerprintEncResult::new) - ).observeOn(AndroidSchedulers.mainThread()) - .subscribe(new FingerprintEncResultObserver()); + } - } - private Observable encryptToKeyStore(String data) { - return SecurityUtils.encryptUsingKeyStore(view.getContext(), data) - .flatMap(encKey ->Observable.just(encKey.getEncrypted())); } @@ -181,99 +158,59 @@ public class ChangePasswordV2Presenter extends BasePresenter implements ChangePa @Override protected void onSuccess(ChangePasswordActivityV2APIResponse changePasswordActivityV2APIResponse) { - view.showProgressBar(false,""); if (changePasswordActivityV2APIResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { - if (SecurityUtils.checkFingerPrintUsablity(view.getContext())) { - encryptPassword(newPassword, changePasswordActivityV2APIResponse.getData().getMessage()); - } else { + + GMEAuthManager gmeAuthManager = GMEAuthManager.getGmeAuthManager((AppCompatActivity) view.getContext()); + if (gmeAuthManager.isBiometricSupportedByDevice()) + gmeAuthManager.persistUserCredentialForFingerprintAuth(gateway.getUserID(), this.newPassword) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new CompletableObserver() { + @Override + public void onSubscribe(Disposable d) { + useCaseCompositeDisposable.add(d); + } + + @Override + public void onComplete() { + view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); + + } + + @Override + public void onError(Throwable e) { + view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); + } + }); + else { view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); } } else view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.FAILED, null); } + @Override public void onFailed(String message) { - view.showProgressBar(false,""); + view.showProgressBar(false, ""); view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); } @Override protected void onConnectionNotEstablished(String message) { - view.showProgressBar(false,""); + view.showProgressBar(false, ""); view.showPopUpMessage(message, CustomAlertDialog.AlertType.NO_INTERNET, null); } @Override protected void unauthorizedAccess(String message) { - view.showProgressBar(false,""); + view.showProgressBar(false, ""); gateway.clearAllUserData(); view.showPopUpMessage(message, CustomAlertDialog.AlertType.ALERT, alertType -> view.logout()); } } - public class FingerprintEncResult { - String encPwd; - String key; - String pwdChangeServerMessage; - - public FingerprintEncResult(String encPwd,String key, String pwdChangeServerMessage) { - this.encPwd = encPwd; - this.key=key; - this.pwdChangeServerMessage = pwdChangeServerMessage; - } - - public String getEncPwd() { - return encPwd; - } - - public String getPwdChangeServerMessage() { - return pwdChangeServerMessage; - } - - public String getKey() { - return key; - } - - @Override - public String toString() { - return "UserCredentialEncryptionResultDTO{" + - "encPwd='" + encPwd + '\'' + - ", key='" + key + '\'' + - ", pwdChangeServerMessage='" + pwdChangeServerMessage + '\'' + - '}'; - } - } - - public class FingerprintEncResultObserver extends DisposableObserver { - - @Override - public void onNext(FingerprintEncResult fingerprintEncResult) { - view.showProgressBar(false,""); - - if (fingerprintEncResult.getEncPwd() == null) { - gateway.flushBiometricData(); - view.showPopUpMessage(fingerprintEncResult.getPwdChangeServerMessage(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); - } else { - gateway.persistUserPwdForBiometric(fingerprintEncResult.getEncPwd()); - gateway.persistSecretKeyForBiometric(fingerprintEncResult.getKey()); - view.showPopUpMessage(fingerprintEncResult.getPwdChangeServerMessage(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); - } - } - - @Override - public void onError(Throwable e) { - view.showProgressBar(false,""); - gateway.flushBiometricData(); - } - - @Override - public void onComplete() { - - } - } - diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2PresenterInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2PresenterInterface.java index bfa8cf22..642e1243 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2PresenterInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/presenter/profilechange/ChangePasswordV2PresenterInterface.java @@ -9,27 +9,16 @@ import com.gmeremit.online.gmeremittance_native.base.BasePresenterInterface; public interface ChangePasswordV2PresenterInterface extends BasePresenterInterface { - boolean validateData(String currentPass, String newPass, String repeatPassword); - boolean validateAll(); - void changePassword(String currentPass,String newPass); + void changePassword(); - void updateCurrentPassword(String encCurrentPassword); + ChangePasswordLiveData getChangePasswordRelatedViewEvents(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings); - void updateNewPassword(String encNewPassword); - - void updateConfirmPassword(String encConfirmPassword); interface ChangePasswordV2ContractInterface extends BaseContractInterface { - void setNewPasswordError(String errorString); - - void setConfirmPasswordError(String passwords_does_not_match); - - void setCurrentPasswordError(String s); - Context getContext(); } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/ChangePasswordViewModelFactory.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/ChangePasswordViewModelFactory.java new file mode 100644 index 00000000..7c7d1f5c --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/ChangePasswordViewModelFactory.java @@ -0,0 +1,28 @@ +package com.gmeremit.online.gmeremittance_native.profile.view.profilechange; + +import androidx.annotation.NonNull; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + +import com.gmeremit.online.gmeremittance_native.loginV2.gateway.LoginV2Gateway; +import com.gmeremit.online.gmeremittance_native.loginV2.presenter.LoginV2Presenter; +import com.gmeremit.online.gmeremittance_native.loginV2.presenter.LoginV2PresenterInterface; +import com.gmeremit.online.gmeremittance_native.profile.gateway.profilechange.ChangePasswordV2Gateway; +import com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange.ChangePasswordV2Presenter; +import com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange.ChangePasswordV2PresenterInterface; + +public class ChangePasswordViewModelFactory implements ViewModelProvider.Factory { + + private final ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view; + + public ChangePasswordViewModelFactory(ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view) { + this.view=view; + } + + @SuppressWarnings("unchecked") + @NonNull + @Override + public T create(@NonNull Class modelClass) { + return (T) new ChangePasswordV2Presenter(view,new ChangePasswordV2Gateway()); + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/UserPasswordChangeV2Activity.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/UserPasswordChangeV2Activity.java index e8b98502..5e0e137c 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/UserPasswordChangeV2Activity.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/profile/view/profilechange/UserPasswordChangeV2Activity.java @@ -4,22 +4,25 @@ import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.RelativeLayout; -import android.widget.ScrollView; import android.widget.TextView; +import androidx.lifecycle.ViewModelProvider; + import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.base.BaseActivity; -import com.gmeremit.online.gmeremittance_native.customwidgets.GmeErrorTextView; -import com.gmeremit.online.gmeremittance_native.profile.gateway.profilechange.ChangePasswordV2Gateway; +import com.gmeremit.online.gmeremittance_native.common.model.FormInputStateDTO; +import com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange.ChangePasswordLiveData; import com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange.ChangePasswordV2Presenter; import com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange.ChangePasswordV2PresenterInterface; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; +import com.jakewharton.rxbinding3.widget.RxTextView; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; -public class UserPasswordChangeV2Activity extends BaseActivity implements ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface, View.OnClickListener { +public class UserPasswordChangeV2Activity extends BaseActivity implements ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface { @BindView(R.id.toolbar_title) @@ -29,47 +32,31 @@ public class UserPasswordChangeV2Activity extends BaseActivity implements Change View iv_cancel; @BindView(R.id.iv_back) View iv_back; - @BindView(R.id.btn_submit) - Button btn_submit; - - @BindView(R.id.currentPasswordErrorTxt) - GmeErrorTextView currentPasswordErrorTxt; - - @BindView(R.id.newPasswordErrorTxt) - GmeErrorTextView newPasswordErrorTxt; - - @BindView(R.id.confirmPasswordErrorTxt) - GmeErrorTextView confirmPasswordErrorTxt; + @BindView(R.id.currentPassword_edTxt) + TextInputEditText currentPassword_edTxt; - @BindView(R.id.keypadContainer) - FrameLayout keypadContainer; + @BindView(R.id.currentPassword_TxtInputLayout) + TextInputLayout currentPassword_TxtInputLayout; - @BindView(R.id.keypadBallon) - RelativeLayout ballonView; + @BindView(R.id.newPassword_edTxt) + TextInputEditText newPassword_edTxt; - @BindView(R.id.scrollView) - ScrollView scrollView; + @BindView(R.id.newPassword_TxtInputLayout) + TextInputLayout newPassword_TxtInputLayout; + @BindView(R.id.confirmPassword_edTxt) + TextInputEditText confirmPassword_edTxt; - @BindView(R.id.newPasswordText) - TextView newPasswordText; - - @BindView(R.id.confirmPasswordText) - TextView confirmPasswordText; - - @BindView(R.id.currentPasswordText) - TextView currentPasswordText; - - @BindView(R.id.rootViewChangePassword) - View rootView; + @BindView(R.id.confirmPassword_TxtInputLayout) + TextInputLayout confirmPassword_TxtInputLayout; + @BindView(R.id.btn_submit) + Button btn_submit; private ChangePasswordV2PresenterInterface presenter; - - @Override protected void onCreate(Bundle savedInstanceState) { enableActivityToTakeScreenShot(false); @@ -83,77 +70,76 @@ public class UserPasswordChangeV2Activity extends BaseActivity implements Change private void initialize() { - this.presenter=new ChangePasswordV2Presenter(this,new ChangePasswordV2Gateway()); - - + this.presenter=new ViewModelProvider(this,new ChangePasswordViewModelFactory(this)).get(ChangePasswordV2Presenter.class); + + ChangePasswordLiveData changePasswordViewModel = presenter.getChangePasswordRelatedViewEvents(new ChangePasswordLiveData.ChangePasswordViewBindings( + RxTextView.textChanges(currentPassword_edTxt).skipInitialValue(), + RxTextView.textChanges(newPassword_edTxt).skipInitialValue(), + RxTextView.textChanges(confirmPassword_edTxt).skipInitialValue() + )); + + changePasswordViewModel.getCurrentPasswordInputLiveData().observe(this,this::onCurrentPasswordStateChanged); + changePasswordViewModel.getNewPasswordInputLiveData().observe(this,this::onNewPasswordStateChanged); + changePasswordViewModel.getConfirmPasswordInputLiveData().observe(this,this::onConfirmPasswordStateChanged); + changePasswordViewModel.getAllFormValidLiveData().observe(this, result->btn_submit.setEnabled(result.isValid())); } - private void performDefaultAction(Bundle savedInstanceState) { - if(savedInstanceState==null) + private void onConfirmPasswordStateChanged(FormInputStateDTO state) { + if(state.isValid()) { - toolbarTitle.setText(getString(R.string.change_password_title_text)); - iv_cancel.setVisibility(View.INVISIBLE); + confirmPassword_TxtInputLayout.setError(null); + if(state.hasData()) + { + confirmPassword_edTxt.setText(state.getData()); + } } + else + confirmPassword_TxtInputLayout.setError(state.getErrorMessage()); } - - @Override - protected void onStart() { - super.onStart(); - iv_back.setOnClickListener(this); - btn_submit.setOnClickListener(this); - + private void onNewPasswordStateChanged(FormInputStateDTO state) { + if(state.isValid()) + { + newPassword_TxtInputLayout.setError(null); + if(state.hasData()) + { + newPassword_edTxt.setText(state.getData()); + } + } + else + newPassword_TxtInputLayout.setError(state.getErrorMessage()); } - @Override - protected void onStop() { - super.onStop(); - iv_back.setOnClickListener(null); - btn_submit.setOnClickListener(null); + private void onCurrentPasswordStateChanged(FormInputStateDTO state) { + if(state.isValid()) + { + currentPassword_TxtInputLayout.setError(null); + if(state.hasData()) + { + currentPassword_edTxt.setText(state.getData()); + } + } + else + currentPassword_TxtInputLayout.setError(state.getErrorMessage()); } - - - - - @Override - public void onClick(View v) { - - switch(v.getId()) + private void performDefaultAction(Bundle savedInstanceState) { + if(savedInstanceState==null) { - case R.id.iv_back: - onBackPressed(); - break; - - case R.id.btn_submit: - if(this.presenter.validateAll()) - { - hideKeyBoard(); - this.presenter.changePassword(null,null); - } - break; + toolbarTitle.setText(getString(R.string.change_password_title_text)); + iv_cancel.setVisibility(View.INVISIBLE); } } - @Override - public void setNewPasswordError(String error) { - newPasswordErrorTxt.setErrorText(error); - } - @Override - public void setConfirmPasswordError(String error) { - confirmPasswordErrorTxt.setErrorText(error); - } - @Override - public void setCurrentPasswordError(String error) { - currentPasswordErrorTxt.setErrorText(error); + @OnClick(R.id.btn_submit) + public void onBtnSubmitClicked() + { + presenter.changePassword(); } - @Override - public Context getContext() { - return this; - } + } diff --git a/app/src/main/res/layout/activity_change_password_v2.xml b/app/src/main/res/layout/activity_change_password_v2.xml index f7f9bd11..4002ba76 100644 --- a/app/src/main/res/layout/activity_change_password_v2.xml +++ b/app/src/main/res/layout/activity_change_password_v2.xml @@ -1,22 +1,14 @@ - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - + - - +