From ecf6a0b33869053e2da5af65eb82dce33d9fefef Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:41:21 -0500 Subject: Fix issues in AccessTokenAuthenticator. --- .../docilealligator/infinityforreddit/AccessTokenAuthenticator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 99858508..19e6d0da 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -49,6 +49,9 @@ class AccessTokenAuthenticator implements Authenticator { Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); if (account == null) { //Anonymous mode + if (mRedditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) { + mRedditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); + } String accessTokenFromSharedPreference = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, ""); if (accessToken.equals(accessTokenFromSharedPreference) || accessToken.equals("null")) { String newAccessToken = getApplicationOnlyAccessToken(); @@ -127,9 +130,10 @@ class AccessTokenAuthenticator implements Authenticator { if (response.isSuccessful() && response.body() != null) { JSONObject jsonObject = new JSONObject(response.body()); String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); + mRedditDataRoomDatabase.accountDao().updateAccessToken(Account.ANONYMOUS_ACCOUNT, newAccessToken); + mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.APPLICATION_ONLY_ACCESS_TOKEN, newAccessToken).apply(); if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(Account.ANONYMOUS_ACCOUNT)) { mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); - mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.APPLICATION_ONLY_ACCESS_TOKEN, newAccessToken).apply(); } return newAccessToken; -- cgit v1.2.3