fixed set state error
This commit is contained in:
parent
168e47d91a
commit
b13e8dc827
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ open class StateViewModel<TState : AbstractState>(application: Application,
|
|||
untilDestroy(Observable.just(Any()), Consumer { onStateCreated() })
|
||||
}
|
||||
|
||||
protected fun onStateCreated() {
|
||||
protected open fun onStateCreated() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue