fixed set state error

This commit is contained in:
Oksana Pokrovskaya 2018-03-15 12:24:03 +03:00
parent 168e47d91a
commit b13e8dc827
2 changed files with 11 additions and 10 deletions

View File

@ -103,7 +103,7 @@ public class ViewControllerFragment<TState extends AbstractState, TActivity exte
private ViewController viewController;
private Disposable viewControllerSubscription;
private TState state;
public TState state;
private boolean started;
private boolean stateCreated;
@ -199,9 +199,18 @@ public class ViewControllerFragment<TState extends AbstractState, TActivity exte
} catch (ShouldNotHappenException ignored) {
// ignored, it`s ok to get null state there
}
state = savedInstanceState != null
? stateFromViewModel != null ? stateFromViewModel : (TState) savedInstanceState.getSerializable(VIEW_CONTROLLER_STATE_EXTRA)
: (getArguments() != null ? (TState) getArguments().getSerializable(VIEW_CONTROLLER_STATE_EXTRA) : null);
if (state != null) {
if (inDebugMode) {
state = reserialize(state);
}
tryCreateState(getContext());
} else if (isStateRequired()) {
Lc.assertion("State is required and null");
}
if (stateFromViewModel == null) {
try {
Method stateSetter = viewModelClass.getSuperclass().getDeclaredMethod("setState", state.getClass().getSuperclass());
@ -212,14 +221,6 @@ public class ViewControllerFragment<TState extends AbstractState, TActivity exte
} catch (InvocationTargetException ignored) {
}
}
if (state != null) {
if (inDebugMode) {
state = reserialize(state);
}
tryCreateState(getContext());
} else if (isStateRequired()) {
Lc.assertion("State is required and null");
}
viewControllerSubscription = Observable
.combineLatest(activitySubject.distinctUntilChanged(), viewSubject.distinctUntilChanged(),

View File

@ -32,7 +32,7 @@ open class StateViewModel<TState : AbstractState>(application: Application,
untilDestroy(Observable.just(Any()), Consumer { onStateCreated() })
}
protected fun onStateCreated() {
protected open fun onStateCreated() {
}