aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java)25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostFilterUsageEmbeddedRecyclerViewAdapter.java65
-rw-r--r--app/src/main/res/layout/item_post_filter_usage_embedded.xml8
-rw-r--r--app/src/main/res/layout/item_post_filter_with_usage.xml (renamed from app/src/main/res/layout/item_post_filter.xml)11
-rw-r--r--app/src/main/res/values/strings.xml3
6 files changed, 104 insertions, 15 deletions
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/PostFilterWithUsageRecyclerViewAdapter.java
index f15c269c..73194143 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterWithUsageRecyclerViewAdapter.java
@@ -12,13 +12,15 @@ 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.databinding.ItemPostFilterBinding;
+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 PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_HEADER = 1;
private static final int VIEW_TYPE_POST_FILTER = 2;
@@ -27,15 +29,17 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private CustomThemeWrapper customThemeWrapper;
private final OnItemClickListener onItemClickListener;
private List<PostFilterWithUsage> postFilterWithUsageList;
+ private RecyclerView.RecycledViewPool recycledViewPool;
public interface OnItemClickListener {
void onItemClick(PostFilter postFilter);
}
- public PostFilterRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
- OnItemClickListener onItemClickListener) {
+ public PostFilterWithUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
+ OnItemClickListener onItemClickListener) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
+ this.recycledViewPool = new RecyclerView.RecycledViewPool();
this.onItemClickListener = onItemClickListener;
}
@@ -53,7 +57,7 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
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));
+ return new PostFilterViewHolder(ItemPostFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
}
@@ -61,6 +65,7 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
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);
}
}
@@ -75,9 +80,10 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
private class PostFilterViewHolder extends RecyclerView.ViewHolder {
- ItemPostFilterBinding binding;
+ ItemPostFilterWithUsageBinding binding;
+ PostFilterUsageEmbeddedRecyclerViewAdapter adapter;
- public PostFilterViewHolder(@NonNull ItemPostFilterBinding binding) {
+ public PostFilterViewHolder(@NonNull ItemPostFilterWithUsageBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.postFilterNameTextViewItemPostFilter.setTextColor(customThemeWrapper.getPrimaryTextColor());
@@ -89,6 +95,11 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
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);
}
}
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<PostFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> {
+
+ private BaseActivity baseActivity;
+ private List<PostFilterUsage> 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<PostFilterUsage> 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_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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" /> \ No newline at end of file
diff --git a/app/src/main/res/layout/item_post_filter.xml b/app/src/main/res/layout/item_post_filter_with_usage.xml
index 8487e105..8a083caa 100644
--- a/app/src/main/res/layout/item_post_filter.xml
+++ b/app/src/main/res/layout/item_post_filter_with_usage.xml
@@ -25,10 +25,13 @@
android:paddingEnd="16dp"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
- android:fontFamily="?attr/font_family"
- android:clickable="true"
- android:focusable="true"
- android:background="?attr/selectableItemBackground" />
+ android:fontFamily="?attr/font_family" />
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/post_filter_usage_recycler_view_item_post_filter"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:nestedScrollingEnabled="false" />
</LinearLayout>
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.</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>
+
</resources>