use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.
the class LoadPhotosetsTask method doInBackground.
@Override
protected Photosets doInBackground(OAuth... params) {
OAuth oauth = params[0];
if (oauth != null) {
OAuthToken token = oauth.getToken();
Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
/* "Currently all sets are returned, but this behaviour may change
* in future."
* (http://flickr.com/services/api/flickr.photosets.getList.html)
*/
try {
return f.getPhotosetsInterface().getList(mUser.getId());
} catch (Exception e) {
e.printStackTrace();
mException = e;
}
} else {
if (BuildConfig.DEBUG)
Log.d(TAG, "Making unauthenticated call");
try {
return FlickrHelper.getInstance().getPhotosetsInterface().getList(mUser.getId());
} catch (Exception e) {
e.printStackTrace();
mException = e;
}
}
return null;
}
use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.
the class AddItemToGroupTask method execute.
@Override
public void execute(final ITaskQueueServiceListener listener) {
if (BuildConfig.DEBUG) {
Log.d(TAG, String.format("Processing photo id %s for group %s", mItemId, mGroupId));
}
if (mOAuth == null) {
Log.e(TAG, "AddItemToGroupTask requires authentication");
MAIN_THREAD.post(new Runnable() {
@Override
public void run() {
listener.onFailure(mItemId, false);
}
});
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
OAuthToken token = mOAuth.getToken();
Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
try {
f.getPoolsInterface().add(mItemId, mGroupId);
/* success */
postToMainThread(listener, true, false);
} catch (FlickrException e) {
e.printStackTrace();
final String errCode = e.getErrorCode();
/* any of the following warrants no retry */
if (FLICKR_PHOTO_NOT_FOUND.equals(errCode) || FLICKR_GROUP_NOT_FOUND.equals(errCode) || FLICKR_ALREADY_IN_POOL.equals(errCode) || FLICKR_PHOTO_IN_MAX_POOLS.equals(errCode) || FLICKR_PHOTO_LIMIT_REACHED.equals(errCode) || FLICKR_PHOTO_PENDING_MOD.equals(errCode) || FLICKR_PHOTO_PENDING.equals(errCode) || FLICKR_POOL_FULL.equals(errCode)) {
postToMainThread(listener, false, false);
} else {
Log.e(TAG, "Unknown FlickrException code: " + errCode);
postToMainThread(listener, false, false);
}
} catch (JSONException e) {
e.printStackTrace();
/* failure, queue for retry */
postToMainThread(listener, false, true);
} catch (IOException e) {
e.printStackTrace();
/* failure, queue for retry */
postToMainThread(listener, false, true);
} catch (Exception e) {
e.printStackTrace();
/* shouldn't get here, don't retry */
postToMainThread(listener, false, false);
}
} catch (RuntimeException e) {
e.printStackTrace();
/* shouldn't get here, don't retry */
postToMainThread(listener, false, false);
}
}
}).start();
}
use of com.googlecode.flickrjandroid.Flickr 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.Flickr in project glimmr by brk3.
the class SetFavoriteTask method doInBackground.
@Override
protected Exception doInBackground(OAuth... params) {
OAuth oauth = params[0];
if (oauth != null) {
OAuthToken token = oauth.getToken();
Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
try {
if (mPhoto.isFavorite()) {
f.getFavoritesInterface().remove(mPhoto.getId());
} else {
f.getFavoritesInterface().add(mPhoto.getId());
}
} catch (Exception e) {
e.printStackTrace();
return e;
}
} else {
Log.e(TAG, "SetFavoriteTask requires authentication");
}
return null;
}
use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.
the class StackRemoteViewsFactory method getFavoritePhotos.
private List<Photo> getFavoritePhotos() throws Exception {
OAuthToken token = mOAuth.getToken();
Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
Date minFavDate = null;
Date maxFavDate = null;
return f.getFavoritesInterface().getList(mUser.getId(), minFavDate, maxFavDate, Constants.FETCH_PER_PAGE, PAGE, Constants.EXTRAS);
}
Aggregations