From 556047aa42b8fba25be56c38e5e919690444858b Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 19 Aug 2019 17:57:04 +0800 Subject: Finish MainActivity if clicking a notification for another user. --- app/src/main/java/Account/AccountDao.java | 3 +++ app/src/main/java/Account/AccountRepository.java | 6 ------ app/src/main/java/Account/AccountViewModel.java | 6 ------ 3 files changed, 3 insertions(+), 12 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 c05e5552..67caf71d 100644 --- a/app/src/main/java/Account/AccountDao.java +++ b/app/src/main/java/Account/AccountDao.java @@ -37,6 +37,9 @@ public interface AccountDao { @Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1") Account getCurrentAccount(); + @Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1") + LiveData getCurrentAccountLiveData(); + @Query("UPDATE accounts SET profile_image_url = :profileImageUrl, banner_image_url = :bannerImageUrl, " + "karma = :karma WHERE username = :username") void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma); diff --git a/app/src/main/java/Account/AccountRepository.java b/app/src/main/java/Account/AccountRepository.java index 7aa77b51..573f00f8 100644 --- a/app/src/main/java/Account/AccountRepository.java +++ b/app/src/main/java/Account/AccountRepository.java @@ -10,19 +10,13 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class AccountRepository { private AccountDao mAccountDao; - private LiveData mAccountLiveData; private LiveData> mAccountsExceptCurrentAccountLiveData; AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) { mAccountDao = redditDataRoomDatabase.accountDao(); - mAccountLiveData = mAccountDao.getAccountLiveData(username); mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData(); } - LiveData getAccountLiveData() { - return mAccountLiveData; - } - public LiveData> getAccountsExceptCurrentAccountLiveData() { return mAccountsExceptCurrentAccountLiveData; } diff --git a/app/src/main/java/Account/AccountViewModel.java b/app/src/main/java/Account/AccountViewModel.java index 15fe6143..53fb0013 100644 --- a/app/src/main/java/Account/AccountViewModel.java +++ b/app/src/main/java/Account/AccountViewModel.java @@ -14,20 +14,14 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class AccountViewModel extends AndroidViewModel { private AccountRepository mAccountRepository; - private LiveData mAccountLiveData; private LiveData> mAccountsExceptCurrentAccountLiveData; public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) { super(application); mAccountRepository = new AccountRepository(redditDataRoomDatabase, id); - mAccountLiveData = mAccountRepository.getAccountLiveData(); mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData(); } - public LiveData getAccountLiveData() { - return mAccountLiveData; - } - public LiveData> getAccountsExceptCurrentAccountLiveData() { return mAccountsExceptCurrentAccountLiveData; } -- cgit v1.2.3