subscription in construction bug fixed
This commit is contained in:
parent
82fb10d94a
commit
311db7b074
|
|
@ -66,7 +66,6 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
|||
this.activity = (TActivity) creationContext.activity;
|
||||
this.fragment = (TFragment) creationContext.fragment;
|
||||
this.container = creationContext.container;
|
||||
baseUiBindable.onCreate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -158,6 +157,14 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
|||
return baseUiBindable.untilDestroy(observable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls right after construction of {@link ViewController}.
|
||||
* Happens at {@link ViewControllerFragment#onActivityCreated(View, ViewControllerActivity, Bundle)}.
|
||||
*/
|
||||
public void onCreate() {
|
||||
baseUiBindable.onCreate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when {@link ViewController} have started.
|
||||
* Happens at {@link ViewControllerFragment#onStart(View, ViewControllerActivity)}.
|
||||
|
|
|
|||
|
|
@ -140,7 +140,14 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
|||
state.onCreate();
|
||||
}
|
||||
viewControllerSubscription = Observable
|
||||
.combineLatest(activitySubject.distinctUntilChanged(), viewSubject.distinctUntilChanged(), this::createViewController)
|
||||
.combineLatest(activitySubject.distinctUntilChanged(), viewSubject.distinctUntilChanged(),
|
||||
(activity, viewInfo) -> {
|
||||
final ViewController newViewController = createViewController(activity, viewInfo);
|
||||
if (newViewController != null) {
|
||||
newViewController.onCreate();
|
||||
}
|
||||
return newViewController;
|
||||
})
|
||||
.subscribe(this::onViewControllerChanged, Lc::assertion);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,14 +84,16 @@ public class BaseUiBindable implements UiBindable {
|
|||
@NonNull
|
||||
@Override
|
||||
public <T> Observable<T> untilStop(@NonNull final Observable<T> observable) {
|
||||
return observable.observeOn(AndroidSchedulers.mainThread())
|
||||
return isCreatedSubject.first()
|
||||
.switchMap(isCreated -> isCreated ? observable.observeOn(AndroidSchedulers.mainThread()) : Observable.empty())
|
||||
.takeUntil(isStartedSubject.filter(started -> !started));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T> Observable<T> untilDestroy(@NonNull final Observable<T> observable) {
|
||||
return observable.observeOn(AndroidSchedulers.mainThread())
|
||||
return isCreatedSubject.first()
|
||||
.switchMap(isCreated -> isCreated ? observable.observeOn(AndroidSchedulers.mainThread()) : Observable.empty())
|
||||
.takeUntil(isCreatedSubject.filter(created -> !created));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue