Skip to content

Commit 0566311

Browse files
committed
Reauthentication prompt
1 parent cfac460 commit 0566311

File tree

18 files changed

+401
-250
lines changed

18 files changed

+401
-250
lines changed

src/main/assets/changelog-alpha.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/Alpha 334 (2023-06-25)
2+
Due to Reddit API changes, any active accounts must be logged in again
3+
14
/Alpha 333 (2023-06-18)
25
Show Reddit user agreement prompt at startup
36
Simplified error handling

src/main/assets/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
105/1.21
22
Show Reddit user agreement prompt at startup
3+
Due to Reddit API changes, any active accounts must be logged in again
34
More specific error message when a subreddit is private
45
Show avatar in user profile dialog (thanks to mgurga)
56
Subreddit emotes now supported in comments (thanks to bharatknv)

src/main/java/org/quantumbadger/redreader/account/RedditAccount.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@
1818
package org.quantumbadger.redreader.account;
1919

2020
import androidx.annotation.NonNull;
21+
import androidx.annotation.Nullable;
2122
import org.quantumbadger.redreader.common.StringUtils;
2223
import org.quantumbadger.redreader.reddit.api.RedditOAuth;
2324

2425
public class RedditAccount {
2526

2627
@NonNull public final String username;
2728
public final RedditOAuth.RefreshToken refreshToken;
28-
public final boolean usesNewClientId;
2929

3030
private RedditOAuth.AccessToken accessToken;
3131

3232
public final long priority;
33+
@Nullable public final String clientId;
3334

3435
public RedditAccount(
3536
@NonNull final String username,
3637
final RedditOAuth.RefreshToken refreshToken,
37-
final boolean usesNewClientId,
38-
final long priority) {
38+
final long priority,
39+
@Nullable final String clientId) {
3940

4041
//noinspection ConstantConditions
4142
if(username == null) {
@@ -44,8 +45,8 @@ public RedditAccount(
4445

4546
this.username = username.trim();
4647
this.refreshToken = refreshToken;
47-
this.usesNewClientId = usesNewClientId;
4848
this.priority = priority;
49+
this.clientId = clientId;
4950
}
5051

5152
public boolean isAnonymous() {

src/main/java/org/quantumbadger/redreader/account/RedditAccountManager.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ public final class RedditAccountManager extends SQLiteOpenHelper {
4242
private static final RedditAccount ANON = new RedditAccount(
4343
"",
4444
null,
45-
true,
46-
10);
45+
10,
46+
null
47+
);
4748

4849
private final Context context;
4950

@@ -60,9 +61,10 @@ protected void notifyListener(final RedditAccountChangeListener listener) {
6061
private static final String FIELD_USERNAME = "username";
6162
private static final String FIELD_REFRESH_TOKEN = "refresh_token";
6263
private static final String FIELD_PRIORITY = "priority";
64+
private static final String FIELD_CLIENT_ID = "client_id";
6365
private static final String FIELD_USES_NEW_CLIENT_ID = "uses_new_client_id";
6466

65-
private static final int ACCOUNTS_DB_VERSION = 3;
67+
private static final int ACCOUNTS_DB_VERSION = 4;
6668

6769
@SuppressLint("StaticFieldLeak") private static RedditAccountManager singleton;
6870

@@ -94,12 +96,14 @@ public void onCreate(final SQLiteDatabase db) {
9496
"%s TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE," +
9597
"%s TEXT," +
9698
"%s INTEGER," +
97-
"%s BOOLEAN NOT NULL)",
99+
"%s BOOLEAN NOT NULL," +
100+
"%s TEXT)",
98101
TABLE,
99102
FIELD_USERNAME,
100103
FIELD_REFRESH_TOKEN,
101104
FIELD_PRIORITY,
102-
FIELD_USES_NEW_CLIENT_ID);
105+
FIELD_USES_NEW_CLIENT_ID,
106+
FIELD_CLIENT_ID);
103107

104108
db.execSQL(queryString);
105109

@@ -130,6 +134,14 @@ public void onUpgrade(
130134
TABLE,
131135
FIELD_USES_NEW_CLIENT_ID));
132136
}
137+
138+
if(oldVersion < 4) {
139+
db.execSQL(String.format(
140+
Locale.US,
141+
"ALTER TABLE %s ADD COLUMN %s TEXT DEFAULT NULL",
142+
TABLE,
143+
FIELD_CLIENT_ID));
144+
}
133145
}
134146

135147
public synchronized void addAccount(final RedditAccount account) {
@@ -158,7 +170,8 @@ private synchronized void addAccount(
158170
}
159171

160172
row.put(FIELD_PRIORITY, account.priority);
161-
row.put(FIELD_USES_NEW_CLIENT_ID, account.usesNewClientId);
173+
row.put(FIELD_USES_NEW_CLIENT_ID, 1);
174+
row.put(FIELD_CLIENT_ID, account.clientId);
162175

163176
db.insert(TABLE, null, row);
164177

@@ -239,7 +252,7 @@ private synchronized void reloadAccounts(final SQLiteDatabase db) {
239252
FIELD_USERNAME,
240253
FIELD_REFRESH_TOKEN,
241254
FIELD_PRIORITY,
242-
FIELD_USES_NEW_CLIENT_ID};
255+
FIELD_CLIENT_ID};
243256

244257
final Cursor cursor = db.query(
245258
TABLE,
@@ -267,13 +280,13 @@ private synchronized void reloadAccounts(final SQLiteDatabase db) {
267280
}
268281

269282
final long priority = cursor.getLong(2);
270-
final boolean usesNewClientId = cursor.getInt(3) != 0;
283+
@Nullable final String clientId = cursor.getString(3);
271284

272285
final RedditAccount account = new RedditAccount(
273286
username,
274287
refreshToken,
275-
usesNewClientId,
276-
priority);
288+
priority,
289+
clientId);
277290

278291
accountsCache.add(account);
279292

src/main/java/org/quantumbadger/redreader/activities/MainActivity.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.quantumbadger.redreader.reddit.PostSort;
6464
import org.quantumbadger.redreader.reddit.RedditSubredditHistory;
6565
import org.quantumbadger.redreader.reddit.UserCommentSort;
66+
import org.quantumbadger.redreader.reddit.api.RedditOAuth;
6667
import org.quantumbadger.redreader.reddit.api.RedditSubredditSubscriptionManager;
6768
import org.quantumbadger.redreader.reddit.api.SubredditSubscriptionState;
6869
import org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost;
@@ -176,9 +177,7 @@ && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
176177
.setMessage(R.string.firstrun_login_message)
177178
.setPositiveButton(
178179
R.string.firstrun_login_button_now,
179-
(dialog, which) -> new AccountListDialog().show(
180-
this.getSupportFragmentManager(),
181-
null))
180+
(dialog, which) -> AccountListDialog.show(this))
182181
.setNegativeButton(R.string.firstrun_login_button_later, null)
183182
.show();
184183

@@ -200,6 +199,10 @@ && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
200199

201200
FeatureFlagHandler.handleUpgrade(this);
202201

202+
if(RedditOAuth.anyNeedRelogin(this)) {
203+
General.showMustReloginDialog(this);
204+
}
205+
203206
recreateSubscriptionListener();
204207

205208
doRefresh(RefreshableFragment.MAIN_RELAYOUT, false, null);

src/main/java/org/quantumbadger/redreader/activities/OptionsMenuUtility.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,7 @@ private static void add(
598598
? R.string.options_account_manager
599599
: R.string.options_accounts))
600600
.setOnMenuItemClickListener(item -> {
601-
new AccountListDialog().show(
602-
activity.getSupportFragmentManager(),
603-
null);
601+
AccountListDialog.show(activity);
604602
return true;
605603
});
606604

src/main/java/org/quantumbadger/redreader/adapters/AccountListAdapter.java

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)