Only check token for logged in users

This commit is contained in:
Balazs Toldi 2024-01-06 21:42:57 +01:00
parent e7f84b8aed
commit 3195f05e56
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58

View File

@ -1144,31 +1144,32 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
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();
if (mAccessToken != null) {
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() {
@Override
public void onFetchSiteInfoFailed() {
}
});
}
});
}
}
}