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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations