aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-19 20:12:47 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-19 20:12:47 +0000
commit2ac4a7f8059fdef8bd151e72f294d453d9c163c2 (patch)
tree27de9a3ce105c3fce7312a01e58b37033915dc8a /app/src/main
parent3a52b39a04b3a4d2c3b6180aa2f152ea50911ff7 (diff)
downloadinfinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar.gz
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar.bz2
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar.lz
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar.xz
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.tar.zst
infinity-for-reddit-2ac4a7f8059fdef8bd151e72f294d453d9c163c2.zip
Continue adding comment filter.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java173
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageRecyclerViewAdapter.java82
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterUsageOptionsBottomSheetFragment.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewCommentFilterUsageBottomSheetFragment.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageViewModel.java40
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilterUsage.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/SaveCommentFilterUsage.java12
-rw-r--r--app/src/main/res/layout/activity_comment_filter_usage_listing.xml49
-rw-r--r--app/src/main/res/layout/dialog_edit_post_or_comment_filter_name_of_usage.xml (renamed from app/src/main/res/layout/dialog_edit_post_filter_name_of_usage.xml)5
-rw-r--r--app/src/main/res/layout/fragment_comment_filter_usage_options_bottom_sheet.xml52
-rw-r--r--app/src/main/res/layout/fragment_new_comment_filter_usage_bottom_sheet.xml52
-rw-r--r--app/src/main/res/values/strings.xml9
16 files changed, 590 insertions, 20 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a72dd210..8a67b013 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -38,6 +38,7 @@
<activity
android:name=".activities.CommentFilterUsageListingActivity"
android:parentActivityName=".activities.SettingsActivity"
+ android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.CustomizeCommentFilterActivity"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 2bb4f6ec..1cb8956a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -10,6 +10,7 @@ import ml.docilealligator.infinityforreddit.activities.AccountPostsActivity;
import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity;
import ml.docilealligator.infinityforreddit.activities.CommentActivity;
import ml.docilealligator.infinityforreddit.activities.CommentFilterPreferenceActivity;
+import ml.docilealligator.infinityforreddit.activities.CommentFilterUsageListingActivity;
import ml.docilealligator.infinityforreddit.activities.CreateMultiRedditActivity;
import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity;
import ml.docilealligator.infinityforreddit.activities.CustomThemePreviewActivity;
@@ -313,6 +314,8 @@ public interface AppComponent {
void inject(CustomizeCommentFilterActivity customizeCommentFilterActivity);
+ void inject(CommentFilterUsageListingActivity commentFilterUsageListingActivity);
+
@Component.Factory
interface Factory {
AppComponent create(@BindsInstance Application application);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java
index 170c5335..71b2a765 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java
@@ -89,7 +89,7 @@ public class CommentFilterPreferenceActivity extends BaseActivity {
public void applyCommentFilterTo(CommentFilter commentFilter) {
Intent intent = new Intent(this, CommentFilterUsageListingActivity.class);
- intent.putExtra(CommentFilterUsageListingActivity.EXTRA_POST_FILTER, commentFilter);
+ intent.putExtra(CommentFilterUsageListingActivity.EXTRA_COMMENT_FILTER, commentFilter);
startActivity(intent);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java
index 587addcf..b174e9e8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java
@@ -1,18 +1,183 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.content.SharedPreferences;
+import android.content.res.ColorStateList;
import android.os.Bundle;
+import android.os.Handler;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
-import androidx.appcompat.app.AppCompatActivity;
+import androidx.annotation.NonNull;
+import androidx.lifecycle.ViewModelProvider;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.textfield.TextInputEditText;
+import com.google.android.material.textfield.TextInputLayout;
+
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.adapters.CommentFilterUsageRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.CommentFilterUsageOptionsBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.NewCommentFilterUsageBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsageViewModel;
+import ml.docilealligator.infinityforreddit.commentfilter.DeleteCommentFilterUsage;
+import ml.docilealligator.infinityforreddit.commentfilter.SaveCommentFilterUsage;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.databinding.ActivityCommentFilterUsageListingBinding;
+import ml.docilealligator.infinityforreddit.utils.Utils;
-public class CommentFilterUsageListingActivity extends AppCompatActivity {
+public class CommentFilterUsageListingActivity extends BaseActivity {
- public static final String EXTRA_POST_FILTER = "EPF";
+ public static final String EXTRA_COMMENT_FILTER = "ECF";
+ @Inject
+ @Named("default")
+ SharedPreferences sharedPreferences;
+ @Inject
+ RedditDataRoomDatabase redditDataRoomDatabase;
+ @Inject
+ CustomThemeWrapper customThemeWrapper;
+ @Inject
+ Executor executor;
+ private ActivityCommentFilterUsageListingBinding binding;
+ public CommentFilterUsageViewModel commentFilterUsageViewModel;
+ private CommentFilterUsageRecyclerViewAdapter adapter;
+ private CommentFilter commentFilter;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ setImmersiveModeNotApplicable();
+
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_comment_filter_usage_listing);
+ binding = ActivityCommentFilterUsageListingBinding.inflate(getLayoutInflater());
+ setContentView(binding.getRoot());
+
+ applyCustomTheme();
+
+ setSupportActionBar(binding.toolbarCommentFilterUsageListingActivity);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ commentFilter = getIntent().getParcelableExtra(EXTRA_COMMENT_FILTER);
+
+ setTitle(commentFilter.name);
+
+ binding.fabCommentFilterUsageListingActivity.setOnClickListener(view -> {
+ NewCommentFilterUsageBottomSheetFragment newCommentFilterUsageBottomSheetFragment = new NewCommentFilterUsageBottomSheetFragment();
+ newCommentFilterUsageBottomSheetFragment.show(getSupportFragmentManager(), newCommentFilterUsageBottomSheetFragment.getTag());
+ });
+
+ adapter = new CommentFilterUsageRecyclerViewAdapter(this, customThemeWrapper, commentFilterUsage -> {
+ CommentFilterUsageOptionsBottomSheetFragment commentFilterUsageOptionsBottomSheetFragment = new CommentFilterUsageOptionsBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(CommentFilterUsageOptionsBottomSheetFragment.EXTRA_COMMENT_FILTER_USAGE, commentFilterUsage);
+ commentFilterUsageOptionsBottomSheetFragment.setArguments(bundle);
+ commentFilterUsageOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterUsageOptionsBottomSheetFragment.getTag());
+ });
+ binding.recyclerViewCommentFilterUsageListingActivity.setAdapter(adapter);
+
+ commentFilterUsageViewModel = new ViewModelProvider(this,
+ new CommentFilterUsageViewModel.Factory(redditDataRoomDatabase, commentFilter.name)).get(CommentFilterUsageViewModel.class);
+
+ commentFilterUsageViewModel.getCommentFilterUsageListLiveData().observe(this, commentFilterUsages -> adapter.setCommentFilterUsages(commentFilterUsages));
+ }
+
+ public void newCommentFilterUsage(int type) {
+ switch (type) {
+ case CommentFilterUsage.SUBREDDIT_TYPE:
+ case CommentFilterUsage.USER_TYPE:
+ editAndCommentFilterUsageNameOfUsage(type, null);
+ break;
+ }
+ }
+
+ private void editAndCommentFilterUsageNameOfUsage(int type, String nameOfUsage) {
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
+ TextView messageTextView = dialogView.findViewById(R.id.message_text_view_edit_post_or_comment_filter_name_of_usage_dialog);
+ messageTextView.setVisibility(View.GONE);
+ TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
+ TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
+ int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
+ textInputLayout.setBoxStrokeColor(primaryTextColor);
+ textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ textInputEditText.setTextColor(primaryTextColor);
+ if (nameOfUsage != null) {
+ textInputEditText.setText(nameOfUsage);
+ }
+ textInputEditText.requestFocus();
+ int titleStringId = R.string.subreddit;
+ switch (type) {
+ case CommentFilterUsage.SUBREDDIT_TYPE:
+ textInputEditText.setHint(R.string.settings_tab_subreddit_name);
+ break;
+ case CommentFilterUsage.USER_TYPE:
+ textInputEditText.setHint(R.string.settings_tab_username);
+ titleStringId = R.string.user;
+ break;
+ }
+
+ Utils.showKeyboard(this, new Handler(), textInputEditText);
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(titleStringId)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (editTextDialogInterface, i1)
+ -> {
+ Utils.hideKeyboard(this);
+
+ CommentFilterUsage commentFilterUsage;
+ if (!textInputEditText.getText().toString().equals("")) {
+ commentFilterUsage = new CommentFilterUsage(commentFilter.name, type, textInputEditText.getText().toString());
+ SaveCommentFilterUsage.saveCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
+ }
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .setOnDismissListener(editTextDialogInterface -> {
+ Utils.hideKeyboard(this);
+ })
+ .show();
+ }
+
+ public void editCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
+ editAndCommentFilterUsageNameOfUsage(commentFilterUsage.usage, commentFilterUsage.nameOfUsage);
+ }
+
+ public void deleteCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
+ DeleteCommentFilterUsage.deleteCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
+ }
+
+ @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() {
+ applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterUsageListingActivity, binding.collapsingToolbarLayoutCommentFilterUsageListingActivity, binding.toolbarCommentFilterUsageListingActivity);
+ applyFABTheme(binding.fabCommentFilterUsageListingActivity);
+ binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor());
}
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java
index f92bf933..bb3265fa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java
@@ -1,13 +1,11 @@
package ml.docilealligator.infinityforreddit.activities;
-import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
-import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
@@ -127,9 +125,9 @@ public class PostFilterUsageListingActivity extends BaseActivity {
}
private void editAndPostFilterUsageNameOfUsage(int type, String nameOfUsage) {
- View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_filter_name_of_usage, null);
- TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_filter_name_of_usage_dialog);
- TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_filter_name_of_usage_dialog);
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
+ TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
+ TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
textInputLayout.setBoxStrokeColor(primaryTextColor);
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageRecyclerViewAdapter.java
new file mode 100644
index 00000000..a6f510fd
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageRecyclerViewAdapter.java
@@ -0,0 +1,82 @@
+package ml.docilealligator.infinityforreddit.adapters;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.util.List;
+
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.activities.BaseActivity;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+
+public class CommentFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+ private List<CommentFilterUsage> commentFilterUsages;
+ private BaseActivity activity;
+ private CustomThemeWrapper customThemeWrapper;
+ private CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener;
+
+ public interface OnItemClickListener {
+ void onClick(CommentFilterUsage commentFilterUsage);
+ }
+
+ public CommentFilterUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
+ CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener) {
+ this.activity = activity;
+ this.customThemeWrapper = customThemeWrapper;
+ this.onItemClickListener = onItemClickListener;
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter_usage, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ CommentFilterUsage commentFilterUsage = commentFilterUsages.get(position);
+ switch (commentFilterUsage.usage) {
+ case CommentFilterUsage.SUBREDDIT_TYPE:
+ ((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_subreddit, commentFilterUsage.nameOfUsage));
+ break;
+ case CommentFilterUsage.USER_TYPE:
+ ((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_user, commentFilterUsage.nameOfUsage));
+ break;
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return commentFilterUsages == null ? 0 : commentFilterUsages.size();
+ }
+
+ public void setCommentFilterUsages(List<CommentFilterUsage> commentFilterUsages) {
+ this.commentFilterUsages = commentFilterUsages;
+ notifyDataSetChanged();
+ }
+
+ private class CommentFilterUsageViewHolder extends RecyclerView.ViewHolder {
+ TextView usageTextView;
+
+ public CommentFilterUsageViewHolder(@NonNull View itemView) {
+ super(itemView);
+ usageTextView = (TextView) itemView;
+
+ usageTextView.setTextColor(customThemeWrapper.getPrimaryTextColor());
+
+ if (activity.typeface != null) {
+ usageTextView.setTypeface(activity.typeface);
+ }
+
+ usageTextView.setOnClickListener(view -> {
+ onItemClickListener.onClick(commentFilterUsages.get(getBindingAdapterPosition()));
+ });
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterUsageOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterUsageOptionsBottomSheetFragment.java
new file mode 100644
index 00000000..988dfdad
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterUsageOptionsBottomSheetFragment.java
@@ -0,0 +1,58 @@
+package ml.docilealligator.infinityforreddit.bottomsheetfragments;
+
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+
+import ml.docilealligator.infinityforreddit.activities.CommentFilterUsageListingActivity;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
+import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
+import ml.docilealligator.infinityforreddit.databinding.FragmentCommentFilterUsageOptionsBottomSheetBinding;
+import ml.docilealligator.infinityforreddit.utils.Utils;
+
+public class CommentFilterUsageOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
+
+ public static final String EXTRA_COMMENT_FILTER_USAGE = "ECFU";
+
+ private CommentFilterUsageListingActivity activity;
+
+ public CommentFilterUsageOptionsBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ FragmentCommentFilterUsageOptionsBottomSheetBinding binding = FragmentCommentFilterUsageOptionsBottomSheetBinding.inflate(inflater, container, false);
+
+ CommentFilterUsage commentFilterUsage = getArguments().getParcelable(EXTRA_COMMENT_FILTER_USAGE);
+
+ binding.editTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
+ activity.editCommentFilterUsage(commentFilterUsage);
+ dismiss();
+ });
+
+ binding.deleteTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
+ activity.deleteCommentFilterUsage(commentFilterUsage);
+ dismiss();
+ });
+
+ if (activity.typeface != null) {
+ Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
+ }
+
+ return binding.getRoot();
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (CommentFilterUsageListingActivity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewCommentFilterUsageBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewCommentFilterUsageBottomSheetFragment.java
new file mode 100644
index 00000000..2ff59d2b
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewCommentFilterUsageBottomSheetFragment.java
@@ -0,0 +1,52 @@
+package ml.docilealligator.infinityforreddit.bottomsheetfragments;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+
+import ml.docilealligator.infinityforreddit.activities.CommentFilterUsageListingActivity;
+import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
+import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
+import ml.docilealligator.infinityforreddit.databinding.FragmentNewCommentFilterUsageBottomSheetBinding;
+import ml.docilealligator.infinityforreddit.utils.Utils;
+
+public class NewCommentFilterUsageBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
+ private CommentFilterUsageListingActivity activity;
+
+ public NewCommentFilterUsageBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ FragmentNewCommentFilterUsageBottomSheetBinding binding = FragmentNewCommentFilterUsageBottomSheetBinding.inflate(inflater, container, false);
+
+ binding.subredditTextViewNewCommentFilterUsageBottomSheetFragment.setOnClickListener(view -> {
+ activity.newCommentFilterUsage(CommentFilterUsage.SUBREDDIT_TYPE);
+ dismiss();
+ });
+
+ binding.userTextViewNewCommentFilterUsageBottomSheetFragment.setOnClickListener(view -> {
+ activity.newCommentFilterUsage(CommentFilterUsage.USER_TYPE);
+ dismiss();
+ });
+
+ if (activity.typeface != null) {
+ Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
+ }
+
+ return binding.getRoot();
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (CommentFilterUsageListingActivity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageViewModel.java
new file mode 100644
index 00000000..89a03f41
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageViewModel.java
@@ -0,0 +1,40 @@
+package ml.docilealligator.infinityforreddit.commentfilter;
+
+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 CommentFilterUsageViewModel extends ViewModel {
+ private LiveData<List<CommentFilterUsage>> mCommentFilterUsageListLiveData;
+
+ public CommentFilterUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
+ mCommentFilterUsageListLiveData = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsageLiveData(name);
+ }
+
+ public LiveData<List<CommentFilterUsage>> getCommentFilterUsageListLiveData() {
+ return mCommentFilterUsageListLiveData;
+ }
+
+ public static class Factory extends ViewModelProvider.NewInstanceFactory {
+
+ private final RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private final String mName;
+
+ public Factory(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
+ mRedditDataRoomDatabase = redditDataRoomDatabase;
+ mName = name;
+ }
+
+ @NonNull
+ @Override
+ public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
+ //noinspection unchecked
+ return (T) new CommentFilterUsageViewModel(mRedditDataRoomDatabase, mName);
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilterUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilterUsage.java
new file mode 100644
index 00000000..69051515
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilterUsage.java
@@ -0,0 +1,12 @@
+package ml.docilealligator.infinityforreddit.commentfilter;
+
+import java.util.concurrent.Executor;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class DeleteCommentFilterUsage {
+ public static void deleteCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
+ CommentFilterUsage commentFilterUsage) {
+ executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().deleteCommentFilterUsage(commentFilterUsage));
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/SaveCommentFilterUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/SaveCommentFilterUsage.java
new file mode 100644
index 00000000..8060d9c0
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/SaveCommentFilterUsage.java
@@ -0,0 +1,12 @@
+package ml.docilealligator.infinityforreddit.commentfilter;
+
+import java.util.concurrent.Executor;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class SaveCommentFilterUsage {
+ public static void saveCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
+ CommentFilterUsage commentFilterUsage) {
+ executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().insert(commentFilterUsage));
+ }
+}
diff --git a/app/src/main/res/layout/activity_comment_filter_usage_listing.xml b/app/src/main/res/layout/activity_comment_filter_usage_listing.xml
index 6b268520..75cfc4e3 100644
--- a/app/src/main/res/layout/activity_comment_filter_usage_listing.xml
+++ b/app/src/main/res/layout/activity_comment_filter_usage_listing.xml
@@ -1,9 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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"
- tools:context=".activities.CommentFilterUsageListingActivity">
+ tools:context=".activities.PostFilterUsageListingActivity">
-</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_comment_filter_usage_listing_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_comment_filter_usage_listing_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_scrollFlags="scroll|enterAlways"
+ app:titleEnabled="false"
+ app:toolbarId="@+id/toolbar_comment_filter_usage_listing_activity">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_comment_filter_usage_listing_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_comment_filter_usage_listing_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fab_comment_filter_usage_listing_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/dialog_edit_post_filter_name_of_usage.xml b/app/src/main/res/layout/dialog_edit_post_or_comment_filter_name_of_usage.xml
index 48ee48f1..df776bae 100644
--- a/app/src/main/res/layout/dialog_edit_post_filter_name_of_usage.xml
+++ b/app/src/main/res/layout/dialog_edit_post_or_comment_filter_name_of_usage.xml
@@ -5,6 +5,7 @@
android:orientation="vertical">
<TextView
+ android:id="@+id/message_text_view_edit_post_or_comment_filter_name_of_usage_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
@@ -17,7 +18,7 @@
android:fontFamily="?attr/font_family" />
<com.google.android.material.textfield.TextInputLayout
- android:id="@+id/text_input_layout_edit_post_filter_name_of_usage_dialog"
+ android:id="@+id/text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
@@ -27,7 +28,7 @@
style="@style/Widget.Material3.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
- android:id="@+id/text_input_edit_text_edit_post_filter_name_of_usage_dialog"
+ android:id="@+id/text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
diff --git a/app/src/main/res/layout/fragment_comment_filter_usage_options_bottom_sheet.xml b/app/src/main/res/layout/fragment_comment_filter_usage_options_bottom_sheet.xml
new file mode 100644
index 00000000..cc9e4926
--- /dev/null
+++ b/app/src/main/res/layout/fragment_comment_filter_usage_options_bottom_sheet.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:paddingBottom="8dp"
+ android:overScrollMode="never">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/edit_text_view_comment_filter_usage_options_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/edit"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ app:drawableStartCompat="@drawable/ic_edit_24dp"
+ android:drawablePadding="48dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/delete_text_view_comment_filter_usage_options_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/delete"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ app:drawableStartCompat="@drawable/ic_delete_24dp"
+ android:drawablePadding="48dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ </LinearLayout>
+
+</androidx.core.widget.NestedScrollView> \ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_new_comment_filter_usage_bottom_sheet.xml b/app/src/main/res/layout/fragment_new_comment_filter_usage_bottom_sheet.xml
new file mode 100644
index 00000000..2cd5e545
--- /dev/null
+++ b/app/src/main/res/layout/fragment_new_comment_filter_usage_bottom_sheet.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:paddingBottom="8dp"
+ android:overScrollMode="never">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/subreddit_text_view_new_comment_filter_usage_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/subreddit"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ app:drawableStartCompat="@drawable/ic_subreddit_24dp"
+ android:drawablePadding="48dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/user_text_view_new_comment_filter_usage_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/user"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ app:drawableStartCompat="@drawable/ic_user_24dp"
+ android:drawablePadding="48dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ </LinearLayout>
+
+</androidx.core.widget.NestedScrollView> \ 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 9090da33..6f97b59f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1159,11 +1159,15 @@
<string name="subreddit">Subreddit</string>
<string name="user">User</string>
<string name="edit_post_filter_name_of_usage_info">Leave it blank to apply this post filter to all the subreddits / users / multireddits</string>
+ <string name="click_to_apply_post_filter">Click here to apply it to some post feeds</string>
+ <string name="post_filter_usage_embedded_more_count">and %1$d more</string>
<string name="comment_filter_name_hint">Comment Filter Name</string>
<string name="comment_filter_requires_a_name">What is the name of this comment filter?</string>
<string name="duplicate_comment_filter_dialog_title">\'%1$s\' Already Exists</string>
<string name="duplicate_comment_filter_dialog_message">Override it?</string>
+ <string name="comment_filter_applied_to_all_subreddits">Applied to all subreddits</string>
+ <string name="comment_filter_usage_embedded_more_count">and %1$d more</string>
<string name="read_all_messages_time_limit">You are doing this too frequently. Try again later. This is Reddit API\'s rate limit.</string>
<string name="read_all_messages_success">Read all messages successfully</string>
@@ -1383,9 +1387,4 @@
Otherwise, Infinity may not load posts at all. Sorry for the inconvenience.</string>
<string name="i_understand">I understand</string>
- <string name="click_to_apply_post_filter">Click here to apply it to some post feeds</string>
- <string name="post_filter_usage_embedded_more_count">and %1$d more</string>
- <string name="comment_filter_applied_to_all_subreddits">Applied to all subreddits</string>
- <string name="comment_filter_usage_embedded_more_count">and %1$d more</string>
-
</resources>