From 3eb608888b0d5563d9c111e25037bef218496300 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 21 Jul 2021 21:29:06 +0800 Subject: Add to post filter menu option available in ViewSubredditActivity and ViewUserActivity. --- .../activities/PostFilterPreferenceActivity.java | 42 ++++++++++++++++++---- .../activities/ViewSubredditDetailActivity.java | 5 +++ .../activities/ViewUserDetailActivity.java | 5 +++ 3 files changed, 46 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/ml') 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 e64bf21e..4ed7534d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -36,6 +36,8 @@ import ml.docilealligator.infinityforreddit.postfilter.PostFilterViewModel; public class PostFilterPreferenceActivity extends BaseActivity { public static final String EXTRA_POST = "EP"; + public static final String EXTRA_SUBREDDIT_NAME = "ESN"; + public static final String EXTRA_USER_NAME = "EUN"; @BindView(R.id.coordinator_layout_post_filter_preference_activity) CoordinatorLayout coordinatorLayout; @@ -76,26 +78,36 @@ public class PostFilterPreferenceActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); Post post = getIntent().getParcelableExtra(EXTRA_POST); + String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); + String username = getIntent().getStringExtra(EXTRA_USER_NAME); fab.setOnClickListener(view -> { - if (post == null) { + if (post != null) { + showPostFilterOptions(post, null); + } else if (subredditName != null) { + excludeSubredditInFilter(subredditName, null); + } else if (username != null) { + excludeUserInFilter(username, null); + } else { Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class); intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true); startActivity(intent); - } else { - showPostFilterOptions(post, null); } }); adapter = new PostFilterRecyclerViewAdapter(postFilter -> { - if (post == null) { + if (post != null) { + showPostFilterOptions(post, postFilter); + } else if (subredditName != null) { + excludeSubredditInFilter(subredditName, postFilter); + } else if (username != null) { + excludeUserInFilter(username, postFilter); + } else { PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter); postFilterOptionsBottomSheetFragment.setArguments(bundle); postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag()); - } else { - showPostFilterOptions(post, postFilter); } }); @@ -145,6 +157,24 @@ public class PostFilterPreferenceActivity extends BaseActivity { .show(); } + public void excludeSubredditInFilter(String subredditName, PostFilter postFilter) { + Intent intent = new Intent(this, CustomizePostFilterActivity.class); + intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_SUBREDDIT, subredditName); + if (postFilter != null) { + intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter); + } + startActivity(intent); + } + + public void excludeUserInFilter(String username, PostFilter postFilter) { + Intent intent = new Intent(this, CustomizePostFilterActivity.class); + intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_USER, username); + if (postFilter != null) { + intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter); + } + startActivity(intent); + } + public void editPostFilter(PostFilter postFilter) { Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class); intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 8486318d..3926062d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1114,6 +1114,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } Intent intent = new Intent(this, MultiredditSelectionActivity.class); startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE); + } else if (itemId == R.id.action_add_to_post_filter_view_subreddit_detail_activity) { + Intent intent = new Intent(this, PostFilterPreferenceActivity.class); + intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, subredditName); + startActivity(intent); + return true; } else if (itemId == R.id.action_share_view_subreddit_detail_activity) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 5432c074..da2216e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -981,6 +981,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } Intent intent = new Intent(this, MultiredditSelectionActivity.class); startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE); + } else if (itemId == R.id.action_add_to_post_filter_view_user_detail_activity) { + Intent intent = new Intent(this, PostFilterPreferenceActivity.class); + intent.putExtra(PostFilterPreferenceActivity.EXTRA_USER_NAME, username); + startActivity(intent); + return true; } else if (itemId == R.id.action_report_view_user_detail_activity) { Intent reportIntent = new Intent(this, LinkResolverActivity.class); reportIntent.setData(Uri.parse("https://www.reddithelp.com/en/categories/rules-reporting/account-and-community-restrictions/what-should-i-do-if-i-see-something-i")); -- cgit v1.2.3