diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-17 02:28:09 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-17 02:28:09 +0000 |
commit | b2cf64db9dc0fca20be122e341573602ac3d5c32 (patch) | |
tree | de46c89f2bea22eeaf366c3a3319e4222e89a4eb /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | a8d511295513a07b9a91478a60755f55127191cd (diff) | |
download | infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar.gz infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar.bz2 infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar.lz infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar.xz infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.tar.zst infinity-for-reddit-b2cf64db9dc0fca20be122e341573602ac3d5c32.zip |
Continue adding comment filter.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
12 files changed, 461 insertions, 19 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 2bf647ec..b4cb2444 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -9,6 +9,7 @@ import dagger.Component; 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.CreateMultiRedditActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemePreviewActivity; @@ -307,6 +308,8 @@ public interface AppComponent { void inject(MorePostsInfoFragment morePostsInfoFragment); + void inject(CommentFilterPreferenceActivity commentFilterPreferenceActivity); + @Component.Factory interface Factory { AppComponent create(@BindsInstance Application application); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 6c559df3..e89a47dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -14,7 +14,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.account.AccountDao; import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterDao; import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsageDao; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDao; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; @@ -80,6 +82,10 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao(); + public abstract CommentFilterDao commentFilterDao(); + + public abstract CommentFilterUsageDao commentFilterUsageDao(); + private static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(SupportSQLiteDatabase database) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java new file mode 100644 index 00000000..aaddff6e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterPreferenceActivity.java @@ -0,0 +1,125 @@ +package ml.docilealligator.infinityforreddit.activities; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.MenuItem; + +import androidx.annotation.NonNull; +import androidx.lifecycle.ViewModelProvider; + +import java.util.concurrent.Executor; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.adapters.CommentFilterWithUsageRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.CommentFilterOptionsBottomSheetFragment; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterWithUsageViewModel; +import ml.docilealligator.infinityforreddit.commentfilter.DeleteCommentFilter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ActivityCommentFilterPreferenceBinding; + +public class CommentFilterPreferenceActivity extends BaseActivity { + + private ActivityCommentFilterPreferenceBinding binding; + + @Inject + @Named("default") + SharedPreferences sharedPreferences; + @Inject + RedditDataRoomDatabase redditDataRoomDatabase; + @Inject + CustomThemeWrapper customThemeWrapper; + @Inject + Executor executor; + public CommentFilterWithUsageViewModel commentFilterWithUsageViewModel; + private CommentFilterWithUsageRecyclerViewAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + + setImmersiveModeNotApplicable(); + + super.onCreate(savedInstanceState); + binding = ActivityCommentFilterPreferenceBinding.inflate(getLayoutInflater()); + + setContentView(binding.getRoot()); + + ButterKnife.bind(this); + + applyCustomTheme(); + + setSupportActionBar(binding.toolbarCommentFilterPreferenceActivity); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + binding.fabCommentFilterPreferenceActivity.setOnClickListener(view -> { + Intent intent = new Intent(this, CustomizeCommentFilterActivity.class); + intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true); + startActivity(intent); + }); + + adapter = new CommentFilterWithUsageRecyclerViewAdapter(this, commentFilter -> { + CommentFilterOptionsBottomSheetFragment commentFilterOptionsBottomSheetFragment = new CommentFilterOptionsBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putParcelable(CommentFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, commentFilter); + commentFilterOptionsBottomSheetFragment.setArguments(bundle); + commentFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterOptionsBottomSheetFragment.getTag()); + }); + + binding.recyclerViewCommentFilterPreferenceActivity.setAdapter(adapter); + + commentFilterWithUsageViewModel = new ViewModelProvider(this, + new CommentFilterWithUsageViewModel.Factory(redditDataRoomDatabase)).get(CommentFilterWithUsageViewModel.class); + + commentFilterWithUsageViewModel.getCommentFilterWithUsageListLiveData().observe(this, commentFilterWithUsages -> adapter.setCommentFilterWithUsageList(commentFilterWithUsages)); + } + + public void editCommentFilter(CommentFilter commentFilter) { + Intent intent = new Intent(this, CustomizeCommentFilterActivity.class); + intent.putExtra(CustomizeCommentFilterActivity.EXTRA_POST_FILTER, commentFilter); + intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true); + startActivity(intent); + } + + public void applyCommentFilterTo(CommentFilter commentFilter) { + Intent intent = new Intent(this, CommentFilterUsageListingActivity.class); + intent.putExtra(CommentFilterUsageListingActivity.EXTRA_POST_FILTER, commentFilter); + startActivity(intent); + } + + public void deleteCommentFilter(CommentFilter commentFilter) { + DeleteCommentFilter.deleteCommentFilter(redditDataRoomDatabase, executor, commentFilter); + } + + @Override + protected SharedPreferences getDefaultSharedPreferences() { + return sharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return customThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterPreferenceActivity, binding.collapsingToolbarLayoutCommentFilterPreferenceActivity, binding.toolbarCommentFilterPreferenceActivity); + applyFABTheme(binding.fabCommentFilterPreferenceActivity); + binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor()); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return false; + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java new file mode 100644 index 00000000..587addcf --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentFilterUsageListingActivity.java @@ -0,0 +1,18 @@ +package ml.docilealligator.infinityforreddit.activities; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; + +import ml.docilealligator.infinityforreddit.R; + +public class CommentFilterUsageListingActivity extends AppCompatActivity { + + public static final String EXTRA_POST_FILTER = "EPF"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_comment_filter_usage_listing); + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java new file mode 100644 index 00000000..68a31b6f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java @@ -0,0 +1,19 @@ +package ml.docilealligator.infinityforreddit.activities; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; + +import ml.docilealligator.infinityforreddit.R; + +public class CustomizeCommentFilterActivity extends AppCompatActivity { + + public static final String EXTRA_POST_FILTER = "EPF"; + public static final String EXTRA_FROM_SETTINGS = "EFS"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customize_comment_filter); + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageEmbeddedRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageEmbeddedRecyclerViewAdapter.java new file mode 100644 index 00000000..5d1ad217 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterUsageEmbeddedRecyclerViewAdapter.java @@ -0,0 +1,79 @@ +package ml.docilealligator.infinityforreddit.adapters; + +import android.view.LayoutInflater; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +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.databinding.ItemCommentFilterUsageEmbeddedBinding; + +public class CommentFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter<CommentFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> { + private BaseActivity baseActivity; + private List<CommentFilterUsage> commentFilterUsageList; + + public CommentFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) { + this.baseActivity = baseActivity; + } + + @NonNull + @Override + public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new EntryViewHolder(ItemCommentFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) { + if (commentFilterUsageList == null || commentFilterUsageList.isEmpty()) { + holder.textView.setText(R.string.click_to_apply_post_filter); + } else if (holder.getBindingAdapterPosition() > 4) { + holder.textView.setText(baseActivity.getString(R.string.post_filter_usage_embedded_more_count, commentFilterUsageList.size() - 5)); + } else { + CommentFilterUsage commentFilterUsage = commentFilterUsageList.get(holder.getBindingAdapterPosition()); + switch (commentFilterUsage.usage) { + case CommentFilterUsage.SUBREDDIT_TYPE: + holder.textView.setText("r/" + commentFilterUsage.nameOfUsage); + break; + case CommentFilterUsage.USER_TYPE: + holder.textView.setText("u/" + commentFilterUsage.nameOfUsage); + break; + } + } + } + + @Override + public int getItemCount() { + return commentFilterUsageList == null || commentFilterUsageList.isEmpty() ? 1 : (commentFilterUsageList.size() > 5 ? 6 : commentFilterUsageList.size()); + } + + public void setCommentFilterUsageList(List<CommentFilterUsage> commentFilterUsageList) { + this.commentFilterUsageList = commentFilterUsageList; + notifyDataSetChanged(); + } + + class EntryViewHolder extends RecyclerView.ViewHolder { + TextView textView; + + public EntryViewHolder(@NonNull ItemCommentFilterUsageEmbeddedBinding binding) { + super(binding.getRoot()); + textView = binding.getRoot(); + + textView.setTextColor(baseActivity.customThemeWrapper.getSecondaryTextColor()); + + if (baseActivity.typeface != null) { + textView.setTypeface(baseActivity.typeface); + } + + textView.setOnClickListener(view -> { + Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show(); + }); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterWithUsageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterWithUsageRecyclerViewAdapter.java new file mode 100644 index 00000000..48fd090f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentFilterWithUsageRecyclerViewAdapter.java @@ -0,0 +1,80 @@ +package ml.docilealligator.infinityforreddit.adapters; + +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterWithUsage; +import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.ItemCommentFilterWithUsageBinding; + +public class CommentFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; + private final OnItemClickListener onItemClickListener; + private List<CommentFilterWithUsage> commentFilterWithUsageList; + private RecyclerView.RecycledViewPool recycledViewPool; + + public interface OnItemClickListener { + void onItemClick(CommentFilter commentFilter); + } + + public CommentFilterWithUsageRecyclerViewAdapter(BaseActivity activity, OnItemClickListener onItemClickListener) { + this.activity = activity; + this.recycledViewPool = new RecyclerView.RecycledViewPool(); + this.onItemClickListener = onItemClickListener; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new CommentFilterViewHolder(ItemCommentFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof CommentFilterViewHolder) { + ((CommentFilterViewHolder) holder).binding.commentFilterNameTextViewItemCommentFilter.setText(commentFilterWithUsageList.get(position - 1).commentFilter.name); + ((CommentFilterViewHolder) holder).adapter.setCommentFilterUsageList(commentFilterWithUsageList.get(position - 1).commentFilterUsageList); + } + } + + @Override + public int getItemCount() { + return commentFilterWithUsageList == null ? 1 : 1 + commentFilterWithUsageList.size(); + } + + public void setCommentFilterWithUsageList(List<CommentFilterWithUsage> commentFilterWithUsageList) { + this.commentFilterWithUsageList = commentFilterWithUsageList; + notifyDataSetChanged(); + } + + private class CommentFilterViewHolder extends RecyclerView.ViewHolder { + ItemCommentFilterWithUsageBinding binding; + CommentFilterUsageEmbeddedRecyclerViewAdapter adapter; + + public CommentFilterViewHolder(@NonNull ItemCommentFilterWithUsageBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.commentFilterNameTextViewItemCommentFilter.setTextColor(activity.customThemeWrapper.getPrimaryTextColor()); + + if (activity.typeface != null) { + binding.commentFilterNameTextViewItemCommentFilter.setTypeface(activity.typeface); + } + + binding.getRoot().setOnClickListener(view -> { + onItemClickListener.onItemClick(commentFilterWithUsageList.get(getBindingAdapterPosition() - 1).commentFilter); + }); + + binding.commentFilterUsageRecyclerViewItemCommentFilter.setRecycledViewPool(recycledViewPool); + binding.commentFilterUsageRecyclerViewItemCommentFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity)); + adapter = new CommentFilterUsageEmbeddedRecyclerViewAdapter(activity); + binding.commentFilterUsageRecyclerViewItemCommentFilter.setAdapter(adapter); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterOptionsBottomSheetFragment.java new file mode 100644 index 00000000..fd06d30e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentFilterOptionsBottomSheetFragment.java @@ -0,0 +1,63 @@ +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 androidx.fragment.app.Fragment; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.CommentFilterPreferenceActivity; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentCommentFilterOptionsBottomSheetBinding; +import ml.docilealligator.infinityforreddit.utils.Utils; + +public class CommentFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { + + public static final String EXTRA_POST_FILTER = "EPF"; + private CommentFilterPreferenceActivity activity; + + public CommentFilterOptionsBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + FragmentCommentFilterOptionsBottomSheetBinding binding = FragmentCommentFilterOptionsBottomSheetBinding.inflate(inflater, container, false); + + CommentFilter commentFilter = getArguments().getParcelable(EXTRA_POST_FILTER); + + binding.editTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> { + activity.editCommentFilter(commentFilter); + dismiss(); + }); + + binding.applyToTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> { + activity.applyCommentFilterTo(commentFilter); + dismiss(); + }); + + binding.deleteTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> { + activity.deleteCommentFilter(commentFilter); + 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 = (CommentFilterPreferenceActivity) context; + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java index 268f82ba..049549d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java @@ -5,26 +5,17 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentPostFilterOptionsBottomSheetBinding; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.utils.Utils; public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { - @BindView(R.id.edit_text_view_post_filter_options_bottom_sheet_fragment) - TextView editTextView; - @BindView(R.id.apply_to_text_view_post_filter_options_bottom_sheet_fragment) - TextView applyToTextView; - @BindView(R.id.delete_text_view_post_filter_options_bottom_sheet_fragment) - TextView deleteTextView; public static final String EXTRA_POST_FILTER = "EPF"; private PostFilterPreferenceActivity activity; @@ -36,32 +27,30 @@ public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRound public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_post_filter_options_bottom_sheet, container, false); - - ButterKnife.bind(this, rootView); + FragmentPostFilterOptionsBottomSheetBinding binding = FragmentPostFilterOptionsBottomSheetBinding.inflate(inflater, container, false); PostFilter postFilter = getArguments().getParcelable(EXTRA_POST_FILTER); - editTextView.setOnClickListener(view -> { + binding.editTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> { activity.editPostFilter(postFilter); dismiss(); }); - applyToTextView.setOnClickListener(view -> { + binding.applyToTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> { activity.applyPostFilterTo(postFilter); dismiss(); }); - deleteTextView.setOnClickListener(view -> { + binding.deleteTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> { activity.deletePostFilter(postFilter); dismiss(); }); if (activity.typeface != null) { - Utils.setFontToAllTextViews(rootView, activity.typeface); + Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface); } - return rootView; + return binding.getRoot(); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java index 9ee9e856..670786a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java @@ -1,5 +1,16 @@ package ml.docilealligator.infinityforreddit.commentfilter; -public class CommentFilterWithUsage { +import androidx.room.Embedded; +import androidx.room.Relation; + +import java.util.List; +public class CommentFilterWithUsage { + @Embedded + public CommentFilter commentFilter; + @Relation( + parentColumn = "name", + entityColumn = "name" + ) + public List<CommentFilterUsage> commentFilterUsageList; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsageViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsageViewModel.java new file mode 100644 index 00000000..fb8733fe --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsageViewModel.java @@ -0,0 +1,38 @@ +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 CommentFilterWithUsageViewModel extends ViewModel { + private LiveData<List<CommentFilterWithUsage>> mCommentFilterWithUsageListLiveData; + + public CommentFilterWithUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase) { + mCommentFilterWithUsageListLiveData = redditDataRoomDatabase.commentFilterDao().getAllCommentFilterWithUsageLiveData(); + } + + public LiveData<List<CommentFilterWithUsage>> getCommentFilterWithUsageListLiveData() { + return mCommentFilterWithUsageListLiveData; + } + + public static class Factory extends ViewModelProvider.NewInstanceFactory { + + private final RedditDataRoomDatabase mRedditDataRoomDatabase; + + public Factory(RedditDataRoomDatabase redditDataRoomDatabase) { + mRedditDataRoomDatabase = redditDataRoomDatabase; + } + + @NonNull + @Override + public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { + //noinspection unchecked + return (T) new CommentFilterWithUsageViewModel(mRedditDataRoomDatabase); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilter.java new file mode 100644 index 00000000..1fb18070 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/DeleteCommentFilter.java @@ -0,0 +1,11 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteCommentFilter { + public static void deleteCommentFilter(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, CommentFilter commentFilter) { + executor.execute(() -> redditDataRoomDatabase.commentFilterDao().deleteCommentFilter(commentFilter)); + } +} |