Add to post filter menu option available in ViewSubredditActivity and ViewUserActivity.

This commit is contained in:
Alex Ning 2021-07-21 21:29:06 +08:00
parent eaa24b4858
commit 3eb608888b
5 changed files with 61 additions and 9 deletions

View File

@ -36,6 +36,8 @@ import ml.docilealligator.infinityforreddit.postfilter.PostFilterViewModel;
public class PostFilterPreferenceActivity extends BaseActivity { public class PostFilterPreferenceActivity extends BaseActivity {
public static final String EXTRA_POST = "EP"; 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) @BindView(R.id.coordinator_layout_post_filter_preference_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -76,26 +78,36 @@ public class PostFilterPreferenceActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Post post = getIntent().getParcelableExtra(EXTRA_POST); Post post = getIntent().getParcelableExtra(EXTRA_POST);
String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
String username = getIntent().getStringExtra(EXTRA_USER_NAME);
fab.setOnClickListener(view -> { 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 intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true); intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent); startActivity(intent);
} else {
showPostFilterOptions(post, null);
} }
}); });
adapter = new PostFilterRecyclerViewAdapter(postFilter -> { 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(); PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter); bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter);
postFilterOptionsBottomSheetFragment.setArguments(bundle); postFilterOptionsBottomSheetFragment.setArguments(bundle);
postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag()); postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag());
} else {
showPostFilterOptions(post, postFilter);
} }
}); });
@ -145,6 +157,24 @@ public class PostFilterPreferenceActivity extends BaseActivity {
.show(); .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) { public void editPostFilter(PostFilter postFilter) {
Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class); Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter); intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);

View File

@ -1114,6 +1114,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
Intent intent = new Intent(this, MultiredditSelectionActivity.class); Intent intent = new Intent(this, MultiredditSelectionActivity.class);
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE); 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) { } else if (itemId == R.id.action_share_view_subreddit_detail_activity) {
Intent shareIntent = new Intent(Intent.ACTION_SEND); Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain"); shareIntent.setType("text/plain");

View File

@ -981,6 +981,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
} }
Intent intent = new Intent(this, MultiredditSelectionActivity.class); Intent intent = new Intent(this, MultiredditSelectionActivity.class);
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE); 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) { } else if (itemId == R.id.action_report_view_user_detail_activity) {
Intent reportIntent = new Intent(this, LinkResolverActivity.class); 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")); 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"));

View File

@ -48,8 +48,14 @@
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_share_view_subreddit_detail_activity" android:id="@+id/action_add_to_post_filter_view_subreddit_detail_activity"
android:orderInCategory="8" android:orderInCategory="8"
android:title="@string/action_add_to_post_filter"
app:showAsAction="never" />
<item
android:id="@+id/action_share_view_subreddit_detail_activity"
android:orderInCategory="9"
android:title="@string/action_share" android:title="@string/action_share"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -51,12 +51,18 @@
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_report_view_user_detail_activity" android:id="@+id/action_add_to_post_filter_view_user_detail_activity"
android:orderInCategory="9" android:orderInCategory="9"
android:title="@string/action_add_to_post_filter"
app:showAsAction="never" />
<item
android:id="@+id/action_report_view_user_detail_activity"
android:orderInCategory="10"
android:title="@string/action_report" /> android:title="@string/action_report" />
<item <item
android:id="@+id/action_block_user_view_user_detail_activity" android:id="@+id/action_block_user_view_user_detail_activity"
android:orderInCategory="10" android:orderInCategory="11"
android:title="@string/action_block_user" /> android:title="@string/action_block_user" />
</menu> </menu>