Search in sources :

Example 1 with Background

use of com.alexvasilkov.events.Events.Background 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();
}
Also used : SearchParameters(com.googlecode.flickrjandroid.photos.SearchParameters) Flickr(com.googlecode.flickrjandroid.Flickr) PhotoList(com.googlecode.flickrjandroid.photos.PhotoList) ArrayList(java.util.ArrayList) Photo(com.googlecode.flickrjandroid.photos.Photo) Background(com.alexvasilkov.events.Events.Background) Subscribe(com.alexvasilkov.events.Events.Subscribe)

Aggregations

Background (com.alexvasilkov.events.Events.Background)1 Subscribe (com.alexvasilkov.events.Events.Subscribe)1 Flickr (com.googlecode.flickrjandroid.Flickr)1 Photo (com.googlecode.flickrjandroid.photos.Photo)1 PhotoList (com.googlecode.flickrjandroid.photos.PhotoList)1 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)1 ArrayList (java.util.ArrayList)1