Search in sources :

Example 1 with PaginatedCollection

use of com.karumi.rosie.repository.PaginatedCollection in project Rosie by Karumi.

the class MainActivityTest method givenThereAreSomeComicSeries.

private List<ComicSeries> givenThereAreSomeComicSeries(int numberOfComicSeries) throws Exception {
    List<ComicSeries> comics = new LinkedList<>();
    for (int i = 0; i < numberOfComicSeries; i++) {
        ComicSeries comic = getComicSeries(i);
        comics.add(comic);
    }
    PaginatedCollection<ComicSeries> paginatedCollection = new PaginatedCollection<>(comics);
    paginatedCollection.setPage(Page.withOffsetAndLimit(0, numberOfComicSeries));
    paginatedCollection.setHasMore(false);
    when(comicSeriesRepository.getPage(any(Page.class))).thenReturn(paginatedCollection);
    return comics;
}
Also used : ComicSeries(com.karumi.rosie.sample.comics.domain.model.ComicSeries) Page(com.karumi.rosie.repository.datasource.paginated.Page) LinkedList(java.util.LinkedList) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 2 with PaginatedCollection

use of com.karumi.rosie.repository.PaginatedCollection in project Rosie by Karumi.

the class GetCharacters method getAllCharactersInCache.

public PaginatedCollection<Character> getAllCharactersInCache() {
    Collection<Character> all;
    try {
        all = charactersRepository.getAll(ReadPolicy.CACHE_ONLY);
    } catch (Exception e) {
        all = new ArrayList<>();
    }
    if (all == null) {
        all = new ArrayList<>();
    }
    Page page = Page.withOffsetAndLimit(0, all.size());
    PaginatedCollection<Character> comics = new PaginatedCollection<>(all);
    comics.setPage(page);
    comics.setHasMore(true);
    return comics;
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character) ArrayList(java.util.ArrayList) Page(com.karumi.rosie.repository.datasource.paginated.Page) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 3 with PaginatedCollection

use of com.karumi.rosie.repository.PaginatedCollection in project Rosie by Karumi.

the class GetComicSeriesPage method getAllComicsInCache.

public PaginatedCollection<ComicSeries> getAllComicsInCache() {
    Collection<ComicSeries> all;
    try {
        all = repository.getAll(ReadPolicy.CACHE_ONLY);
    } catch (Exception e) {
        all = new ArrayList<>();
    }
    if (all == null) {
        all = new ArrayList<>();
    }
    Page page = Page.withOffsetAndLimit(0, all.size());
    PaginatedCollection<ComicSeries> comics = new PaginatedCollection<>(all);
    comics.setPage(page);
    comics.setHasMore(true);
    return comics;
}
Also used : ComicSeries(com.karumi.rosie.sample.comics.domain.model.ComicSeries) ArrayList(java.util.ArrayList) Page(com.karumi.rosie.repository.datasource.paginated.Page) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 4 with PaginatedCollection

use of com.karumi.rosie.repository.PaginatedCollection in project Rosie by Karumi.

the class ComicSeriesApiDataSource method getPage.

@Override
public PaginatedCollection<ComicSeries> getPage(Page page) throws MarvelApiException {
    int offset = page.getOffset();
    int limit = page.getLimit();
    MarvelResponse<SeriesCollectionDto> seriesApiResponse = seriesApiClient.getAll(offset, limit);
    SeriesCollectionDto seriesCollectionDto = seriesApiResponse.getResponse();
    Collection<ComicSeries> comicSeries = mapper.reverseMap(seriesCollectionDto.getSeries());
    PaginatedCollection<ComicSeries> comicSeriesPage = new PaginatedCollection<>(comicSeries);
    comicSeriesPage.setPage(page);
    comicSeriesPage.setHasMore(seriesCollectionDto.getOffset() + seriesCollectionDto.getCount() < seriesCollectionDto.getTotal());
    return comicSeriesPage;
}
Also used : ComicSeries(com.karumi.rosie.sample.comics.domain.model.ComicSeries) SeriesCollectionDto(com.karumi.marvelapiclient.model.SeriesCollectionDto) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 5 with PaginatedCollection

use of com.karumi.rosie.repository.PaginatedCollection in project Rosie by Karumi.

the class MainActivityTest method givenThereAreSomeCharacters.

private List<Character> givenThereAreSomeCharacters(int numberOfCharacters) throws Exception {
    List<Character> characters = new LinkedList<>();
    for (int i = 0; i < numberOfCharacters; i++) {
        Character character = getCharacter(i);
        characters.add(character);
        when(charactersRepository.getByKey(String.valueOf(i))).thenReturn(character);
    }
    PaginatedCollection<Character> paginatedCollection = new PaginatedCollection<>(characters);
    paginatedCollection.setPage(Page.withOffsetAndLimit(0, numberOfCharacters));
    paginatedCollection.setHasMore(false);
    when(charactersRepository.getPage(any(Page.class))).thenReturn(paginatedCollection);
    return characters;
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character) Page(com.karumi.rosie.repository.datasource.paginated.Page) LinkedList(java.util.LinkedList) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Aggregations

PaginatedCollection (com.karumi.rosie.repository.PaginatedCollection)6 Page (com.karumi.rosie.repository.datasource.paginated.Page)4 Character (com.karumi.rosie.sample.characters.domain.model.Character)3 ComicSeries (com.karumi.rosie.sample.comics.domain.model.ComicSeries)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CharactersDto (com.karumi.marvelapiclient.model.CharactersDto)1 SeriesCollectionDto (com.karumi.marvelapiclient.model.SeriesCollectionDto)1