aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-12-20 13:07:46 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-12-20 13:07:46 +0000
commit21e7dad1b04f7b1753aa50efc2cf760568c9595f (patch)
treee6b2e8cd012b16d74eca454bc291bcd0b33cca7a
parent053773741e08f4fd0bd8ff006af552b3f6754d92 (diff)
downloadinfinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar.gz
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar.bz2
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar.lz
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar.xz
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.tar.zst
infinity-for-reddit-21e7dad1b04f7b1753aa50efc2cf760568c9595f.zip
Search subscribed users and multireddits.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditRepository.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditViewModel.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserDao.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserRepository.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserViewModel.java14
11 files changed, 56 insertions, 41 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
index 1365603c..1aa679ee 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
@@ -563,10 +563,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
subscribedSubredditsListingFragment.changeSearchQuery(searchQuery);
}
if (followedUsersListingFragment != null) {
-
+ followedUsersListingFragment.changeSearchQuery(searchQuery);
}
if (multiRedditListingFragment != null) {
-
+ multiRedditListingFragment.changeSearchQuery(searchQuery);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
index b3413209..0fe9a13d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
@@ -179,4 +179,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public void changeSearchQuery(String searchQuery) {
+ mSubscribedUserViewModel.setSearchQuery(searchQuery);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
index 302b0ea0..17a2fb96 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
@@ -200,6 +200,10 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
}
}
+ public void changeSearchQuery(String searchQuery) {
+ mMultiRedditViewModel.setSearchQuery(searchQuery);
+ }
+
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java
index 4d99e7a4..4e6b5a7b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java
@@ -16,14 +16,14 @@ public interface MultiRedditDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<MultiReddit> multiReddits);
- @Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<MultiReddit>> getAllMultiReddits(String username);
+ @Query("SELECT * FROM multi_reddits WHERE username = :username AND display_name LIKE '%' || :searchQuery || '%' ORDER BY name COLLATE NOCASE ASC")
+ LiveData<List<MultiReddit>> getAllMultiRedditsWithSearchQuery(String username, String searchQuery);
@Query("SELECT * FROM multi_reddits WHERE username = :username ORDER BY name COLLATE NOCASE ASC")
List<MultiReddit> getAllMultiRedditsList(String username);
- @Query("SELECT * FROM multi_reddits WHERE username = :username AND is_favorite ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<MultiReddit>> getAllFavoriteMultiReddits(String username);
+ @Query("SELECT * FROM multi_reddits WHERE username = :username AND is_favorite AND display_name LIKE '%' || :searchQuery || '%' ORDER BY name COLLATE NOCASE ASC")
+ LiveData<List<MultiReddit>> getAllFavoriteMultiRedditsWithSearchQuery(String username, String searchQuery);
@Query("SELECT * FROM multi_reddits WHERE path = :path AND username = :username COLLATE NOCASE LIMIT 1")
MultiReddit getMultiReddit(String path, String username);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditRepository.java
index 8b8156ae..45b000f9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditRepository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditRepository.java
@@ -7,20 +7,19 @@ import java.util.List;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class MultiRedditRepository {
- private LiveData<List<MultiReddit>> mAllMultiReddits;
- private LiveData<List<MultiReddit>> mAllFavoriteMultiReddits;
+ private MultiRedditDao mMultiRedditDao;
+ private String mAccountName;
MultiRedditRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
- MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao();
- mAllMultiReddits = multiRedditDao.getAllMultiReddits(accountName);
- mAllFavoriteMultiReddits = multiRedditDao.getAllFavoriteMultiReddits(accountName);
+ mMultiRedditDao = redditDataRoomDatabase.multiRedditDao();
+ mAccountName = accountName;
}
- LiveData<List<MultiReddit>> getAllMultiReddits() {
- return mAllMultiReddits;
+ LiveData<List<MultiReddit>> getAllMultiRedditsWithSearchQuery(String searchQuery) {
+ return mMultiRedditDao.getAllMultiRedditsWithSearchQuery(mAccountName, searchQuery);
}
- LiveData<List<MultiReddit>> getAllFavoriteMultiReddits() {
- return mAllFavoriteMultiReddits;
+ LiveData<List<MultiReddit>> getAllFavoriteMultiRedditsWithSearchQuery(String searchQuery) {
+ return mMultiRedditDao.getAllFavoriteMultiRedditsWithSearchQuery(mAccountName, searchQuery);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditViewModel.java
index 989b4853..efb532de 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditViewModel.java
@@ -5,6 +5,8 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
@@ -16,12 +18,16 @@ public class MultiRedditViewModel extends AndroidViewModel {
private MultiRedditRepository mMultiRedditRepository;
private LiveData<List<MultiReddit>> mAllMultiReddits;
private LiveData<List<MultiReddit>> mAllFavoriteMultiReddits;
+ private MutableLiveData<String> searchQueryLiveData;
public MultiRedditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application);
mMultiRedditRepository = new MultiRedditRepository(redditDataRoomDatabase, accountName);
- mAllMultiReddits = mMultiRedditRepository.getAllMultiReddits();
- mAllFavoriteMultiReddits = mMultiRedditRepository.getAllFavoriteMultiReddits();
+ searchQueryLiveData = new MutableLiveData<>();
+ searchQueryLiveData.postValue("");
+
+ mAllMultiReddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mMultiRedditRepository.getAllMultiRedditsWithSearchQuery(searchQuery));
+ mAllFavoriteMultiReddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mMultiRedditRepository.getAllFavoriteMultiRedditsWithSearchQuery(searchQuery));
}
public LiveData<List<MultiReddit>> getAllMultiReddits() {
@@ -32,6 +38,10 @@ public class MultiRedditViewModel extends AndroidViewModel {
return mAllFavoriteMultiReddits;
}
+ public void setSearchQuery(String searchQuery) {
+ searchQueryLiveData.postValue(searchQuery);
+ }
+
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Application mApplication;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java
index edcfa4cc..7867d225 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java
@@ -19,18 +19,12 @@ public interface SubscribedSubredditDao {
@Query("DELETE FROM subscribed_subreddits")
void deleteAllSubscribedSubreddits();
- @Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits(String accountName);
-
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName AND name LIKE '%' || :searchQuery || '%' ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubredditsWithSearchQuery(String accountName, String searchQuery);
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
List<SubscribedSubredditData> getAllSubscribedSubredditsList(String accountName);
- @Query("SELECT * from subscribed_subreddits WHERE username = :accountName COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubreddits(String accountName);
-
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubredditsWithSearchQuery(String accountName, String searchQuery);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java
index 0901da55..2bb9e247 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java
@@ -10,15 +10,11 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class SubscribedSubredditRepository {
private SubscribedSubredditDao mSubscribedSubredditDao;
- private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
- private LiveData<List<SubscribedSubredditData>> mAllFavoriteSubscribedSubreddits;
private String mAccountName;
SubscribedSubredditRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
mAccountName = accountName;
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
- mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits(accountName);
- mAllFavoriteSubscribedSubreddits = mSubscribedSubredditDao.getAllFavoriteSubscribedSubreddits(accountName);
}
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubredditsWithSearchQuery(String searchQuery) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserDao.java
index 18754a6b..ed7249db 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserDao.java
@@ -16,14 +16,14 @@ public interface SubscribedUserDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<SubscribedUserData> subscribedUserDataList);
- @Query("SELECT * FROM subscribed_users WHERE username = :accountName COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName);
+ @Query("SELECT * FROM subscribed_users WHERE username = :accountName AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
+ LiveData<List<SubscribedUserData>> getAllSubscribedUsersWithSearchQuery(String accountName, String searchQuery);
@Query("SELECT * FROM subscribed_users WHERE username = :accountName COLLATE NOCASE ORDER BY name COLLATE NOCASE ASC")
List<SubscribedUserData> getAllSubscribedUsersList(String accountName);
- @Query("SELECT * FROM subscribed_users WHERE username = :accountName COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
- LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers(String accountName);
+ @Query("SELECT * FROM subscribed_users WHERE username = :accountName AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
+ LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsersWithSearchQuery(String accountName, String searchQuery);
@Query("SELECT * FROM subscribed_users WHERE name = :name COLLATE NOCASE AND username = :accountName COLLATE NOCASE LIMIT 1")
SubscribedUserData getSubscribedUser(String name, String accountName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserRepository.java
index 1bd0aa71..befdcdb2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserRepository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserRepository.java
@@ -10,21 +10,19 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class SubscribedUserRepository {
private SubscribedUserDao mSubscribedUserDao;
- private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
- private LiveData<List<SubscribedUserData>> mAllFavoriteSubscribedUsers;
+ private String mAccountName;
SubscribedUserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
- mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(accountName);
- mAllFavoriteSubscribedUsers = mSubscribedUserDao.getAllFavoriteSubscribedUsers(accountName);
+ mAccountName = accountName;
}
- LiveData<List<SubscribedUserData>> getAllSubscribedSubreddits() {
- return mAllSubscribedUsers;
+ LiveData<List<SubscribedUserData>> getAllSubscribedUsersWithSearchQuery(String searchQuery) {
+ return mSubscribedUserDao.getAllSubscribedUsersWithSearchQuery(mAccountName, searchQuery);
}
- LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedSubreddits() {
- return mAllFavoriteSubscribedUsers;
+ LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsersWithSearchQuery(String searchQuery) {
+ return mSubscribedUserDao.getAllFavoriteSubscribedUsersWithSearchQuery(mAccountName, searchQuery);
}
public void insert(SubscribedUserData subscribedUserData) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserViewModel.java
index b19e5906..100703f8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribeduser/SubscribedUserViewModel.java
@@ -5,6 +5,8 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
@@ -16,12 +18,16 @@ public class SubscribedUserViewModel extends AndroidViewModel {
private SubscribedUserRepository mSubscribedUserRepository;
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
private LiveData<List<SubscribedUserData>> mAllFavoriteSubscribedUsers;
+ private MutableLiveData<String> searchQueryLiveData;
public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application);
mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName);
- mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits();
- mAllFavoriteSubscribedUsers = mSubscribedUserRepository.getAllFavoriteSubscribedSubreddits();
+ searchQueryLiveData = new MutableLiveData<>();
+ searchQueryLiveData.postValue("");
+
+ mAllSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllSubscribedUsersWithSearchQuery(searchQuery));
+ mAllFavoriteSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllFavoriteSubscribedUsersWithSearchQuery(searchQuery));
}
public LiveData<List<SubscribedUserData>> getAllSubscribedUsers() {
@@ -36,6 +42,10 @@ public class SubscribedUserViewModel extends AndroidViewModel {
mSubscribedUserRepository.insert(subscribedUserData);
}
+ public void setSearchQuery(String searchQuery) {
+ searchQueryLiveData.postValue(searchQuery);
+ }
+
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Application mApplication;
private RedditDataRoomDatabase mRedditDataRoomDatabase;