@Test public void testRetryAfterError() { Mockito.when(twitterService.loadTweets(Matchers.eq(1))) .thenReturn(Single.error(new RuntimeException())); TweetListModel model = viewModel.initAndResume(); assertThat(viewModel.isError().get()).isTrue(); Mockito.when(twitterService.loadTweets(Matchers.eq(1))) .thenReturn(TestData.tweets(10)); viewModel.reloadData(); assertThat(viewModel.isError().get()).isFalse(); assertThat(model.getItems()).hasSize(10); }
@Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return twitterService.loadTweets(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()); }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return twitterService.loadTweets(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()); } }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return twitterService.loadTweets(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()); } @Inject  TweetListViewModel(); }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return twitterService.loadTweets(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()); } @Inject  TweetListViewModel(); void loadNextPage(); }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { @Override protected Disposable reloadData(ObservableBoolean loadingAction, boolean forceFetch) { loadingAction.set(true); return twitterService.loadTweets(1) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingAction.set(false)) .subscribe(posts -> { model.done(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()); } @Inject  TweetListViewModel(); void loadNextPage();  }