diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-06 06:30:33 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-06 06:30:33 +0000 |
commit | 68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86 (patch) | |
tree | 3782c09da7b3b510cdc971aa0af974f09ecdb6f3 /app/src | |
parent | e4c9f7b927476c5498950516f2c1768047d56970 (diff) | |
download | infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar.gz infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar.bz2 infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar.lz infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar.xz infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.tar.zst infinity-for-reddit-68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86.zip |
Click a flair to see filtered posts. Fix filtering posts that contain certain flairs.
Diffstat (limited to '')
5 files changed, 106 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 73217aad..e14e8499 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -63,6 +63,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_QUERY = "EQ"; public static final String EXTRA_FILTER = "EF"; + public static final String EXTRA_CONTAIN_FLAIR = "ECF"; public static final String EXTRA_POST_TYPE = "EPT"; public static final String EXTRA_USER_WHERE = "EUW"; @@ -213,6 +214,11 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec break; } + String flair = getIntent().getStringExtra(EXTRA_CONTAIN_FLAIR); + if (flair != null) { + postFilter.containFlairs = flair; + } + if (postType == PostDataSource.TYPE_USER) { userWhere = getIntent().getStringExtra(EXTRA_USER_WHERE); if (userWhere != null && !PostDataSource.USER_WHERE_SUBMITTED.equals(userWhere) && mMenu != null) { @@ -262,7 +268,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec private void bindView(PostFilter postFilter, boolean initializeFragment) { switch (postType) { case PostDataSource.TYPE_FRONT_PAGE: - getSupportActionBar().setTitle(name); + getSupportActionBar().setTitle(R.string.home); break; case PostDataSource.TYPE_SEARCH: getSupportActionBar().setTitle(R.string.search); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 8b779730..13f9d07f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -2182,6 +2182,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mActivity.startActivity(intent); }); + mFlairTextView.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair()); + mActivity.startActivity(intent); + }); + mNSFWTextView.setOnClickListener(view -> { Intent intent = new Intent(mActivity, FilteredPostsActivity.class); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 99df68d9..5e64c959 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -2014,6 +2014,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView void typeChipClicked(int filter); + void flairChipClicked(String flair); + void nsfwChipClicked(); void currentlyBindItem(int position); @@ -2304,6 +2306,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mCallback.typeChipClicked(post.getPostType()); } }); + + flairTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.flairChipClicked(post.getFlair()); + } + }); } upvoteButton.setOnClickListener(view -> { @@ -3257,6 +3270,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } }); + flairTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null && !(mActivity instanceof FilteredPostsActivity)) { + mCallback.flairChipClicked(post.getFlair()); + } + }); + imageView.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position < 0) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 161643a5..2c3f28b8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -458,6 +458,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); @@ -526,6 +536,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); @@ -593,6 +612,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath); @@ -661,6 +689,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_USER_WHERE, where); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username); @@ -709,16 +747,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best)); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); startActivity(intent); } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best)); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE); startActivity(intent); @@ -762,16 +806,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best)); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); startActivity(intent); } @Override + public void flairChipClicked(String flair) { + Intent intent = new Intent(activity, FilteredPostsActivity.class); + intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair); + startActivity(intent); + } + + @Override public void nsfwChipClicked() { Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best)); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE); startActivity(intent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java index 87185b19..9cc0987f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java @@ -213,10 +213,20 @@ public class PostFilter implements Parcelable { } if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) { String[] flairs = postFilter.containFlairs.split(",", 0); - for (String f : flairs) { - if (!f.trim().equals("") && post.getFlair().equalsIgnoreCase(f.trim())) { - return false; + if (flairs.length > 0) { + boolean match = false; + for (int i = 0; i < flairs.length; i++) { + String flair = flairs[i].trim(); + if (flair.equals("") && i == flairs.length - 1) { + return false; + } + if (!flair.equals("") && post.getFlair().equalsIgnoreCase(flair)) { + match = true; + break; + } } + + return match; } } |