@Test public void testRetryAfterError() { when(wordPressService.listPosts(eq(1))) .thenReturn(Single.error(new RuntimeException())); PostListModel model = viewModel.initAndResume(); assertThat(viewModel.isError().get()).isTrue(); when(wordPressService.listPosts(eq(1))) .thenReturn(postResponse(6)); viewModel.reloadData(); assertThat(viewModel.isError().get()).isFalse(); assertThat(model.getItems().size()).isEqualTo(6); }
@Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return getObservable(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()); }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return getObservable(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()); } }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return getObservable(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()); } @Inject  PostListViewModel(); }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return getObservable(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()); } @Inject  PostListViewModel(); void goToDetail(int position); void loadNextPage(); boolean isToolbarVisible(); String getToolbarTitle(); }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return getObservable(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()); } @Inject  PostListViewModel(); void goToDetail(int position); void loadNextPage(); boolean isToolbarVisible(); String getToolbarTitle();  }