use of com.alexvasilkov.events.Events.Subscribe in project GestureViews by alexvasilkov.
the class FlickrApi method loadImages.
@Background(singleThread = true)
@Subscribe(LOAD_IMAGES_EVENT)
private static synchronized EventResult loadImages(int count) throws Exception {
SearchParameters params = new SearchParameters();
params.setText(SEARCH_QUERY);
params.setSafeSearch(Flickr.SAFETYLEVEL_SAFE);
params.setSort(SearchParameters.RELEVANCE);
params.setLicense(LICENCE_ID);
params.setExtras(photoParams);
boolean hasNext = hasNext();
final PhotosInterface flickrPhotos = new Flickr(API_KEY).getPhotosInterface();
while (photos.size() < count && hasNext) {
final PhotoList loaded = flickrPhotos.search(params, PER_PAGE, pages.size() + 1);
pages.add(loaded);
photos.addAll(loaded);
hasNext = hasNext();
}
int resultSize;
if (photos.size() >= count) {
resultSize = count;
} else {
resultSize = photos.size();
}
List<Photo> result = new ArrayList<>(photos.subList(0, resultSize));
if (!hasNext) {
hasNext = photos.size() > count;
}
return EventResult.create().result(result, hasNext).build();
}
use of com.alexvasilkov.events.Events.Subscribe in project GestureViews by alexvasilkov.
the class FlickrApi method loadImages.
@Background(singleThread = true)
@Subscribe(LOAD_IMAGES_EVENT)
private static synchronized EventResult loadImages(int count) throws Exception {
SearchParameters params = new SearchParameters();
params.setText(SEARCH_QUERY);
params.setSafeSearch(Flickr.SAFETYLEVEL_SAFE);
params.setSort(SearchParameters.RELEVANCE);
params.setLicense(LICENCE_ID);
params.setExtras(photoParams);
boolean hasNext = hasNext();
while (photos.size() < count && hasNext) {
PhotoList loaded = new Flickr(API_KEY).getPhotosInterface().search(params, PER_PAGE, pages.size() + 1);
pages.add(loaded);
photos.addAll(loaded);
hasNext = hasNext();
}
int resultSize;
if (photos.size() >= count) {
resultSize = count;
} else {
resultSize = photos.size();
}
List<Photo> result = new ArrayList<>(photos.subList(0, resultSize));
if (!hasNext) {
hasNext = photos.size() > count;
}
return EventResult.create().result(result, hasNext).build();
}
Aggregations