aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java88
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java4
-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.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditViewModel.java14
-rw-r--r--app/src/main/res/layout/activity_subscribed_thing_listing.xml16
-rw-r--r--app/src/main/res/menu/subscribed_thing_listing_activity.xml10
7 files changed, 140 insertions, 8 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 dde51105..1365603c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
@@ -1,15 +1,21 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -79,6 +85,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_subscribed_thing_listing_activity)
Toolbar toolbar;
+ @BindView(R.id.search_edit_text_subscribed_thing_listing_activity)
+ EditText searchEditText;
@BindView(R.id.tab_layout_subscribed_thing_listing_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_subscribed_thing_listing_activity)
@@ -107,6 +115,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
private boolean mInsertMultiredditSuccess = false;
private boolean showMultiReddits = false;
private SectionsPagerAdapter sectionsPagerAdapter;
+ private Menu mMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -165,6 +174,23 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
} else {
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
}
+
+ searchEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+ sectionsPagerAdapter.changeSearchQuery(editable.toString());
+ }
+ });
initializeViewPagerAndLoadSubscriptions();
}
@@ -184,6 +210,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
applyTabLayoutTheme(tabLayout);
applyFABTheme(fab);
+ searchEditText.setTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
+ searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarSecondaryTextColor());
}
private void initializeViewPagerAndLoadSubscriptions() {
@@ -223,8 +251,37 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.subscribed_thing_listing_activity, menu);
+ mMenu = menu;
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
+ if (item.getItemId() == R.id.action_search_subscribed_thing_listing_activity) {
+ item.setVisible(false);
+ searchEditText.setVisibility(View.VISIBLE);
+ searchEditText.requestFocus();
+ if (searchEditText.requestFocus()) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(searchEditText, InputMethodManager.SHOW_IMPLICIT);
+ }
+ return true;
+ } else if (item.getItemId() == android.R.id.home) {
+ if (searchEditText.getVisibility() == View.VISIBLE) {
+ View view = this.getCurrentFocus();
+ if (view != null) {
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+ searchEditText.setVisibility(View.GONE);
+ searchEditText.setText("");
+ mMenu.findItem(R.id.action_search_subscribed_thing_listing_activity).setVisible(true);
+ sectionsPagerAdapter.changeSearchQuery("");
+ return true;
+ }
finish();
return true;
}
@@ -233,6 +290,23 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
}
@Override
+ public void onBackPressed() {
+ if (searchEditText.getVisibility() == View.VISIBLE) {
+ View view = this.getCurrentFocus();
+ if (view != null) {
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+ searchEditText.setVisibility(View.GONE);
+ searchEditText.setText("");
+ mMenu.findItem(R.id.action_search_subscribed_thing_listing_activity).setVisible(true);
+ sectionsPagerAdapter.changeSearchQuery("");
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
@@ -483,5 +557,17 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
multiRedditListingFragment.goBackToTop();
}
}
+
+ void changeSearchQuery(String searchQuery) {
+ if (subscribedSubredditsListingFragment != null) {
+ subscribedSubredditsListingFragment.changeSearchQuery(searchQuery);
+ }
+ if (followedUsersListingFragment != null) {
+
+ }
+ if (multiRedditListingFragment != null) {
+
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
index 11d902fb..755f4833 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
@@ -198,4 +198,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public void changeSearchQuery(String searchQuery) {
+ mSubscribedSubredditViewModel.setSearchQuery(searchQuery);
+ }
}
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 09d866ec..edcfa4cc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditDao.java
@@ -22,12 +22,18 @@ public interface SubscribedSubredditDao {
@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);
+
@Query("SELECT * from subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE AND username = :accountName COLLATE NOCASE LIMIT 1")
SubscribedSubredditData getSubscribedSubreddit(String subredditName, String accountName);
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 053ae1ed..0901da55 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditRepository.java
@@ -12,19 +12,21 @@ 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>> getAllSubscribedSubreddits() {
- return mAllSubscribedSubreddits;
+ LiveData<List<SubscribedSubredditData>> getAllSubscribedSubredditsWithSearchQuery(String searchQuery) {
+ return mSubscribedSubredditDao.getAllSubscribedSubredditsWithSearchQuery(mAccountName, searchQuery);
}
- public LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubreddits() {
- return mAllFavoriteSubscribedSubreddits;
+ public LiveData<List<SubscribedSubredditData>> getAllFavoriteSubscribedSubredditsWithSearchQuery(String searchQuery) {
+ return mSubscribedSubredditDao.getAllFavoriteSubscribedSubredditsWithSearchQuery(mAccountName, searchQuery);
}
public void insert(SubscribedSubredditData subscribedSubredditData) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditViewModel.java
index fa38fcac..6191b680 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subscribedsubreddit/SubscribedSubredditViewModel.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 SubscribedSubredditViewModel extends AndroidViewModel {
private SubscribedSubredditRepository mSubscribedSubredditRepository;
private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
private LiveData<List<SubscribedSubredditData>> mAllFavoriteSubscribedSubreddits;
+ private MutableLiveData<String> searchQueryLiveData;
public SubscribedSubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application);
mSubscribedSubredditRepository = new SubscribedSubredditRepository(redditDataRoomDatabase, accountName);
- mAllSubscribedSubreddits = mSubscribedSubredditRepository.getAllSubscribedSubreddits();
- mAllFavoriteSubscribedSubreddits = mSubscribedSubredditRepository.getAllFavoriteSubscribedSubreddits();
+ searchQueryLiveData = new MutableLiveData<>();
+ searchQueryLiveData.postValue("");
+
+ mAllSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllSubscribedSubredditsWithSearchQuery(searchQuery));
+ mAllFavoriteSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllFavoriteSubscribedSubredditsWithSearchQuery(searchQuery));
}
public LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits() {
@@ -36,6 +42,10 @@ public class SubscribedSubredditViewModel extends AndroidViewModel {
mSubscribedSubredditRepository.insert(subscribedSubredditData);
}
+ 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/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml
index 10037a07..15e8fd7b 100644
--- a/app/src/main/res/layout/activity_subscribed_thing_listing.xml
+++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml
@@ -29,7 +29,21 @@
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
- app:navigationIcon="?attr/homeAsUpIndicator" />
+ app:navigationIcon="?attr/homeAsUpIndicator">
+
+ <EditText
+ android:id="@+id/search_edit_text_subscribed_thing_listing_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#00000000"
+ android:gravity="top"
+ android:hint="@string/search"
+ android:maxLines="1"
+ android:textSize="?attr/font_20"
+ android:fontFamily="?attr/font_family"
+ android:visibility="gone" />
+
+ </androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
diff --git a/app/src/main/res/menu/subscribed_thing_listing_activity.xml b/app/src/main/res/menu/subscribed_thing_listing_activity.xml
new file mode 100644
index 00000000..83e6d9a5
--- /dev/null
+++ b/app/src/main/res/menu/subscribed_thing_listing_activity.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_search_subscribed_thing_listing_activity"
+ android:orderInCategory="1"
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_search_toolbar_24dp"
+ app:showAsAction="ifRoom" />
+</menu> \ No newline at end of file