Search in sources :

Example 16 with Flickr

use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.

the class LoadGroupInfoTask method doInBackground.

@Override
protected Group doInBackground(OAuth... params) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Starting LoadGroupInfoTask");
    OAuth oauth = params[0];
    if (oauth != null) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Authenticated call");
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        try {
            return f.getGroupsInterface().getInfo(mGroupId);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Unauthenticated call");
        try {
            return FlickrHelper.getInstance().getGroupsInterface().getInfo(mGroupId);
        } 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 17 with Flickr

use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.

the class LoadGroupsTask method doInBackground.

@Override
protected Collection<Group> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        try {
            return f.getPoolsInterface().getGroups();
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        Log.e(TAG, "LoadGroupsTask requires authentication");
    }
    return null;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 18 with Flickr

use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.

the class LoadPhotostreamTask method doInBackground.

@Override
protected List<Photo> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    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.getPeopleInterface().getPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        try {
            return FlickrHelper.getInstance().getPeopleInterface().getPublicPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage);
        } 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 19 with Flickr

use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.

the class UploadPhotoTask method execute.

@Override
public void execute(final ITaskQueueServiceListener listener) {
    if (mOAuth == null) {
        Log.e(TAG, "UploadPhotoTask requires authentication");
        MAIN_THREAD.post(new Runnable() {

            @Override
            public void run() {
                listener.onFailure(mPhoto.getUri(), 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.getUploader().upload(mMetadata.getTitle(), new FileInputStream(mPhoto.getUri()), mMetadata);
                    /* success */
                    postToMainThread(listener, true, false);
                } catch (FlickrException e) {
                    e.printStackTrace();
                    final String errCode = e.getErrorCode();
                    /* retry */
                    if (FLICKR_GENERAL_UPLOAD_FAILURE.equals(errCode) || FLICKR_UPLOAD_LIMIT_REACHED.equals(errCode)) {
                        postToMainThread(listener, false, true);
                    } else {
                        postToMainThread(listener, false, false);
                    }
                } 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) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FlickrException(com.googlecode.flickrjandroid.FlickrException) IOException(java.io.IOException)

Example 20 with Flickr

use of com.googlecode.flickrjandroid.Flickr in project glimmr by brk3.

the class FlickrHelper method getFlickrAuthed.

public Flickr getFlickrAuthed(String token, String secret) {
    Flickr f = getFlickr();
    RequestContext requestContext = RequestContext.getRequestContext();
    OAuth auth = new OAuth();
    auth.setToken(new OAuthToken(token, secret));
    requestContext.setOAuth(auth);
    return f;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) RequestContext(com.googlecode.flickrjandroid.RequestContext) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

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