Merge pull request #32 from TouchInstinct/bind_fix

Binding fix of observing for empty callbacks
This commit is contained in:
Gavriil 2017-03-03 15:29:42 +03:00 committed by GitHub
commit c219f2cdbe
2 changed files with 18 additions and 5 deletions

View File

@ -23,7 +23,7 @@ repositories {
dependencies {
compile project(path: ':libraries:components')
compile 'net.danlew:android.joda:2.9.4.1'
compile 'net.danlew:android.joda:2.9.7'
compile 'com.android.support:multidex:1.0.1'
compile 'io.reactivex:rxandroid:1.2.1'

View File

@ -35,6 +35,7 @@ import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.exceptions.OnErrorThrowable;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Actions;
@ -168,12 +169,24 @@ public abstract class TouchinService<TLogic extends Logic> extends Service {
@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())
.switchMap(created -> created ? actualObservable : Observable.empty())
.takeUntil(conditionSubject.filter(condition -> condition))
.subscribe(onNextAction, onErrorAction);
.subscribe(onNextAction, throwable -> {
final boolean isRxError = throwable instanceof OnErrorThrowable;
if ((!isRxError && throwable instanceof RuntimeException)
|| (isRxError && throwable.getCause() instanceof RuntimeException)) {
Lc.assertion(throwable);
}
onErrorAction.call(throwable);
});
}
@SuppressWarnings("CPD-END")