aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-10-28 00:59:57 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-10-28 00:59:57 +0000
commit84e4dd09c3bb585c4cfc4166c9f9207610458cf2 (patch)
tree1b5d613124bbdecb4cc246117a5a76d205359b91 /app
parente1b0b568ec21be256318d387ed2809ed3dc45b63 (diff)
downloadinfinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar.gz
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar.bz2
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar.lz
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar.xz
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.tar.zst
infinity-for-reddit-84e4dd09c3bb585c4cfc4166c9f9207610458cf2.zip
Add an option to filter subreddits in popular and all.
Diffstat (limited to '')
-rw-r--r--app/src/main/AndroidManifest.xml8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java155
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditFilterRecyclerViewAdapter.java72
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FilterPreferenceFragment.java38
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/DeleteSubredditFilter.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/InsertSubredditFilter.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilter.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterDao.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterViewModel.java36
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/drawable-night/ic_filter_24dp.xml9
-rw-r--r--app/src/main/res/drawable/ic_filter_24dp.xml9
-rw-r--r--app/src/main/res/layout/activity_subreddit_filter_popular_and_all.xml52
-rw-r--r--app/src/main/res/layout/item_selected_subreddit.xml6
-rw-r--r--app/src/main/res/values/strings.xml4
-rw-r--r--app/src/main/res/xml/filter_preferences.xml11
-rw-r--r--app/src/main/res/xml/main_preferences.xml5
19 files changed, 565 insertions, 4 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 265a9963..6cbdca3f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -32,7 +32,13 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
- <activity android:name=".Activity.FetchRandomSubredditOrPostActivity"
+ <activity android:name=".Activity.SubredditFilterPopularAndAllActivity"
+ android:label="@string/subreddit_filter_popular_and_all_activity_label"
+ android:parentActivityName=".Activity.SettingsActivity"
+ android:theme="@style/AppTheme.NoActionBar"
+ android:windowSoftInputMode="adjustResize" />
+ <activity
+ android:name=".Activity.FetchRandomSubredditOrPostActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java
new file mode 100644
index 00000000..88618b5e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java
@@ -0,0 +1,155 @@
+package ml.docilealligator.infinityforreddit.Activity;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Adapter.SubredditFilterRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SubredditFilter.DeleteSubredditFilter;
+import ml.docilealligator.infinityforreddit.SubredditFilter.InsertSubredditFilter;
+import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
+import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterViewModel;
+
+public class SubredditFilterPopularAndAllActivity extends BaseActivity {
+
+ @BindView(R.id.coordinator_layout_subreddit_filter_popular_and_all_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_subreddit_filter_popular_and_all_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_subreddit_filter_popular_and_all_activity)
+ Toolbar toolbar;
+ @BindView(R.id.recycler_view_subreddit_filter_popular_and_all_activity)
+ RecyclerView recyclerView;
+ @BindView(R.id.fab_subreddit_filter_popular_and_all_activity)
+ FloatingActionButton fab;
+ @Inject
+ @Named("default")
+ SharedPreferences sharedPreferences;
+ @Inject
+ RedditDataRoomDatabase redditDataRoomDatabase;
+ @Inject
+ CustomThemeWrapper customThemeWrapper;
+ SubredditFilterViewModel subredditFilterViewModel;
+ private SubredditFilterRecyclerViewAdapter adapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ setImmersiveModeNotApplicable();
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_subreddit_filter_popular_and_all);
+
+ ButterKnife.bind(this);
+
+ applyCustomTheme();
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ adapter = new SubredditFilterRecyclerViewAdapter(subredditFilter -> DeleteSubredditFilter.deleteSubredditFilter(redditDataRoomDatabase, subredditFilter, () -> {}));
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ recyclerView.setAdapter(adapter);
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy > 0) {
+ fab.hide();
+ } else if (dy < 0) {
+ fab.show();
+ }
+ }
+ });
+
+ subredditFilterViewModel = new ViewModelProvider(this,
+ new SubredditFilterViewModel.Factory(redditDataRoomDatabase))
+ .get(SubredditFilterViewModel.class);
+ subredditFilterViewModel.getSubredditFilterLiveData().observe(this, subredditFilters -> adapter.updateSubredditsName(subredditFilters));
+
+ fab.setOnClickListener(view -> {
+ EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null);
+ thingEditText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.choose_a_subreddit)
+ .setView(thingEditText)
+ .setPositiveButton(R.string.ok, (dialogInterface, i)
+ -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ SubredditFilter subredditFilter = new SubredditFilter(thingEditText.getText().toString(), SubredditFilter.TYPE_POPULAR_AND_ALL);
+ InsertSubredditFilter.insertSubredditFilter(redditDataRoomDatabase, subredditFilter,
+ () -> {});
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .setNeutralButton(R.string.search, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ }
+ })
+ .setOnDismissListener(dialogInterface -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
+ .show();
+ });
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return sharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return customThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditFilterRecyclerViewAdapter.java
new file mode 100644
index 00000000..28678b40
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditFilterRecyclerViewAdapter.java
@@ -0,0 +1,72 @@
+package ml.docilealligator.infinityforreddit.Adapter;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
+
+public class SubredditFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+ private List<SubredditFilter> subredditFilters;
+ private ItemClickListener itemClickListener;
+
+ public SubredditFilterRecyclerViewAdapter(ItemClickListener itemClickListener) {
+ this.itemClickListener = itemClickListener;
+ }
+
+ public interface ItemClickListener {
+ void onItemDelete(SubredditFilter subredditFilter);
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new SubredditNameViewHolder(LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.item_selected_subreddit, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ if (holder instanceof SubredditNameViewHolder) {
+ ((SubredditNameViewHolder) holder).subredditRedditNameTextView.setText(subredditFilters.get(position).getSubredditName());
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return subredditFilters == null ? 0 : subredditFilters.size();
+ }
+
+ public void updateSubredditsName(List<SubredditFilter> subredditFilters) {
+ this.subredditFilters = subredditFilters;
+ notifyDataSetChanged();
+ }
+
+ class SubredditNameViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.subreddit_name_item_selected_subreddit)
+ TextView subredditRedditNameTextView;
+ @BindView(R.id.delete_image_view_item_selected_subreddit)
+ ImageView deleteImageView;
+
+ public SubredditNameViewHolder(@NonNull View itemView) {
+ super(itemView);
+
+ ButterKnife.bind(this, itemView);
+
+ deleteImageView.setOnClickListener(view -> {
+ itemClickListener.onItemDelete(subredditFilters.get(getAdapterPosition()));
+ });
+ }
+ }
+
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 4b83ac3f..6fc0c4b8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.Activity.SelectedSubredditsActivity;
import ml.docilealligator.infinityforreddit.Activity.SendPrivateMessageActivity;
import ml.docilealligator.infinityforreddit.Activity.SettingsActivity;
import ml.docilealligator.infinityforreddit.Activity.SubmitCrosspostActivity;
+import ml.docilealligator.infinityforreddit.Activity.SubredditFilterPopularAndAllActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
@@ -224,4 +225,6 @@ public interface AppComponent {
void inject(FetchRandomSubredditOrPostActivity fetchRandomSubredditOrPostActivity);
void inject(MiscellaneousPreferenceFragment miscellaneousPreferenceFragment);
+
+ void inject(SubredditFilterPopularAndAllActivity subredditFilterPopularAndAllActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
index 18ce485d..7e7a6c01 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
@@ -20,6 +20,8 @@ import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQuery;
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQueryDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
+import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
+import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterDao;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
@@ -28,7 +30,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
- SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class}, version = 11)
+ SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, SubredditFilter.class}, version = 12)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
private static RedditDataRoomDatabase INSTANCE;
@@ -40,7 +42,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
RedditDataRoomDatabase.class, "reddit_data")
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
- MIGRATION_9_10, MIGRATION_10_11)
+ MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12)
.build();
}
}
@@ -64,6 +66,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
public abstract RecentSearchQueryDao recentSearchQueryDao();
+ public abstract SubredditFilterDao subredditFilterDao();
+
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
@@ -243,4 +247,12 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
+ " ADD COLUMN over_18 INTEGER DEFAULT 0 NOT NULL");
}
};
+
+ private static final Migration MIGRATION_11_12 = new Migration(11, 12) {
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ database.execSQL("CREATE TABLE subreddit_filter" +
+ "(subreddit_name TEXT NOT NULL, type INTEGER NOT NULL, PRIMARY KEY(subreddit_name, type))");
+ }
+ };
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FilterPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FilterPreferenceFragment.java
new file mode 100644
index 00000000..a0555d5d
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FilterPreferenceFragment.java
@@ -0,0 +1,38 @@
+package ml.docilealligator.infinityforreddit.Settings;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+
+import ml.docilealligator.infinityforreddit.Activity.SubredditFilterPopularAndAllActivity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+public class FilterPreferenceFragment extends PreferenceFragmentCompat {
+
+ private Activity activity;
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.filter_preferences, rootKey);
+
+ Preference subredditFilterPopularAndAllPreference = findPreference(SharedPreferencesUtils.SUBREDDIT_FILTER_POPULAR_AND_ALL);
+
+ subredditFilterPopularAndAllPreference.setOnPreferenceClickListener(preference -> {
+ Intent intent = new Intent(activity, SubredditFilterPopularAndAllActivity.class);
+ activity.startActivity(intent);
+ return true;
+ });
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (Activity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/DeleteSubredditFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/DeleteSubredditFilter.java
new file mode 100644
index 00000000..63b856dc
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/DeleteSubredditFilter.java
@@ -0,0 +1,41 @@
+package ml.docilealligator.infinityforreddit.SubredditFilter;
+
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class DeleteSubredditFilter {
+ public interface DeleteSubredditFilterListener {
+ void success();
+ }
+
+ public static void deleteSubredditFilter(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
+ DeleteSubredditFilterListener deleteSubredditFilterListener) {
+ new DeleteSubredditFilterAsyncTask(redditDataRoomDatabase, subredditFilter, deleteSubredditFilterListener).execute();
+ }
+
+ private static class DeleteSubredditFilterAsyncTask extends AsyncTask<Void, Void, Void> {
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private SubredditFilter subredditFilter;
+ private DeleteSubredditFilterListener deleteSubredditFilterListener;
+
+ DeleteSubredditFilterAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
+ DeleteSubredditFilterListener deleteSubredditFilterListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.subredditFilter = subredditFilter;
+ this.deleteSubredditFilterListener = deleteSubredditFilterListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.subredditFilterDao().deleteSubredditFilter(subredditFilter);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteSubredditFilterListener.success();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/InsertSubredditFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/InsertSubredditFilter.java
new file mode 100644
index 00000000..b91fa1e2
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/InsertSubredditFilter.java
@@ -0,0 +1,41 @@
+package ml.docilealligator.infinityforreddit.SubredditFilter;
+
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class InsertSubredditFilter {
+ public interface InsertSubredditFilterListener {
+ void success();
+ }
+
+ public static void insertSubredditFilter(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
+ InsertSubredditFilterListener insertSubredditFilterListener) {
+ new InsertSubredditFilterAsyncTask(redditDataRoomDatabase, subredditFilter, insertSubredditFilterListener).execute();
+ }
+
+ private static class InsertSubredditFilterAsyncTask extends AsyncTask<Void, Void, Void> {
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private SubredditFilter subredditFilter;
+ private InsertSubredditFilterListener insertSubredditFilterListener;
+
+ InsertSubredditFilterAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
+ InsertSubredditFilterListener insertSubredditFilterListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.subredditFilter = subredditFilter;
+ this.insertSubredditFilterListener = insertSubredditFilterListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.subredditFilterDao().insert(subredditFilter);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ insertSubredditFilterListener.success();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilter.java
new file mode 100644
index 00000000..88ef79f7
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilter.java
@@ -0,0 +1,37 @@
+package ml.docilealligator.infinityforreddit.SubredditFilter;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+
+@Entity(tableName = "subreddit_filter", primaryKeys = {"subreddit_name", "type"})
+public class SubredditFilter {
+ public static int TYPE_POPULAR_AND_ALL = 0;
+ @NonNull
+ @ColumnInfo(name = "subreddit_name")
+ private String subredditName;
+ @ColumnInfo(name = "type")
+ private int type;
+
+ public SubredditFilter(@NonNull String subredditName, int type) {
+ this.subredditName = subredditName;
+ this.type = type;
+ }
+
+ @NonNull
+ public String getSubredditName() {
+ return subredditName;
+ }
+
+ public void setSubredditName(@NonNull String subredditName) {
+ this.subredditName = subredditName;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterDao.java
new file mode 100644
index 00000000..fb5d3829
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterDao.java
@@ -0,0 +1,25 @@
+package ml.docilealligator.infinityforreddit.SubredditFilter;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Delete;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+
+import java.util.List;
+
+@Dao
+public interface SubredditFilterDao {
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insert(SubredditFilter subredditFilter);
+
+ @Query("SELECT * FROM subreddit_filter")
+ LiveData<List<SubredditFilter>> getAllSubredditFiltersLiveData();
+
+ @Query("SELECT * FROM subreddit_filter")
+ List<SubredditFilter> getAllSubredditFilters();
+
+ @Delete
+ void deleteSubredditFilter(SubredditFilter subredditFilter);
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterViewModel.java
new file mode 100644
index 00000000..557e879d
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditFilter/SubredditFilterViewModel.java
@@ -0,0 +1,36 @@
+package ml.docilealligator.infinityforreddit.SubredditFilter;
+
+import androidx.annotation.NonNull;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
+import java.util.List;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class SubredditFilterViewModel extends ViewModel {
+ private LiveData<List<SubredditFilter>> subredditFilterLiveData;
+
+ public SubredditFilterViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
+ subredditFilterLiveData = redditDataRoomDatabase.subredditFilterDao().getAllSubredditFiltersLiveData();
+ }
+
+ public LiveData<List<SubredditFilter>> getSubredditFilterLiveData() {
+ return subredditFilterLiveData;
+ }
+
+ public static class Factory extends ViewModelProvider.NewInstanceFactory {
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+
+ public Factory(RedditDataRoomDatabase redditDataRoomDatabase) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ }
+
+ @NonNull
+ @Override
+ public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
+ return (T) new SubredditFilterViewModel(redditDataRoomDatabase);
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index a2b909eb..940cf3e3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -136,6 +136,7 @@ public class SharedPreferencesUtils {
public static final String DATA_SAVING_MODE_ALWAYS = "2";
public static final String NATIONAL_FLAGS = "national_flags";
public static final String RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE = "respect_subreddit_recommended_comment_sort_type";
+ public static final String SUBREDDIT_FILTER_POPULAR_AND_ALL = "subreddit_filter_popular_and_all";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";
diff --git a/app/src/main/res/drawable-night/ic_filter_24dp.xml b/app/src/main/res/drawable-night/ic_filter_24dp.xml
new file mode 100644
index 00000000..641119c4
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_filter_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M7,6h10l-5.01,6.3L7,6zM4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_filter_24dp.xml b/app/src/main/res/drawable/ic_filter_24dp.xml
new file mode 100644
index 00000000..869e7e5e
--- /dev/null
+++ b/app/src/main/res/drawable/ic_filter_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#000000"
+ android:pathData="M7,6h10l-5.01,6.3L7,6zM4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
+</vector>
diff --git a/app/src/main/res/layout/activity_subreddit_filter_popular_and_all.xml b/app/src/main/res/layout/activity_subreddit_filter_popular_and_all.xml
new file mode 100644
index 00000000..6a342718
--- /dev/null
+++ b/app/src/main/res/layout/activity_subreddit_filter_popular_and_all.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/coordinator_layout_subreddit_filter_popular_and_all_activity"
+ tools:context=".Activity.SubredditFilterPopularAndAllActivity">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_subreddit_filter_popular_and_all_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <com.google.android.material.appbar.CollapsingToolbarLayout
+ android:id="@+id/collapsing_toolbar_layout_subreddit_filter_popular_and_all_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_scrollFlags="scroll|enterAlways"
+ app:titleEnabled="false"
+ app:toolbarId="@+id/toolbar_subreddit_filter_popular_and_all_activity">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_subreddit_filter_popular_and_all_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?attr/actionBarSize"
+ app:popupTheme="@style/AppTheme.PopupOverlay"
+ app:navigationIcon="?attr/homeAsUpIndicator" />
+
+ </com.google.android.material.appbar.CollapsingToolbarLayout>
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/recycler_view_subreddit_filter_popular_and_all_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fab_subreddit_filter_popular_and_all_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/fab_margin"
+ android:layout_gravity="bottom|end"
+ app:backgroundTint="?attr/colorPrimaryLightTheme"
+ app:srcCompat="@drawable/ic_add_day_night_24dp"
+ app:tint="@android:color/white" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/item_selected_subreddit.xml b/app/src/main/res/layout/item_selected_subreddit.xml
index 6e1a570a..2e8ae1c9 100644
--- a/app/src/main/res/layout/item_selected_subreddit.xml
+++ b/app/src/main/res/layout/item_selected_subreddit.xml
@@ -15,6 +15,7 @@
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:textSize="?attr/font_default"
+ android:textColor="?attr/primaryTextColor"
android:fontFamily="?attr/font_family" />
<ImageView
@@ -22,6 +23,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
- android:src="@drawable/ic_delete_24dp" />
+ android:src="@drawable/ic_delete_24dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0375432b..f5d3bdec 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -33,6 +33,7 @@
<string name="view_reddit_gallery_activity_video_label">Video %1$d/%2$d</string>
<string name="submit_crosspost_activity_label">Crosspost</string>
<string name="give_award_activity_label">Give Award</string>
+ <string name="subreddit_filter_popular_and_all_activity_label">r/all and r/popular</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -497,6 +498,9 @@
<string name="settings_miscellaneous_title">Miscellaneous</string>
<string name="settings_respect_subreddit_recommended_comment_sort_type_title">Respect Subreddit Recommended Comment Sort Type</string>
<string name="settings_respect_subreddit_recommended_comment_sort_type_summary">Comment sort type will not be saved</string>
+ <string name="settings_filter_title">Filter</string>
+ <string name="settings_subreddit_filter_category">Subreddit Filter</string>
+ <string name="settings_subreddit_filter_popular_and_all">r/popular and r/all</string>
<string name="no_link_available">Cannot get the link</string>
diff --git a/app/src/main/res/xml/filter_preferences.xml b/app/src/main/res/xml/filter_preferences.xml
new file mode 100644
index 00000000..a0e2a991
--- /dev/null
+++ b/app/src/main/res/xml/filter_preferences.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <PreferenceCategory
+ app:title="@string/settings_subreddit_filter_category" />
+
+ <Preference
+ app:key="subreddit_filter_popular_and_all"
+ app:title="@string/settings_subreddit_filter_popular_and_all" />
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 8ada3e6c..1dea4177 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -59,6 +59,11 @@
app:fragment="ml.docilealligator.infinityforreddit.Settings.NsfwAndBlurringFragment"/>
<Preference
+ app:icon="@drawable/ic_filter_24dp"
+ app:title="@string/settings_filter_title"
+ app:fragment="ml.docilealligator.infinityforreddit.Settings.FilterPreferenceFragment"/>
+
+ <Preference
app:icon="@drawable/ic_miscellaneous_24dp"
app:title="@string/settings_miscellaneous_title"
app:fragment="ml.docilealligator.infinityforreddit.Settings.MiscellaneousPreferenceFragment"/>