From 85597a82d065374955153c0481663fac2b0c3264 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 8 Aug 2019 20:19:38 +0800 Subject: Switch between all logged-in reddit accounts is available. --- app/src/main/java/Account/AccountDao.java | 7 +++++-- app/src/main/java/Account/AccountRepository.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/Account') diff --git a/app/src/main/java/Account/AccountDao.java b/app/src/main/java/Account/AccountDao.java index 22eae5d5..b3672bb5 100644 --- a/app/src/main/java/Account/AccountDao.java +++ b/app/src/main/java/Account/AccountDao.java @@ -35,6 +35,9 @@ public interface AccountDao { "karma = :karma WHERE username = :username") void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma); - @Query("SELECT * FROM accounts WHERE username != :username") - LiveData> getAccountsExceptCurrentAccountLiveData(String username); + @Query("SELECT * FROM accounts WHERE is_current_user = 0 ORDER BY username COLLATE NOCASE ASC") + LiveData> getAccountsExceptCurrentAccountLiveData(); + + @Query("UPDATE accounts SET is_current_user = 1 WHERE username = :username") + void markAccountCurrent(String username); } diff --git a/app/src/main/java/Account/AccountRepository.java b/app/src/main/java/Account/AccountRepository.java index 33927077..7aa77b51 100644 --- a/app/src/main/java/Account/AccountRepository.java +++ b/app/src/main/java/Account/AccountRepository.java @@ -16,7 +16,7 @@ public class AccountRepository { AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) { mAccountDao = redditDataRoomDatabase.accountDao(); mAccountLiveData = mAccountDao.getAccountLiveData(username); - mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData(username); + mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData(); } LiveData getAccountLiveData() { -- cgit v1.2.3