aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/Account
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-08 12:05:45 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-08 12:05:45 +0000
commite542ac51388b9293297bb74b851dcb5ded621a3e (patch)
treec6c7073946063ca1a430f85ce0335d51d8d0812b /app/src/main/java/Account
parent5b5da3d3fd44d79bc301546b7be94de0a206e020 (diff)
downloadinfinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar.gz
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar.bz2
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar.lz
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar.xz
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.tar.zst
infinity-for-reddit-e542ac51388b9293297bb74b851dcb5ded621a3e.zip
Log in other reddit accounts are available. Add an account switcher in the navigation drawer in MainActivity.
Diffstat (limited to 'app/src/main/java/Account')
-rw-r--r--app/src/main/java/Account/AccountDao.java3
-rw-r--r--app/src/main/java/Account/AccountRepository.java8
-rw-r--r--app/src/main/java/Account/AccountViewModel.java8
3 files changed, 19 insertions, 0 deletions
diff --git a/app/src/main/java/Account/AccountDao.java b/app/src/main/java/Account/AccountDao.java
index 3052e2b5..22eae5d5 100644
--- a/app/src/main/java/Account/AccountDao.java
+++ b/app/src/main/java/Account/AccountDao.java
@@ -34,4 +34,7 @@ public interface AccountDao {
@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);
+
+ @Query("SELECT * FROM accounts WHERE username != :username")
+ LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData(String username);
}
diff --git a/app/src/main/java/Account/AccountRepository.java b/app/src/main/java/Account/AccountRepository.java
index c495579d..33927077 100644
--- a/app/src/main/java/Account/AccountRepository.java
+++ b/app/src/main/java/Account/AccountRepository.java
@@ -4,21 +4,29 @@ import android.os.AsyncTask;
import androidx.lifecycle.LiveData;
+import java.util.List;
+
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class AccountRepository {
private AccountDao mAccountDao;
private LiveData<Account> mAccountLiveData;
+ private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
mAccountDao = redditDataRoomDatabase.accountDao();
mAccountLiveData = mAccountDao.getAccountLiveData(username);
+ mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData(username);
}
LiveData<Account> getAccountLiveData() {
return mAccountLiveData;
}
+ public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
+ return mAccountsExceptCurrentAccountLiveData;
+ }
+
public void insert(Account Account) {
new InsertAsyncTask(mAccountDao).execute(Account);
}
diff --git a/app/src/main/java/Account/AccountViewModel.java b/app/src/main/java/Account/AccountViewModel.java
index ab6e9663..15fe6143 100644
--- a/app/src/main/java/Account/AccountViewModel.java
+++ b/app/src/main/java/Account/AccountViewModel.java
@@ -8,22 +8,30 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
+import java.util.List;
+
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class AccountViewModel extends AndroidViewModel {
private AccountRepository mAccountRepository;
private LiveData<Account> mAccountLiveData;
+ private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
super(application);
mAccountRepository = new AccountRepository(redditDataRoomDatabase, id);
mAccountLiveData = mAccountRepository.getAccountLiveData();
+ mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
}
public LiveData<Account> getAccountLiveData() {
return mAccountLiveData;
}
+ public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
+ return mAccountsExceptCurrentAccountLiveData;
+ }
+
public void insert(Account userData) {
mAccountRepository.insert(userData);
}