Search in sources :

Example 1 with TraktHttpClient

use of com.uwetrottmann.trakt.v2.TraktHttpClient in project aos-MediaLib by nova-video-player.

the class Trakt method refreshAccessToken.

private boolean refreshAccessToken() {
    Log.d(TAG, "refreshAccessToken()");
    try {
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mContext);
        String refreshToken = getRefreshTokenFromPreferences(pref);
        if (refreshToken == null || refreshToken.isEmpty()) {
            Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
            intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
            mContext.sendBroadcast(intent);
        } else {
            OAuthClientRequest request = TraktV2.getAccessTokenRefreshRequest(API_KEY, API_SECRET, "http://localhost", refreshToken);
            OAuthClient client = new OAuthClient(new TraktHttpClient());
            OAuthJSONAccessTokenResponse res = client.accessToken(request);
            if (res != null && res.getAccessToken() != null && !res.getAccessToken().isEmpty()) {
                setAccessToken(pref, res.getAccessToken());
                mTraktV2.setAccessToken(res.getAccessToken());
                setRefreshToken(pref, res.getRefreshToken());
                return true;
            }
        }
    } catch (OAuthSystemException e) {
        Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
        intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
        mContext.sendBroadcast(intent);
    } catch (OAuthProblemException e) {
        Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
        intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
        mContext.sendBroadcast(intent);
    }
    return false;
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) TraktHttpClient(com.uwetrottmann.trakt.v2.TraktHttpClient) SharedPreferences(android.content.SharedPreferences) OAuthClient(org.apache.oltu.oauth2.client.OAuthClient) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuthJSONAccessTokenResponse(org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse) Intent(android.content.Intent) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Aggregations

Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 TraktHttpClient (com.uwetrottmann.trakt.v2.TraktHttpClient)1 OAuthClient (org.apache.oltu.oauth2.client.OAuthClient)1 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1 OAuthJSONAccessTokenResponse (org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1