diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-01-08 01:41:21 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-01-08 01:41:21 +0000 |
commit | ecf6a0b33869053e2da5af65eb82dce33d9fefef (patch) | |
tree | 6a27fafe86d5d02fa8c8ce607743e3f03f059e66 /app/src | |
parent | 977495cd448d9f21589a39c67f43848df638bba9 (diff) | |
download | infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar.gz infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar.bz2 infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar.lz infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar.xz infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.tar.zst infinity-for-reddit-ecf6a0b33869053e2da5af65eb82dce33d9fefef.zip |
Fix issues in AccessTokenAuthenticator.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java | 6 |
1 files changed, 5 insertions, 1 deletions
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; |