Forked from rohmanhakim/PasswordConfirmationStream.java
Created
February 15, 2017 09:04
-
-
Save AjiSetya/71bce0f69a8fa53da4582e2c380eebcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Boolean> passwordConfirmationStream = Observable.merge( | |
| RxTextView.textChanges(etPassword) | |
| .map(new Func1<CharSequence, Boolean>() { | |
| @Override | |
| public Boolean call(CharSequence charSequence) { | |
| return !charSequence.toString().trim().equals(etPasswordConfirmation.getText().toString()); | |
| } | |
| }), | |
| RxTextView.textChanges(etPasswordConfirmation) | |
| .map(new Func1<CharSequence, Boolean>() { | |
| @Override | |
| public Boolean call(CharSequence charSequence) { | |
| return !charSequence.toString().trim().equals(etPassword.getText().toString()); | |
| } | |
| }) | |
| ); | |
| Observer<Boolean> passwordConfirmationObserver = new Observer<Boolean>() { | |
| @Override | |
| public void onCompleted() { | |
| Log.d("rx","Password confirmation stream completed"); | |
| } | |
| @Override | |
| public void onError(Throwable e) { | |
| Log.d("rx",e.getMessage()); | |
| } | |
| @Override | |
| public void onNext(Boolean passwordConfirmationDontMatch) { | |
| Log.d("passwordConfirmation",String.valueOf(passwordConfirmationDontMatch.booleanValue())); | |
| showPasswordConfirmationAlert(passwordConfirmationDontMatch.booleanValue()); | |
| } | |
| }; | |
| public void showPasswordConfirmationAlert(boolean value){ | |
| if(value){ | |
| textPasswordConfirmationAlert.setText(R.string.password_confirmation_does_not_match_alert); | |
| textPasswordConfirmationAlert.setVisibility(View.VISIBLE); | |
| } else { | |
| textPasswordConfirmationAlert.setVisibility(View.GONE); | |
| } | |
| } | |
| passwordConfirmationStream.subscribe(passwordConfirmationObserver); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment