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