From e7f84b8aed91bb59f551618fad9c3c4510c15c05 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Sat, 6 Jan 2024 11:40:00 +0100 Subject: [PATCH] Better realization of a Lemmy upgrade --- .../activities/LoginActivity.java | 3 ++ .../activities/MainActivity.java | 30 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java index a575d468..550206ce 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java @@ -242,6 +242,9 @@ public class LoginActivity extends BaseActivity { if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) { mRetrofit.setAccessToken(accessToken); mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply(); + } else { + mRetrofit.setAccessToken(null); + mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false).apply(); } } } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java index 33cdf607..166603d7 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java @@ -14,6 +14,7 @@ import android.os.Bundle; import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; @@ -119,6 +120,8 @@ import eu.toldi.infinityforlemmy.post.MarkPostAsRead; import eu.toldi.infinityforlemmy.post.Post; import eu.toldi.infinityforlemmy.post.PostPagingSource; import eu.toldi.infinityforlemmy.readpost.InsertReadPost; +import eu.toldi.infinityforlemmy.site.FetchSiteInfo; +import eu.toldi.infinityforlemmy.site.SiteInfo; import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData; import eu.toldi.infinityforlemmy.subreddit.SubredditData; import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData; @@ -1138,7 +1141,32 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public void onFetchUserDataFailed() { - mFetchUserInfoSuccess = false; + mFetchUserInfoSuccess = false; + } + }); + + FetchSiteInfo.fetchSiteInfo(mRetrofit.getRetrofit(), mAccessToken, new FetchSiteInfo.FetchSiteInfoListener() { + @Override + public void onFetchSiteInfoSuccess(SiteInfo siteInfo) { + String[] version = siteInfo.getVersion().split("\\."); + if (version.length > 0) { + Log.d("MainActvity", "Lemmy Version: " + version[0] + "." + version[1]); + int majorVersion = Integer.parseInt(version[0]); + int minorVersion = Integer.parseInt(version[1]); + if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) { + mRetrofit.setAccessToken(mAccessToken); + mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply(); + checkUserToken(); + } else { + mRetrofit.setAccessToken(null); + mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false).apply(); + } + } + } + + @Override + public void onFetchSiteInfoFailed() { + } }); }