From 70c2d571ce113d912bfc04cd86af36f602528740 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 15 Oct 2023 00:09:31 -0400 Subject: Continue implementing showing post filter usages in PostFilterPreferenceActivity. --- .../activities/PostFilterPreferenceActivity.java | 7 +- .../adapters/PostFilterRecyclerViewAdapter.java | 104 ------------------- .../PostFilterWithUsageRecyclerViewAdapter.java | 115 +++++++++++++++++++++ ...PostFilterUsageEmbeddedRecyclerViewAdapter.java | 65 ++++++++++++ app/src/main/res/layout/item_post_filter.xml | 35 ------- .../res/layout/item_post_filter_usage_embedded.xml | 8 ++ .../res/layout/item_post_filter_with_usage.xml | 38 +++++++ app/src/main/res/values/strings.xml | 3 + 8 files changed, 232 insertions(+), 143 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostFilterUsageEmbeddedRecyclerViewAdapter.java delete mode 100644 app/src/main/res/layout/item_post_filter.xml create mode 100644 app/src/main/res/layout/item_post_filter_usage_embedded.xml create mode 100644 app/src/main/res/layout/item_post_filter_with_usage.xml (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java index a8e49ae0..09ba5f0a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.util.Log; import android.view.MenuItem; import androidx.annotation.NonNull; @@ -29,7 +28,7 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.adapters.PostFilterRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.adapters.PostFilterWithUsageRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostFilterOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.post.Post; @@ -66,7 +65,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { @Inject Executor executor; public PostFilterWithUsageViewModel postFilterWithUsageViewModel; - private PostFilterRecyclerViewAdapter adapter; + private PostFilterWithUsageRecyclerViewAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -102,7 +101,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { } }); - adapter = new PostFilterRecyclerViewAdapter(this, customThemeWrapper, postFilter -> { + adapter = new PostFilterWithUsageRecyclerViewAdapter(this, customThemeWrapper, postFilter -> { if (post != null) { showPostFilterOptions(post, postFilter); } else if (subredditName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java deleted file mode 100644 index f15c269c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java +++ /dev/null @@ -1,104 +0,0 @@ -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.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.databinding.ItemPostFilterBinding; -import ml.docilealligator.infinityforreddit.postfilter.PostFilter; -import ml.docilealligator.infinityforreddit.postfilter.PostFilterWithUsage; -import ml.docilealligator.infinityforreddit.utils.Utils; - -public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter { - - private static final int VIEW_TYPE_HEADER = 1; - private static final int VIEW_TYPE_POST_FILTER = 2; - - private BaseActivity activity; - private CustomThemeWrapper customThemeWrapper; - private final OnItemClickListener onItemClickListener; - private List postFilterWithUsageList; - - public interface OnItemClickListener { - void onItemClick(PostFilter postFilter); - } - - public PostFilterRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, - OnItemClickListener onItemClickListener) { - this.activity = activity; - this.customThemeWrapper = customThemeWrapper; - this.onItemClickListener = onItemClickListener; - } - - @Override - public int getItemViewType(int position) { - if (position == 0) { - return VIEW_TYPE_HEADER; - } - return VIEW_TYPE_POST_FILTER; - } - - @NonNull - @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - if (viewType == VIEW_TYPE_HEADER) { - return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false)); - } else { - return new PostFilterViewHolder(ItemPostFilterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); - } - } - - @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof PostFilterViewHolder) { - ((PostFilterViewHolder) holder).binding.postFilterNameTextViewItemPostFilter.setText(postFilterWithUsageList.get(position - 1).postFilter.name); - } - } - - @Override - public int getItemCount() { - return postFilterWithUsageList == null ? 1 : 1 + postFilterWithUsageList.size(); - } - - public void setPostFilterWithUsageList(List postFilterWithUsageList) { - this.postFilterWithUsageList = postFilterWithUsageList; - notifyDataSetChanged(); - } - - private class PostFilterViewHolder extends RecyclerView.ViewHolder { - ItemPostFilterBinding binding; - - public PostFilterViewHolder(@NonNull ItemPostFilterBinding binding) { - super(binding.getRoot()); - this.binding = binding; - binding.postFilterNameTextViewItemPostFilter.setTextColor(customThemeWrapper.getPrimaryTextColor()); - - if (activity.typeface != null) { - binding.postFilterNameTextViewItemPostFilter.setTypeface(activity.typeface); - } - - binding.getRoot().setOnClickListener(view -> { - onItemClickListener.onItemClick(postFilterWithUsageList.get(getBindingAdapterPosition() - 1).postFilter); - }); - } - } - - private class HeaderViewHolder extends RecyclerView.ViewHolder { - - public HeaderViewHolder(@NonNull View itemView) { - super(itemView); - TextView infoTextView = itemView.findViewById(R.id.info_text_view_item_filter_fragment_header); - infoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); - infoTextView.setCompoundDrawablesWithIntrinsicBounds(Utils.getTintedDrawable(activity, R.drawable.ic_info_preference_24dp, activity.customThemeWrapper.getPrimaryIconColor()), null, null, null); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java new file mode 100644 index 00000000..73194143 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java @@ -0,0 +1,115 @@ +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.adapters.navigationdrawer.PostFilterUsageEmbeddedRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.ItemPostFilterWithUsageBinding; +import ml.docilealligator.infinityforreddit.postfilter.PostFilter; +import ml.docilealligator.infinityforreddit.postfilter.PostFilterWithUsage; +import ml.docilealligator.infinityforreddit.utils.Utils; + +public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter { + + private static final int VIEW_TYPE_HEADER = 1; + private static final int VIEW_TYPE_POST_FILTER = 2; + + private BaseActivity activity; + private CustomThemeWrapper customThemeWrapper; + private final OnItemClickListener onItemClickListener; + private List postFilterWithUsageList; + private RecyclerView.RecycledViewPool recycledViewPool; + + public interface OnItemClickListener { + void onItemClick(PostFilter postFilter); + } + + public PostFilterWithUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, + OnItemClickListener onItemClickListener) { + this.activity = activity; + this.customThemeWrapper = customThemeWrapper; + this.recycledViewPool = new RecyclerView.RecycledViewPool(); + this.onItemClickListener = onItemClickListener; + } + + @Override + public int getItemViewType(int position) { + if (position == 0) { + return VIEW_TYPE_HEADER; + } + return VIEW_TYPE_POST_FILTER; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == VIEW_TYPE_HEADER) { + return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false)); + } else { + return new PostFilterViewHolder(ItemPostFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof PostFilterViewHolder) { + ((PostFilterViewHolder) holder).binding.postFilterNameTextViewItemPostFilter.setText(postFilterWithUsageList.get(position - 1).postFilter.name); + ((PostFilterViewHolder) holder).adapter.setPostFilterUsageList(postFilterWithUsageList.get(position - 1).postFilterUsages); + } + } + + @Override + public int getItemCount() { + return postFilterWithUsageList == null ? 1 : 1 + postFilterWithUsageList.size(); + } + + public void setPostFilterWithUsageList(List postFilterWithUsageList) { + this.postFilterWithUsageList = postFilterWithUsageList; + notifyDataSetChanged(); + } + + private class PostFilterViewHolder extends RecyclerView.ViewHolder { + ItemPostFilterWithUsageBinding binding; + PostFilterUsageEmbeddedRecyclerViewAdapter adapter; + + public PostFilterViewHolder(@NonNull ItemPostFilterWithUsageBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.postFilterNameTextViewItemPostFilter.setTextColor(customThemeWrapper.getPrimaryTextColor()); + + if (activity.typeface != null) { + binding.postFilterNameTextViewItemPostFilter.setTypeface(activity.typeface); + } + + binding.getRoot().setOnClickListener(view -> { + onItemClickListener.onItemClick(postFilterWithUsageList.get(getBindingAdapterPosition() - 1).postFilter); + }); + + binding.postFilterUsageRecyclerViewItemPostFilter.setRecycledViewPool(recycledViewPool); + binding.postFilterUsageRecyclerViewItemPostFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity)); + adapter = new PostFilterUsageEmbeddedRecyclerViewAdapter(activity); + binding.postFilterUsageRecyclerViewItemPostFilter.setAdapter(adapter); + } + } + + private class HeaderViewHolder extends RecyclerView.ViewHolder { + + public HeaderViewHolder(@NonNull View itemView) { + super(itemView); + TextView infoTextView = itemView.findViewById(R.id.info_text_view_item_filter_fragment_header); + infoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + infoTextView.setCompoundDrawablesWithIntrinsicBounds(Utils.getTintedDrawable(activity, R.drawable.ic_info_preference_24dp, activity.customThemeWrapper.getPrimaryIconColor()), null, null, null); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostFilterUsageEmbeddedRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostFilterUsageEmbeddedRecyclerViewAdapter.java new file mode 100644 index 00000000..51c3fc76 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostFilterUsageEmbeddedRecyclerViewAdapter.java @@ -0,0 +1,65 @@ +package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; + +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.databinding.ItemPostFilterUsageEmbeddedBinding; +import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage; + +public class PostFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter { + + private BaseActivity baseActivity; + private List postFilterUsageList; + + public PostFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) { + this.baseActivity = baseActivity; + } + + @NonNull + @Override + public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new EntryViewHolder(ItemPostFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) { + if (postFilterUsageList == null || postFilterUsageList.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, postFilterUsageList.size() - 5)); + } else { + holder.textView.setText(postFilterUsageList.get(holder.getBindingAdapterPosition()).nameOfUsage); + } + } + + @Override + public int getItemCount() { + return postFilterUsageList == null || postFilterUsageList.isEmpty() ? 1 : (postFilterUsageList.size() > 5 ? 6 : postFilterUsageList.size()); + } + + public void setPostFilterUsageList(List postFilterUsageList) { + this.postFilterUsageList = postFilterUsageList; + notifyDataSetChanged(); + } + + class EntryViewHolder extends RecyclerView.ViewHolder { + TextView textView; + + public EntryViewHolder(@NonNull ItemPostFilterUsageEmbeddedBinding binding) { + super(binding.getRoot()); + this.textView = binding.getRoot(); + textView.setOnClickListener(view -> { + Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show(); + }); + } + } +} diff --git a/app/src/main/res/layout/item_post_filter.xml b/app/src/main/res/layout/item_post_filter.xml deleted file mode 100644 index 8487e105..00000000 --- a/app/src/main/res/layout/item_post_filter.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_filter_usage_embedded.xml b/app/src/main/res/layout/item_post_filter_usage_embedded.xml new file mode 100644 index 00000000..bfec3dbb --- /dev/null +++ b/app/src/main/res/layout/item_post_filter_usage_embedded.xml @@ -0,0 +1,8 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_filter_with_usage.xml b/app/src/main/res/layout/item_post_filter_with_usage.xml new file mode 100644 index 00000000..8a083caa --- /dev/null +++ b/app/src/main/res/layout/item_post_filter_with_usage.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ 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 c6e755e8..44534471 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1372,4 +1372,7 @@ Otherwise, Infinity may not load posts at all. Sorry for the inconvenience. I understand + Click here to apply it to some post feeds + and %1$d more + -- cgit v1.2.3