|
Observable<Boolean> emptyFieldStream = Observable.combineLatest( |
|
RxTextView.textChanges(etEmail) |
|
.map(new Func1<CharSequence, Boolean>() { |
|
@Override |
|
public Boolean call(CharSequence charSequence) { |
|
return TextUtils.isEmpty(charSequence); |
|
} |
|
}), |
|
RxTextView.textChanges(etPassword) |
|
.map(new Func1<CharSequence, Boolean>() { |
|
@Override |
|
public Boolean call(CharSequence charSequence) { |
|
return TextUtils.isEmpty(charSequence); |
|
} |
|
}), |
|
RxTextView.textChanges(etPasswordConfirmation) |
|
.map(new Func1<CharSequence, Boolean>() { |
|
@Override |
|
public Boolean call(CharSequence charSequence) { |
|
return TextUtils.isEmpty(charSequence); |
|
} |
|
}), |
|
new Func3<Boolean, Boolean, Boolean, Boolean>() { |
|
@Override |
|
public Boolean call(Boolean emailEmpty, Boolean passwordEmpty, Boolean passwordConfirmationEmpty) { |
|
return emailEmpty || passwordEmpty || passwordConfirmationEmpty; |
|
} |
|
} |
|
); |
|
|
|
Observable<Boolean> invalidFieldsStream = Observable.combineLatest( |
|
emailStream, |
|
passwordStream, |
|
passwordConfirmationStream, |
|
emptyFieldStream, new Func4<Boolean, Boolean, Boolean, Boolean, Boolean>() { |
|
@Override |
|
public Boolean call(Boolean emailInvalid, Boolean passwordInvalid, Boolean passwordConfirmationInvalid, Boolean emptyFieldExist) { |
|
return !emailInvalid && !passwordInvalid && !passwordConfirmationInvalid && !emptyFieldExist; |
|
} |
|
}); |
|
|
|
Observer<Boolean> invalidFieldsObserver = new Observer<Boolean>() { |
|
@Override |
|
public void onCompleted() { |
|
Log.d("rx","All field valid stream completed"); |
|
} |
|
|
|
@Override |
|
public void onError(Throwable e) { |
|
Log.d("rx",e.getMessage()); |
|
} |
|
|
|
@Override |
|
public void onNext(Boolean invalidFieldExist) { |
|
Log.d("invalidFieldsStream",String.valueOf(invalidFieldExist.booleanValue())); |
|
btnSubmit.setEnabled(invalidFieldExist); |
|
} |
|
}; |
|
|
|
invalidFieldsStream.subscribe(invalidFieldsObserver); |