Click a flair to see filtered posts. Fix filtering posts that contain certain flairs.

This commit is contained in:
Alex Ning 2021-04-06 14:30:33 +08:00
parent e4c9f7b927
commit 68d8aaf61d
5 changed files with 106 additions and 8 deletions

View File

@ -63,6 +63,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ"; public static final String EXTRA_QUERY = "EQ";
public static final String EXTRA_FILTER = "EF"; 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_POST_TYPE = "EPT";
public static final String EXTRA_USER_WHERE = "EUW"; public static final String EXTRA_USER_WHERE = "EUW";
@ -213,6 +214,11 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
break; break;
} }
String flair = getIntent().getStringExtra(EXTRA_CONTAIN_FLAIR);
if (flair != null) {
postFilter.containFlairs = flair;
}
if (postType == PostDataSource.TYPE_USER) { if (postType == PostDataSource.TYPE_USER) {
userWhere = getIntent().getStringExtra(EXTRA_USER_WHERE); userWhere = getIntent().getStringExtra(EXTRA_USER_WHERE);
if (userWhere != null && !PostDataSource.USER_WHERE_SUBMITTED.equals(userWhere) && mMenu != null) { 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) { private void bindView(PostFilter postFilter, boolean initializeFragment) {
switch (postType) { switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE: case PostDataSource.TYPE_FRONT_PAGE:
getSupportActionBar().setTitle(name); getSupportActionBar().setTitle(R.string.home);
break; break;
case PostDataSource.TYPE_SEARCH: case PostDataSource.TYPE_SEARCH:
getSupportActionBar().setTitle(R.string.search); getSupportActionBar().setTitle(R.string.search);

View File

@ -2182,6 +2182,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mActivity.startActivity(intent); 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 -> { mNSFWTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class); Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));

View File

@ -2014,6 +2014,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
void typeChipClicked(int filter); void typeChipClicked(int filter);
void flairChipClicked(String flair);
void nsfwChipClicked(); void nsfwChipClicked();
void currentlyBindItem(int position); void currentlyBindItem(int position);
@ -2304,6 +2306,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mCallback.typeChipClicked(post.getPostType()); 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 -> { 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 -> { imageView.setOnClickListener(view -> {
int position = getBindingAdapterPosition(); int position = getBindingAdapterPosition();
if (position < 0) { if (position < 0) {

View File

@ -457,6 +457,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
startActivity(intent); startActivity(intent);
} }
@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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); Intent intent = new Intent(activity, FilteredPostsActivity.class);
@ -525,6 +535,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
startActivity(intent); startActivity(intent);
} }
@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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); Intent intent = new Intent(activity, FilteredPostsActivity.class);
@ -592,6 +611,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
startActivity(intent); startActivity(intent);
} }
@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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); Intent intent = new Intent(activity, FilteredPostsActivity.class);
@ -660,6 +688,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
startActivity(intent); startActivity(intent);
} }
@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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); Intent intent = new Intent(activity, FilteredPostsActivity.class);
@ -709,16 +747,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void typeChipClicked(int filter) { public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredPostsActivity.class); 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_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent); 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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); 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_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent); startActivity(intent);
@ -762,16 +806,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void typeChipClicked(int filter) { public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredPostsActivity.class); 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_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent); 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 @Override
public void nsfwChipClicked() { public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class); 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_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent); startActivity(intent);

View File

@ -213,10 +213,20 @@ public class PostFilter implements Parcelable {
} }
if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) { if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) {
String[] flairs = postFilter.containFlairs.split(",", 0); String[] flairs = postFilter.containFlairs.split(",", 0);
for (String f : flairs) { if (flairs.length > 0) {
if (!f.trim().equals("") && post.getFlair().equalsIgnoreCase(f.trim())) { 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; return false;
} }
if (!flair.equals("") && post.getFlair().equalsIgnoreCase(flair)) {
match = true;
break;
}
}
return match;
} }
} }