Skip to content

Instantly share code, notes, and snippets.

@rohmanhakim
Last active February 15, 2017 09:04
Show Gist options
  • Save rohmanhakim/e140e5c49d666a59b5b8ef5bbac3a18a to your computer and use it in GitHub Desktop.
Save rohmanhakim/e140e5c49d666a59b5b8ef5bbac3a18a to your computer and use it in GitHub Desktop.
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