Search in sources :

Example 6 with Flickr

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;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 7 with Flickr

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();
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) FlickrException(com.googlecode.flickrjandroid.FlickrException) JSONException(org.json.JSONException) IOException(java.io.IOException) FlickrException(com.googlecode.flickrjandroid.FlickrException) IOException(java.io.IOException) JSONException(org.json.JSONException)

Example 8 with Flickr

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;
}
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 9 with Flickr

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;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 10 with Flickr

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);
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) Date(java.util.Date)

Aggregations

Flickr (com.googlecode.flickrjandroid.Flickr)21 OAuthToken (com.googlecode.flickrjandroid.oauth.OAuthToken)19 OAuth (com.googlecode.flickrjandroid.oauth.OAuth)12 FlickrException (com.googlecode.flickrjandroid.FlickrException)3 IOException (java.io.IOException)3 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)2 JSONException (org.json.JSONException)2 Background (com.alexvasilkov.events.Events.Background)1 Subscribe (com.alexvasilkov.events.Events.Subscribe)1 RequestContext (com.googlecode.flickrjandroid.RequestContext)1 OAuthInterface (com.googlecode.flickrjandroid.oauth.OAuthInterface)1 Photo (com.googlecode.flickrjandroid.photos.Photo)1 PhotoList (com.googlecode.flickrjandroid.photos.PhotoList)1 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1