Search in sources :

Example 1 with SearchParameters

use of com.googlecode.flickrjandroid.photos.SearchParameters 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();
}
Also used : PhotosInterface(com.googlecode.flickrjandroid.photos.PhotosInterface) 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)

Example 2 with SearchParameters

use of com.googlecode.flickrjandroid.photos.SearchParameters in project glimmr by brk3.

the class SearchPhotosTask method doInBackground.

@Override
protected List<Photo> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    SearchParameters sp = new SearchParameters();
    sp.setExtras(Constants.EXTRAS);
    sp.setText(mSearchTerm);
    if (mUserId != null) {
        sp.setUserId(mUserId);
    }
    switch(mSortType) {
        case AbstractPhotoSearchGridFragment.SORT_TYPE_RECENT:
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Search type:RECENT");
            sp.setSort(SearchParameters.DATE_POSTED_DESC);
            break;
        case AbstractPhotoSearchGridFragment.SORT_TYPE_INTERESTING:
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Search type:INTERESTINGNESS");
            sp.setSort(SearchParameters.INTERESTINGNESS_DESC);
            break;
        case AbstractPhotoSearchGridFragment.SORT_TYPE_RELAVANCE:
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Search type:RELAVANCE");
            sp.setSort(SearchParameters.RELEVANCE);
            break;
        default:
            Log.e(TAG, "Unknown sort type, defaulting to RELAVANCE");
            sp.setSort(SearchParameters.RELEVANCE);
    }
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Fetching page " + mPage);
        try {
            return f.getPhotosInterface().search(sp, Constants.FETCH_PER_PAGE, mPage);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Making unauthenticated call");
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Fetching page " + mPage);
        try {
            return FlickrHelper.getInstance().getPhotosInterface().search(sp, Constants.FETCH_PER_PAGE, mPage);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    }
    return null;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) SearchParameters(com.googlecode.flickrjandroid.photos.SearchParameters) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 3 with SearchParameters

use of com.googlecode.flickrjandroid.photos.SearchParameters 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

Flickr (com.googlecode.flickrjandroid.Flickr)3 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)3 Background (com.alexvasilkov.events.Events.Background)2 Subscribe (com.alexvasilkov.events.Events.Subscribe)2 Photo (com.googlecode.flickrjandroid.photos.Photo)2 PhotoList (com.googlecode.flickrjandroid.photos.PhotoList)2 ArrayList (java.util.ArrayList)2 OAuth (com.googlecode.flickrjandroid.oauth.OAuth)1 OAuthToken (com.googlecode.flickrjandroid.oauth.OAuthToken)1 PhotosInterface (com.googlecode.flickrjandroid.photos.PhotosInterface)1