Browse Source

Change Pin and Pass Form Validation on Button Click

new_design
Santosh Bhandary 3 years ago
parent
commit
2a52d84a2e
  1. 2
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/presenter/ChangePassNPInV2PresenterInterface.java
  2. 15
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/presenter/ChangePassNPinViewModel.java
  3. 9
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/view/ChangePassNPinActivity.java
  4. 11
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/presenter/ChangePasswordV2Presenter.java
  5. 2
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/presenter/ChangePasswordV2PresenterInterface.java
  6. 10
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/view/UserPasswordChangeV2Activity.java
  7. 38
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/presenter/ChangePinV2Presenter.java
  8. 1
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/presenter/ChangePinV2PresenterInterface.java
  9. 60
      app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/view/ChangeTxnPinActivity.java
  10. 2
      app/src/main/res/layout/activity_change_pass_n_pin_layout.xml
  11. 1
      app/src/main/res/layout/activity_change_password_v2.xml
  12. 1
      app/src/main/res/layout/activity_change_txn_pin.xml

2
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/presenter/ChangePassNPInV2PresenterInterface.java

@ -7,6 +7,8 @@ public interface ChangePassNPInV2PresenterInterface extends BasePresenterInterfa
void changePassNPin();
boolean validateAllChangePinPassForm();
ChangePassNPinLiveData getPassNPInChangeRelatedViewEvents(
ChangePassNPinLiveData.ChangePassNPinViewBindings viewBindings);

15
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/presenter/ChangePassNPinViewModel.java

@ -61,6 +61,21 @@ public class ChangePassNPinViewModel extends BaseViewModel implements ChangePass
.subscribeWith(new ChangePassNPinObserver(this.changePassNPinValidator.newPassword)));
}
@Override
public boolean validateAllChangePinPassForm() {
if(
changePassNPinValidator.isCurrentPasswordValid(changePassNPinValidator.currentPassword)&&
changePassNPinValidator.isNewPasswordValid(changePassNPinValidator.newPassword)&&
changePassNPinValidator.isConfirmPasswordValid(changePassNPinValidator.confirmPassword)&&
changePassNPinValidator.isCurrentPinValid(changePassNPinValidator.currentPin)&&
changePassNPinValidator.isNewPinValid(changePassNPinValidator.newPin)&&
changePassNPinValidator.isConfirmPinValid(changePassNPinValidator.confirmNewPin)
){
return true;
}
return false;
}
@Override
public ChangePassNPinLiveData getPassNPInChangeRelatedViewEvents(ChangePassNPinLiveData.ChangePassNPinViewBindings viewBindings) {
bindView(viewBindings);

9
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassNPin/view/ChangePassNPinActivity.java

@ -105,7 +105,9 @@ public class ChangePassNPinActivity extends BaseActivity implements ChangePassNP
changePassNPinLiveData.getCurrentPinInputLiveData().observe(this,this::onCurrentPinStateChanged);
changePassNPinLiveData.getNewPinInputLiveData().observe(this,this::onNewPinStateChanged);
changePassNPinLiveData.getConfirmPinInputLiveData().observe(this,this::onConfirmPinStateChanged);
changePassNPinLiveData.getAllFormValidLiveData().observe(this, result->btn_submit.setEnabled(result.isValid()));
changePassNPinLiveData.getAllFormValidLiveData().observe(this, result-> {
// btn_submit.setEnabled(result.isValid());
});
}
private void onConfirmPinStateChanged(FormInputStateDTO<String> state) {
@ -229,7 +231,10 @@ public class ChangePassNPinActivity extends BaseActivity implements ChangePassNP
@OnClick(R.id.btn_submit)
public void onBtnSubmitClicked()
{
viewModel.changePassNPin();
if(viewModel.validateAllChangePinPassForm()){
viewModel.changePassNPin();
}
}
}

11
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/presenter/ChangePasswordV2Presenter.java

