0

I have an API that lets me retrieve an object like this:

Answer from API
{
    currentPage = some_int;
    maxPage = some_int;
    List<String> items; //items on page
}

And i have some RestApiService with method getItems(page) who return

Observable<Answer from API>

The problem how get all of pages from server?

Kota1921
  • 2,451
  • 1
  • 10
  • 13
  • 2
    Take a look at [this question](https://stackoverflow.com/questions/37024967/how-to-handle-pagination-with-retrofit-2-and-rxjava) or [this question](https://stackoverflow.com/questions/28047272/handle-paging-with-rxjava) – miensol Nov 17 '16 at 09:42

1 Answers1

0

This code base example should do the trick

@Test
public void repeat() {
    int maxPage = 10;
    int[] arrayPages = IntStream.range(0, maxPage).toArray();
    List<Integer> pages = IntStream.of(arrayPages).boxed().collect(Collectors.toList());
    Observable.from(pages)
            .map(this::getItemsApi)
            .toList()
            .subscribe(list -> System.out.println("All items:" + list));
}

public String getItemsApi(int page) {
    return "Items form page " + page;
}

Anyway, you should try to avoid copy/paste code without understand how works. You can see here some practical examples and some documentation about RxJava https://github.com/politrons/reactive

paul
  • 12,873
  • 23
  • 91
  • 153