now inflation is executing on UI thread by default

This commit is contained in:
Gavriil Sitnikov 2016-03-22 16:32:51 +03:00
parent 7dfd59cd1c
commit 50dfbbaa8a
1 changed files with 12 additions and 1 deletions

View File

@ -69,7 +69,7 @@ public abstract class ViewControllerFragment<TState extends Serializable, TLogic
private final BehaviorSubject<TActivity> activitySubject = BehaviorSubject.create();
private final BehaviorSubject<Pair<ViewGroup, Bundle>> viewSubject = BehaviorSubject.create();
private final Scheduler backgroundScheduler = RxAndroidUtils.createLooperScheduler();
private Scheduler backgroundScheduler;
@Nullable
private ViewController viewController;
private Subscription viewControllerSubscription;
@ -111,6 +111,15 @@ public abstract class ViewControllerFragment<TState extends Serializable, TLogic
})
.observeOn(AndroidSchedulers.mainThread());
/**
* Override it to enable inflation of view and creation of {@link ViewController} in background.
*
* @return Returns if it should do work in background. False by default.
*/
protected boolean isCreationInBackgroundEnabled() {
return false;
}
/**
* Returns specific object which contains state of ViewController.
*
@ -145,6 +154,8 @@ public abstract class ViewControllerFragment<TState extends Serializable, TLogic
? (TState) savedInstanceState.getSerializable(VIEW_CONTROLLER_STATE_EXTRA)
: (getArguments() != null ? (TState) getArguments().getSerializable(VIEW_CONTROLLER_STATE_EXTRA) : null);
backgroundScheduler = isCreationInBackgroundEnabled() ? RxAndroidUtils.createLooperScheduler() : AndroidSchedulers.mainThread();
viewControllerSubscription = viewControllerObservable.subscribe(this::onViewControllerChanged, Lc::assertion);
}