Search in sources :

Example 1 with DatabaseHelper

use of com.mxt.anitrend.data.DatabaseHelper in project anitrend-app by AniTrend.

the class WebTokenRequest method getToken.

/**
 * Request a new access token using access code for authenticated content,
 * and replace the current token with the new one from the server after authentication
 */
public static synchronized boolean getToken(Context context, String code) throws ExecutionException, InterruptedException {
    WebToken authenticatedToken = new AuthenticationCodeAsync().execute(code).get();
    if (authenticatedToken != null) {
        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        databaseHelper.saveWebToken(authenticatedToken);
        databaseHelper.saveAuthCode(new AuthBase(code, authenticatedToken.getRefresh_token()));
        createNewTokenReference(authenticatedToken);
        return true;
    }
    return false;
}
Also used : DatabaseHelper(com.mxt.anitrend.data.DatabaseHelper) AuthBase(com.mxt.anitrend.model.entity.base.AuthBase) WebToken(com.mxt.anitrend.model.entity.anilist.WebToken)

Example 2 with DatabaseHelper

use of com.mxt.anitrend.data.DatabaseHelper in project anitrend-app by AniTrend.

the class NotificationSyncTask method checkNotificationCount.

/**
 * Check the notification count for the current user
 * @return unread notification count
 */
private void checkNotificationCount(UserModel userModel) {
    try {
        Response<User> response = userModel.getCurrentUser(GraphUtil.getDefaultQuery(false)).execute();
        if (response.isSuccessful() && (user = response.body()) != null) {
            DatabaseHelper databaseHelper = presenter.getDatabase();
            databaseHelper.saveCurrentUser(user);
        } else
            Log.e(TAG, ErrorUtil.getError(response));
    } catch (IOException e) {
        Log.e(TAG, e.getLocalizedMessage());
        e.printStackTrace();
    }
}
Also used : User(com.mxt.anitrend.model.entity.anilist.User) DatabaseHelper(com.mxt.anitrend.data.DatabaseHelper) IOException(java.io.IOException)

Aggregations

DatabaseHelper (com.mxt.anitrend.data.DatabaseHelper)2 User (com.mxt.anitrend.model.entity.anilist.User)1 WebToken (com.mxt.anitrend.model.entity.anilist.WebToken)1 AuthBase (com.mxt.anitrend.model.entity.base.AuthBase)1 IOException (java.io.IOException)1