@Test public void testLoadMoreTweets() { Mockito.when(twitterService.loadTweets(Matchers.eq(1))) .thenReturn(TestData.tweets(20)); Mockito.when(twitterService.loadTweets(Matchers.eq(2))) .thenReturn(TestData.tweets(8)); TweetListModel tweetListModel = viewModel.initAndResume(); assertThat(tweetListModel.getItems()).hasSize(20); viewModel.loadNextPage(); assertThat(tweetListModel.getItems()).hasSize(28); }
public void loadNextPage() { if (!isLoadingNextPage().get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), TwitterService.PAGE_SIZE); loadingNextPage.set(true); disposable.add(twitterService.loadTweets(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()) ); } }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { public void loadNextPage() { if (!isLoadingNextPage().get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), TwitterService.PAGE_SIZE); loadingNextPage.set(true); disposable.add(twitterService.loadTweets(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()) ); } } }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { public void loadNextPage() { if (!isLoadingNextPage().get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), TwitterService.PAGE_SIZE); loadingNextPage.set(true); disposable.add(twitterService.loadTweets(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()) ); } } @Inject  TweetListViewModel(); }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { public void loadNextPage() { if (!isLoadingNextPage().get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), TwitterService.PAGE_SIZE); loadingNextPage.set(true); disposable.add(twitterService.loadTweets(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()) ); } } @Inject  TweetListViewModel(); void loadNextPage(); }
TweetListViewModel extends RxListViewModel<Void, TweetListModel> { public void loadNextPage() { if (!isLoadingNextPage().get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), TwitterService.PAGE_SIZE); loadingNextPage.set(true); disposable.add(twitterService.loadTweets(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == TwitterService.PAGE_SIZE); }, throwable -> model.error()) ); } } @Inject  TweetListViewModel(); void loadNextPage();  }