Skip to content

Commit 8b118b3

Browse files
Vivek Maskaraneslihanturan
authored andcommitted
Fix loading issue after upgrade from older version (commons-app#1454)
1 parent 3b129a6 commit 8b118b3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.support.v7.app.AppCompatDelegate;
2020
import android.text.Editable;
2121
import android.text.TextWatcher;
22-
import android.util.Log;
2322
import android.view.MenuInflater;
2423
import android.view.MenuItem;
2524
import android.view.View;
@@ -28,7 +27,6 @@
2827
import android.widget.Button;
2928
import android.widget.EditText;
3029
import android.widget.TextView;
31-
import android.widget.Toast;
3230

3331
import java.io.IOException;
3432

@@ -160,7 +158,10 @@ protected void onResume() {
160158
WelcomeActivity.startYourself(this);
161159
prefs.edit().putBoolean("firstrun", false).apply();
162160
}
163-
if (sessionManager.getCurrentAccount() != null) {
161+
162+
if (sessionManager.getCurrentAccount() != null
163+
&& sessionManager.isUserLoggedIn()
164+
&& sessionManager.getCachedAuthCookie() != null) {
164165
startMainActivity();
165166
}
166167
}

app/src/main/java/fr/free/nrw/commons/auth/SessionManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,26 @@ public Boolean revalidateAuthToken() {
6161
}
6262

6363
public String getAuthCookie() {
64-
boolean isLoggedIn = sharedPreferences.getBoolean("isUserLoggedIn", false);
65-
66-
if (!isLoggedIn) {
64+
if (!isUserLoggedIn()) {
6765
Timber.e("User is not logged in");
6866
return null;
6967
} else {
70-
String authCookie = sharedPreferences.getString("getAuthCookie", null);
68+
String authCookie = getCachedAuthCookie();
7169
if (authCookie == null) {
7270
Timber.e("Auth cookie is null even after login");
7371
}
7472
return authCookie;
7573
}
7674
}
7775

76+
public String getCachedAuthCookie() {
77+
return sharedPreferences.getString("getAuthCookie", null);
78+
}
79+
80+
public boolean isUserLoggedIn() {
81+
return sharedPreferences.getBoolean("isUserLoggedIn", false);
82+
}
83+
7884
public Completable clearAllAccounts() {
7985
AccountManager accountManager = AccountManager.get(context);
8086
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);

0 commit comments

Comments
 (0)