aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-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
11 files changed, 463 insertions, 2 deletions
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";