Search in sources :

Example 6 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth 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 OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth 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 8 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth 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 9 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class OAuthUtils method isLoggedIn.

public static boolean isLoggedIn(Context context) {
    OAuth oauth = loadAccessToken(context);
    boolean isLoggedIn = (oauth != null && oauth.getUser() != null);
    if (BuildConfig.DEBUG)
        Log.d(TAG, "isLoggedIn: " + isLoggedIn);
    return isLoggedIn;
}
Also used : OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 10 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class AppService method doWakefulWork.

/**
     * Essentially like a crontab entry, what gets executed periodically.
     */
@Override
protected void doWakefulWork(Intent intent) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "doWakefulWork");
    /* Fetch the oauth token from storage */
    OAuth oauth = OAuthUtils.loadAccessToken(this);
    if (oauth == null) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "doWakefulWork: no stored oauth token found, " + "doing nothing");
        }
        return;
    }
    /* Important: add each handler to be run here */
    List<GlimmrNotificationHandler> handlers = new ArrayList<GlimmrNotificationHandler>();
    handlers.add(new ContactsPhotosNotificationHandler(this));
    handlers.add(new ActivityNotificationHandler(this));
    /* Start each handler */
    for (GlimmrNotificationHandler handler : handlers) {
        if (handler.enabledInPreferences()) {
            handler.startTask(oauth);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Aggregations

OAuth (com.googlecode.flickrjandroid.oauth.OAuth)15 OAuthToken (com.googlecode.flickrjandroid.oauth.OAuthToken)13 Flickr (com.googlecode.flickrjandroid.Flickr)12 SharedPreferences (android.content.SharedPreferences)1 RequestContext (com.googlecode.flickrjandroid.RequestContext)1 User (com.googlecode.flickrjandroid.people.User)1 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)1 ArrayList (java.util.ArrayList)1