Binding simplified to not observe on something if there are no callbacks

This commit is contained in:
Gavriil Sitnikov 2017-03-03 15:13:17 +03:00
parent 81149c8b57
commit 8c39890dc8
1 changed files with 8 additions and 4 deletions

View File

@ -158,11 +158,15 @@ public class BaseLifecycleBindable implements LifecycleBindable {
@NonNull final Action1<T> onNextAction,
@NonNull final Action1<Throwable> onErrorAction,
@NonNull final Action0 onCompletedAction) {
final Observable<T> actualObservable;
if (onNextAction == Actions.empty() && onNextAction == Actions.empty() && onNextAction == Actions.empty()) {
actualObservable = observable.doOnCompleted(onCompletedAction);
} else {
actualObservable = observable.observeOn(AndroidSchedulers.mainThread()).doOnCompleted(onCompletedAction);
}
return isCreatedSubject.first()
.switchMap(created -> created
? observable.observeOn(AndroidSchedulers.mainThread()).doOnCompleted(onCompletedAction)
: Observable.empty())
//TODO: basically takeUntil is calling completed so investigate observable = ***.first() behavior and doOnCompleted also
.switchMap(created -> created ? actualObservable : Observable.empty())
.takeUntil(conditionSubject.filter(condition -> condition))
.subscribe(onNextAction, throwable -> {
final boolean isRxError = throwable instanceof OnErrorThrowable;