@ -47,6 +47,7 @@ public class ChangePasswordV2Presenter extends BaseViewModel implements ChangePa
return changePasswordLiveData;
}
private void bindView(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings) {
viewEventCompositeDisposable.add(
Observable.combineLatest(
@ -95,6 +96,16 @@ public class ChangePasswordV2Presenter extends BaseViewModel implements ChangePa
.subscribeWith(new ChangePasswordObserver(this.changePasswordValidator.newPassword)));
}
@Override
public boolean validateAllChangePasswordForm() {
if((changePasswordValidator.isCurrentPasswordValid(changePasswordValidator.currentPassword))&&
(changePasswordValidator.isNewPasswordValid(changePasswordValidator.newPassword))&&
(changePasswordValidator.isConfirmPasswordValid(changePasswordValidator.confirmPassword))){
return true;
}
return false;
}
private class ChangePasswordValidator {

2
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/presenter/ChangePasswordV2PresenterInterface.java

@ -11,6 +11,8 @@ public interface ChangePasswordV2PresenterInterface extends BasePresenterInterfa
void changePassword();
boolean validateAllChangePasswordForm();
ChangePasswordLiveData getChangePasswordRelatedViewEvents(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings);

10
app/src/main/java/com/swifttech/remit/jmecustomer/features/changepassword/view/UserPasswordChangeV2Activity.java

@ -81,7 +81,9 @@ public class UserPasswordChangeV2Activity extends BaseActivity implements Change
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()));
changePasswordViewModel.getAllFormValidLiveData().observe(this, result-> {
// btn_submit.setEnabled(result.isValid());
});
}
private void onConfirmPasswordStateChanged(FormInputStateDTO<String> state) {
@ -151,7 +153,11 @@ public class UserPasswordChangeV2Activity extends BaseActivity implements Change
@OnClick(R.id.btn_submit)
public void onBtnSubmitClicked()
{
presenter.changePassword();
if(presenter.validateAllChangePasswordForm()){
hideKeyBoard();
presenter.changePassword();
}
}

38
app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/presenter/ChangePinV2Presenter.java

@ -44,9 +44,9 @@ public class ChangePinV2Presenter extends BaseViewModel implements ChangePinV2In
private void bindView(ChangePinLiveData.ChangePinViewBindings viewBindings) {
viewEventCompositeDisposable.add(
Observable.combineLatest(
viewBindings.getCurrentPinInputLiveData().map(this.changePinValidator::isCurrentPasswordValid),
viewBindings.getNewPinInputLiveData().map(this.changePinValidator::isNewPasswordValid),
viewBindings.getConfirmPinInputLiveData().map(this.changePinValidator::isConfirmPasswordValid),
viewBindings.getCurrentPinInputLiveData().map(this.changePinValidator::isCurrentPinValid),
viewBindings.getNewPinInputLiveData().map(this.changePinValidator::isNewPinValid),
viewBindings.getConfirmPinInputLiveData().map(this.changePinValidator::isConfirmPinValid),
(isCurrentPassValid, isNewPasswordValid, isConfirmPasswordValid) ->
isCurrentPassValid && isNewPasswordValid && isConfirmPasswordValid)
.subscribeWith(new DisposableObserver<Boolean>() {
@ -89,6 +89,18 @@ public class ChangePinV2Presenter extends BaseViewModel implements ChangePinV2In
.subscribeWith(new ChangePinObserver()));
}
@Override
public boolean validateAllChangePinForm() {
if (
changePinValidator.isCurrentPinValid(changePinValidator.currentPin)
&& changePinValidator.isNewPinValid(changePinValidator.newPin)
&& changePinValidator.isConfirmPinValid(changePinValidator.confirmPin)
) {
return true;
}
return false;
}
private class ChangePinValidator {
@ -96,9 +108,9 @@ public class ChangePinV2Presenter extends BaseViewModel implements ChangePinV2In
private String newPin;
private String confirmPin;
boolean isCurrentPasswordValid(CharSequence password) {
if (password != null && password.length() ==PIN_LENGTH) {
this.currentPin = password.toString();
boolean isCurrentPinValid(CharSequence currentPin) {
if (currentPin != null && currentPin.length() == PIN_LENGTH) {
this.currentPin = currentPin.toString();
changePinLiveData.setCurrentPinInputLiveData(new FormInputStateDTO<>(true, null));
return true;
} else {
@ -110,9 +122,9 @@ public class ChangePinV2Presenter extends BaseViewModel implements ChangePinV2In
}
boolean isNewPasswordValid(CharSequence password) {
if (password != null && password.length() ==PIN_LENGTH) {
this.newPin = password.toString();
boolean isNewPinValid(CharSequence newPin) {
if (newPin != null && newPin.length() == PIN_LENGTH) {
this.newPin = newPin.toString();
changePinLiveData.setNewPinInputLiveData(new FormInputStateDTO<>(true, null));
return true;
} else {
@ -124,11 +136,9 @@ public class ChangePinV2Presenter extends BaseViewModel implements ChangePinV2In
}
boolean isConfirmPasswordValid(CharSequence password) {
if (password != null && password.length() ==PIN_LENGTH) {
this.confirmPin = password.toString();
boolean isConfirmPinValid(CharSequence confirmPin) {
if (confirmPin != null && confirmPin.length() == PIN_LENGTH) {
this.confirmPin = confirmPin.toString();
changePinLiveData.setConfirmPinInputLiveData(new FormInputStateDTO<>(true, null));
return true;

1
app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/presenter/ChangePinV2PresenterInterface.java

@ -10,6 +10,7 @@ public interface ChangePinV2PresenterInterface extends BasePresenterInterface {
void changePin();
boolean validateAllChangePinForm();
ChangePinLiveData getChangePasswordRelatedViewEvents(ChangePinLiveData.ChangePinViewBindings viewBindings);

60
app/src/main/java/com/swifttech/remit/jmecustomer/features/changetxnpin/view/ChangeTxnPinActivity.java

@ -1,12 +1,12 @@
package com.swifttech.remit.jmecustomer.features.changetxnpin.view;
import androidx.lifecycle.ViewModelProvider;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.jakewharton.rxbinding3.widget.RxTextView;
@ -66,9 +66,8 @@ public class ChangeTxnPinActivity extends BaseActivity implements ChangePinV2Pre
}
private void initialize() {
this.viewModel=new ViewModelProvider(this,new ChangePinViewModelFactory(this)).get(ChangePinV2Presenter.class);
this.viewModel = new ViewModelProvider(this, new ChangePinViewModelFactory(this)).get(ChangePinV2Presenter.class);
ChangePinLiveData changePinLiveData = viewModel.getChangePasswordRelatedViewEvents(new ChangePinLiveData.ChangePinViewBindings(
RxTextView.textChanges(currentPin_edTxt).skipInitialValue(),
@ -76,39 +75,35 @@ public class ChangeTxnPinActivity extends BaseActivity implements ChangePinV2Pre
RxTextView.textChanges(confirmPin_edTxt).skipInitialValue()
));
changePinLiveData.getCurrentPinInputLiveData().observe(this,this::onCurrentPasswordStateChanged);
changePinLiveData.getNewPinInputLiveData().observe(this,this::onNewPasswordStateChanged);
changePinLiveData.getConfirmPinInputLiveData().observe(this,this::onConfirmPasswordStateChanged);
changePinLiveData.getAllFormValidLiveData().observe(this, result->btn_submit.setEnabled(result.isValid()));
changePinLiveData.getCurrentPinInputLiveData().observe(this, this::onCurrentPasswordStateChanged);
changePinLiveData.getNewPinInputLiveData().observe(this, this::onNewPasswordStateChanged);
changePinLiveData.getConfirmPinInputLiveData().observe(this, this::onConfirmPasswordStateChanged);
changePinLiveData.getAllFormValidLiveData().observe(this, result -> {
// btn_submit.setEnabled(result.isValid());
});
}
private void onConfirmPasswordStateChanged(FormInputStateDTO<String> state) {
if(state.isValid())
{
if (state.isValid()) {
confirmPin_TxtInputLayout.setError(null);
confirmPin_TxtInputLayout.setErrorEnabled(false);
if(state.hasData())
{
if (state.hasData()) {
confirmPin_edTxt.setText(state.getData());
}
}
else{
} else {
confirmPin_TxtInputLayout.setErrorEnabled(true);
confirmPin_TxtInputLayout.setError(state.getErrorMessage());
}
}
private void onNewPasswordStateChanged(FormInputStateDTO<String> state) {
if(state.isValid())
{
if (state.isValid()) {
newPin_TxtInputLayout.setError(null);
newPin_TxtInputLayout.setErrorEnabled(false);
if(state.hasData())
{
if (state.hasData()) {
newPin_edTxt.setText(state.getData());
}
}
else{
} else {
newPin_TxtInputLayout.setErrorEnabled(true);
newPin_TxtInputLayout.setError(state.getErrorMessage());
}
@ -116,41 +111,38 @@ public class ChangeTxnPinActivity extends BaseActivity implements ChangePinV2Pre
}
private void onCurrentPasswordStateChanged(FormInputStateDTO<String> state) {
if(state.isValid())
{
if (state.isValid()) {
currentPin_TxtInputLayout.setError(null);
currentPin_TxtInputLayout.setErrorEnabled(false);
if(state.hasData())
{
if (state.hasData()) {
currentPin_edTxt.setText(state.getData());
}
}
else{
} else {
currentPin_TxtInputLayout.setErrorEnabled(true);
currentPin_TxtInputLayout.setError(state.getErrorMessage());
}
}
private void performDefaultAction(Bundle savedInstanceState) {
if(savedInstanceState==null)
{
if (savedInstanceState == null) {
toolbarTitle.setText(getResources().getString(R.string.changepin_text));
iv_cancel.setVisibility(View.INVISIBLE);
}
}
@OnClick(R.id.iv_back)
public void onBackButtonClicked(View v)
{
public void onBackButtonClicked(View v) {
onBackPressed();
}
@OnClick(R.id.btn_submit)
public void onBtnSubmitClicked()
{
viewModel.changePin();
public void onBtnSubmitClicked() {
if (viewModel.validateAllChangePinForm()) {
hideKeyBoard();
viewModel.changePin();
}
}
}

2
app/src/main/res/layout/activity_change_pass_n_pin_layout.xml

@ -130,11 +130,11 @@
<com.swifttech.remit.jmecustomer.common.customwidgets.GmeButton
style="@style/MButton"
android:enabled="true"
android:id="@+id/btn_submit"
android:text="@string/save_password_text"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>
</LinearLayout>
</ScrollView>

1
app/src/main/res/layout/activity_change_password_v2.xml

@ -75,6 +75,7 @@
<com.swifttech.remit.jmecustomer.common.customwidgets.GmeButton
style="@style/MButton"
android:id="@+id/btn_submit"
android:enabled="true"
android:text="@string/save_password_text"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>

1
app/src/main/res/layout/activity_change_txn_pin.xml

@ -78,6 +78,7 @@
<com.swifttech.remit.jmecustomer.common.customwidgets.GmeButton
style="@style/MButton"
android:id="@+id/btn_submit"
android:enabled="true"
android:text="@string/save_password_text"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>

Loading…
Cancel
Save