@Test public void testLoadMore() { when(wordPressService.listPosts(eq(1))) .thenReturn(postResponse(10)); when(wordPressService.listPosts(eq(2))) .thenReturn(postResponse(6)); PostListModel model = viewModel.initAndResume(); viewModel.loadNextPage(); List<Post> items = model.getItems(); assertThat(items.size()).isEqualTo(16); }
public void loadNextPage() { if (!loadingNextPage.get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), WordPressService.POST_PAGE_SIZE); loadingNextPage.set(true); disposable.add(getObservable(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()) ); } }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { public void loadNextPage() { if (!loadingNextPage.get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), WordPressService.POST_PAGE_SIZE); loadingNextPage.set(true); disposable.add(getObservable(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()) ); } } }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { public void loadNextPage() { if (!loadingNextPage.get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), WordPressService.POST_PAGE_SIZE); loadingNextPage.set(true); disposable.add(getObservable(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()) ); } } @Inject  PostListViewModel(); }
PostListViewModel extends RxListViewModel<PostListArgument, PostListModel> { public void loadNextPage() { if (!loadingNextPage.get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), WordPressService.POST_PAGE_SIZE); loadingNextPage.set(true); disposable.add(getObservable(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(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> { public void loadNextPage() { if (!loadingNextPage.get() && model.isMoreDataAvailable()) { int page = calcNextPage(model.getItems().size(), WordPressService.POST_PAGE_SIZE); loadingNextPage.set(true); disposable.add(getObservable(page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> loadingNextPage.set(false)) .subscribe(posts -> { model.append(posts); model.setMoreDataAvailable(posts.size() == WordPressService.POST_PAGE_SIZE); }, throwable -> model.error()) ); } } @Inject  PostListViewModel(); void goToDetail(int position); void loadNextPage(); boolean isToolbarVisible(); String getToolbarTitle();  }