-
Notifications
You must be signed in to change notification settings - Fork 35
Adds multiple accounts support #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -258,6 +258,16 @@ private Completable removeAllMessages(InboxFolder folder) { | |||||
}); | ||||||
} | ||||||
|
||||||
@CheckResult | ||||||
public Completable clearMessages() { | ||||||
return Completable.fromAction(() -> { | ||||||
try (BriteDatabase.Transaction transaction = briteDatabase.newTransaction()) { | ||||||
briteDatabase.delete(CachedMessage.TABLE_NAME, ""); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on documentation passing
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah OK. Anyways I wasn't 100% sure about deleting the cache table but switching to other account would end in merging PM from all your accounts. It's seems to be more a hack than a fix to me. |
||||||
transaction.markSuccessful(); | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
||||||
// ======== READ STATUS ======== // | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import me.saket.dank.data.OnLoginRequireListener; | ||
import me.saket.dank.reply.ReplyRepository; | ||
import me.saket.dank.ui.UrlRouter; | ||
import me.saket.dank.ui.accountmanager.AccountManagerActivity; | ||
import me.saket.dank.ui.authentication.LoginActivity; | ||
import me.saket.dank.ui.submission.DraftStore; | ||
import me.saket.dank.ui.submission.LinkOptionsPopup; | ||
|
@@ -184,8 +185,8 @@ DraftStore provideReplyDraftStore(ReplyRepository replyRepository) { | |
@Provides | ||
OnLoginRequireListener provideOnLoginRequireListener(Application appContext) { | ||
return () -> { | ||
Intent loginIntent = LoginActivity.intent(appContext); | ||
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
Intent loginIntent = new Intent(appContext, AccountManagerActivity.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
loginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
appContext.startActivity(loginIntent); | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package me.saket.dank.ui.accountmanager; | ||
|
||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import io.reactivex.functions.Function; | ||
|
||
import me.saket.dank.ui.accountmanager.AccountManagerScreenUiModel; | ||
import me.saket.dank.ui.accountmanager.AutoValue_AccountManager; | ||
import me.saket.dank.utils.Cursors; | ||
|
||
@AutoValue | ||
public abstract class AccountManager implements AccountManagerScreenUiModel { | ||
|
||
static final String TABLE_NAME = "Account"; | ||
static final String COLUMN_USERNAME = "username"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This column is not clear to me.
You see the inconsistencies? I guess what you want here are columns named rank and username instead. You should use the same naming everywhere. |
||
static final String COLUMN_LABEL = "label"; | ||
|
||
public static final String QUERY_CREATE_TABLE = | ||
"CREATE TABLE " + TABLE_NAME + " (" | ||
+ COLUMN_LABEL + " TEXT NOT NULL PRIMARY KEY, " | ||
+ COLUMN_USERNAME + " TEXT NOT NULL)"; | ||
|
||
public static final String QUERY_GET_ALL_ORDERED_BY_USER = | ||
"SELECT * FROM " + TABLE_NAME; | ||
|
||
public static final String WHERE_USERNAME = | ||
COLUMN_LABEL + " = ?"; | ||
|
||
public static AccountManager create(int rank, String label) { | ||
return new AutoValue_AccountManager(rank, label); | ||
} | ||
|
||
public static AccountManager create(String username) { | ||
return new AutoValue_AccountManager(1, username); | ||
} | ||
|
||
public static final Function<Cursor, AccountManager> MAPPER = cursor -> { | ||
int user = Cursors.intt(cursor, COLUMN_USERNAME); | ||
String label = Cursors.string(cursor, COLUMN_LABEL); | ||
return create(user, label); | ||
}; | ||
|
||
public abstract int rank(); | ||
|
||
public abstract String label(); | ||
|
||
public AccountManager withRank(int newRank) { | ||
return create(newRank, label()); | ||
} | ||
|
||
public String id() { | ||
return label(); | ||
} | ||
|
||
@Override | ||
public long adapterId() { | ||
return label().hashCode(); | ||
} | ||
|
||
public ContentValues toValues() { | ||
ContentValues values = new ContentValues(2); | ||
values.put(COLUMN_USERNAME, rank()); | ||
values.put(COLUMN_LABEL, label()); | ||
return values; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upgrade method will need some fixing. I can see that you followed the convention in the first if statement but it won't work correctly.
Let's say that the user is on the version of app where the database has version 1. Now when they update to latest version this method will be called with parameters
oldVersion=1
andnewVersion=3
. In that case by following the logic inside of if statements we can see that none of them will be executed and the upgrade won't work correctly.In the first statement you want to keep on check on
oldVersion
only. That is, we should simply delete cached messages table when upgrading from that version.In the second statement you want to check only on
newVersion
since you need to create the table also when upgrading from older versions. Additionally I'm not sure but perhaps we should go a bit further and check whether new version is equal to or greater than 3 to also take into account future versions.Other than that it would be a good idea to add tests for the whole upgrade since that is an important operation. Of course tests for other operations on the database would be nice too but I feel like this one is the minimum.