@Test public void testRetryAfterError() { when(wordPressService.listAuthors()) .thenReturn( Single.error(new RuntimeException()), authorResponse(2) ); AuthorListModel model = viewModel.initAndResume(); assertThat(model.size()).isEqualTo(0); viewModel.reloadData(); assertThat(model.size()).isEqualTo(2); }
@Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return (forceFetch ? authorsStore.fetch(0) : authorsStore.get(0)) .singleOrError() .doOnSuccess(Collections::sort) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(model::done, throwable -> model.error()); }
AuthorListViewModel extends RxListViewModel<Void, AuthorListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return (forceFetch ? authorsStore.fetch(0) : authorsStore.get(0)) .singleOrError() .doOnSuccess(Collections::sort) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(model::done, throwable -> model.error()); } }
AuthorListViewModel extends RxListViewModel<Void, AuthorListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return (forceFetch ? authorsStore.fetch(0) : authorsStore.get(0)) .singleOrError() .doOnSuccess(Collections::sort) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(model::done, throwable -> model.error()); } @Inject  AuthorListViewModel(); }
AuthorListViewModel extends RxListViewModel<Void, AuthorListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return (forceFetch ? authorsStore.fetch(0) : authorsStore.get(0)) .singleOrError() .doOnSuccess(Collections::sort) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(model::done, throwable -> model.error()); } @Inject  AuthorListViewModel(); void goToAuthorDetail(int position); }
AuthorListViewModel extends RxListViewModel<Void, AuthorListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return (forceFetch ? authorsStore.fetch(0) : authorsStore.get(0)) .singleOrError() .doOnSuccess(Collections::sort) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(model::done, throwable -> model.error()); } @Inject  AuthorListViewModel(); void goToAuthorDetail(int position);  }