Skip to content

Instantly share code, notes, and snippets.

@HIFILEO
Last active January 30, 2018 14:24
Show Gist options
  • Save HIFILEO/3929471d9e06074069721b406627c0fc to your computer and use it in GitHub Desktop.
Save HIFILEO/3929471d9e06074069721b406627c0fc to your computer and use it in GitHub Desktop.
//Save
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(LAST_UIMODEL, latestUiModel);
}
//Init ViewModel with saved state
public void init(@Nullable UiModel restoredUiModel) {
if (initialUiModel == null) {
if (restoredUiModel == null) {
initialUiModel = UiModel.initState();
startEventsObservable = Observable.just(new ScrollEvent(initialUiModel.getPageNumber() + 1));
} else {
//restore required
initialUiModel = UiModel.restoreState(restoredUiModel.getPageNumber(), new ArrayList<>(), null);
startEventsObservable = Observable.just(new RestoreEvent(initialUiModel.getPageNumber()));
}
bind();
}
}
/*Scan in Main Pipe*/
.scan(initialUiModel, (uiModel, result) -> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment