Search in sources :

Example 1 with FlickrException

use of com.googlecode.flickrjandroid.FlickrException 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 2 with FlickrException

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

the class ExifInfoFragment method onExifInfoReady.

public void onExifInfoReady(List<Exif> exifInfo, Exception exc) {
    mActivity.setProgressBarIndeterminateVisibility(Boolean.FALSE);
    if (FlickrHelper.getInstance().handleFlickrUnavailable(mActivity, exc)) {
        return;
    }
    if (FlickrHelper.getInstance().handleFlickrUnavailable(mActivity, exc)) {
        return;
    }
    /* Something went wrong, show message and return */
    if (exc != null) {
        mTextViewErrorMessage.setVisibility(View.VISIBLE);
        if (exc instanceof FlickrException) {
            String errCode = ((FlickrException) exc).getErrorCode();
            if (BuildConfig.DEBUG)
                Log.d(getLogTag(), "errCode: " + errCode);
            if (errCode != null && ERR_PERMISSION_DENIED.equals(errCode)) {
                mTextViewErrorMessage.setText(mActivity.getString(R.string.no_exif_permission));
            } else {
                mTextViewErrorMessage.setText(mActivity.getString(R.string.no_connection));
            }
        } else {
            mTextViewErrorMessage.setText(mActivity.getString(R.string.no_connection));
        }
        return;
    }
    /* Populate table with exif info */
    for (Exif e : exifInfo) {
        /* Convert camel case key to space delimited:
             * http://stackoverflow.com/a/2560017/663370 */
        String rawTag = e.getTag();
        String tagConverted = rawTag.replaceAll(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), " ");
        addKeyValueRow(tagConverted, e.getRaw());
    }
}
Also used : Exif(com.googlecode.flickrjandroid.photos.Exif) FlickrException(com.googlecode.flickrjandroid.FlickrException)

Example 3 with FlickrException

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

the class AddItemToPhotosetTask method execute.

@Override
public void execute(final ITaskQueueServiceListener listener) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, String.format("Processing photo id %s for photoset %s", mItemId, mPhotosetId));
    }
    if (mOAuth == null) {
        Log.e(TAG, "AddItemToPhotosetTask 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.getPhotosetsInterface().addPhoto(mPhotosetId, mItemId);
                    /* success */
                    postToMainThread(listener, true, false);
                } catch (FlickrException e) {
                    e.printStackTrace();
                    final String errCode = e.getErrorCode();
                    /* any of the following warrants no retry */
                    if (FLICKR_PHOTOSET_NOT_FOUND.equals(errCode) || FLICKR_PHOTO_NOT_FOUND.equals(errCode) || FLICKR_PHOTO_ALREADY_IN_SET.equals(errCode) || FLICKR_PHOTOSET_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 4 with FlickrException

use of com.googlecode.flickrjandroid.FlickrException 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)

Aggregations

FlickrException (com.googlecode.flickrjandroid.FlickrException)4 Flickr (com.googlecode.flickrjandroid.Flickr)3 OAuthToken (com.googlecode.flickrjandroid.oauth.OAuthToken)3 IOException (java.io.IOException)3 JSONException (org.json.JSONException)2 Exif (com.googlecode.flickrjandroid.photos.Exif)1 FileInputStream (java.io.FileInputStream)1