From 7777a6d6756b6b2631ea24548bd69ff42bd39034 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:06:58 -0500 Subject: Start CustomizePostFilterActivity instead of FilteredPostsActivity when pressing the filter posts option. --- .../activities/CustomizePostFilterActivity.java | 27 ++++- .../activities/FilteredPostsActivity.java | 124 +++++++++++---------- .../adapters/PostDetailRecyclerViewAdapter.java | 4 +- .../infinityforreddit/fragments/PostFragment.java | 44 ++++---- 4 files changed, 112 insertions(+), 87 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java index 0480887a..1e173b5f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -63,6 +63,7 @@ public class CustomizePostFilterActivity extends BaseActivity { public static final String EXTRA_CONTAIN_FLAIR = "ECF"; public static final String EXTRA_EXCLUDE_DOMAIN = "EED"; public static final String EXTRA_CONTAIN_DOMAIN = "ECD"; + public static final String EXTRA_START_FILTERED_POSTS_WHEN_FINISH = "ESFPWF"; public static final String RETURN_EXTRA_POST_FILTER = "REPF"; private static final String POST_FILTER_STATE = "PFS"; private static final String ORIGINAL_NAME_STATE = "ONS"; @@ -399,9 +400,16 @@ public class CustomizePostFilterActivity extends BaseActivity { } else if (item.getItemId() == R.id.action_save_customize_post_filter_activity) { try { constructPostFilter(); - Intent returnIntent = new Intent(); - returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter); - setResult(Activity.RESULT_OK, returnIntent); + if (getIntent().getBooleanExtra(EXTRA_START_FILTERED_POSTS_WHEN_FINISH, false)) { + Intent intent = new Intent(this, FilteredPostsActivity.class); + intent.putExtras(getIntent()); + intent.putExtra(FilteredPostsActivity.EXTRA_CONSTRUCTED_POST_FILTER, postFilter); + startActivity(intent); + } else { + Intent returnIntent = new Intent(); + returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter); + setResult(Activity.RESULT_OK, returnIntent); + } finish(); } catch (PatternSyntaxException e) { Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show(); @@ -429,9 +437,16 @@ public class CustomizePostFilterActivity extends BaseActivity { new SavePostFilter.SavePostFilterListener() { @Override public void success() { - Intent returnIntent = new Intent(); - returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter); - setResult(Activity.RESULT_OK, returnIntent); + if (getIntent().getBooleanExtra(EXTRA_START_FILTERED_POSTS_WHEN_FINISH, false)) { + Intent intent = new Intent(CustomizePostFilterActivity.this, FilteredPostsActivity.class); + intent.putExtras(getIntent()); + intent.putExtra(FilteredPostsActivity.EXTRA_CONSTRUCTED_POST_FILTER, postFilter); + startActivity(intent); + } else { + Intent returnIntent = new Intent(); + returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter); + setResult(Activity.RESULT_OK, returnIntent); + } finish(); } 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 8780f4b6..4a28efcb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -65,7 +65,8 @@ 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_TRENDING_SOURCE = "ETS"; - public static final String EXTRA_FILTER = "EF"; + public static final String EXTRA_POST_TYPE_FILTER = "EPTF"; + public static final String EXTRA_CONSTRUCTED_POST_FILTER = "ECPF"; public static final String EXTRA_CONTAIN_FLAIR = "ECF"; public static final String EXTRA_POST_TYPE = "EPT"; public static final String EXTRA_USER_WHERE = "EUW"; @@ -162,66 +163,69 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec name = getIntent().getStringExtra(EXTRA_NAME); postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE); - int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000); - PostFilter postFilter = new PostFilter(); - postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false); - switch (filter) { - case Post.NSFW_TYPE: - postFilter.onlyNSFW = true; - break; - case Post.TEXT_TYPE: - postFilter.containTextType = true; - postFilter.containLinkType = false; - postFilter.containImageType = false; - postFilter.containGifType = false; - postFilter.containVideoType = false; - postFilter.containGalleryType = false; - break; - case Post.LINK_TYPE: - postFilter.containTextType = false; - postFilter.containLinkType = true; - postFilter.containImageType = false; - postFilter.containGifType = false; - postFilter.containVideoType = false; - postFilter.containGalleryType = false; - break; - case Post.IMAGE_TYPE: - postFilter.containTextType = false; - postFilter.containLinkType = false; - postFilter.containImageType = true; - postFilter.containGifType = false; - postFilter.containVideoType = false; - postFilter.containGalleryType = false; - break; - case Post.GIF_TYPE: - postFilter.containTextType = false; - postFilter.containLinkType = false; - postFilter.containImageType = false; - postFilter.containGifType = true; - postFilter.containVideoType = false; - postFilter.containGalleryType = false; - break; - case Post.VIDEO_TYPE: - postFilter.containTextType = false; - postFilter.containLinkType = false; - postFilter.containImageType = false; - postFilter.containGifType = false; - postFilter.containVideoType = true; - postFilter.containGalleryType = false; - break; - case Post.GALLERY_TYPE: - postFilter.containTextType = false; - postFilter.containLinkType = false; - postFilter.containImageType = false; - postFilter.containGifType = false; - postFilter.containVideoType = false; - postFilter.containGalleryType = true; - break; - } + int filter = getIntent().getIntExtra(EXTRA_POST_TYPE_FILTER, -1000); + PostFilter postFilter = getIntent().getParcelableExtra(EXTRA_CONSTRUCTED_POST_FILTER); + if (postFilter == null) { + postFilter = new PostFilter(); + postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false); + switch (filter) { + case Post.NSFW_TYPE: + postFilter.onlyNSFW = true; + break; + case Post.TEXT_TYPE: + postFilter.containTextType = true; + postFilter.containLinkType = false; + postFilter.containImageType = false; + postFilter.containGifType = false; + postFilter.containVideoType = false; + postFilter.containGalleryType = false; + break; + case Post.LINK_TYPE: + postFilter.containTextType = false; + postFilter.containLinkType = true; + postFilter.containImageType = false; + postFilter.containGifType = false; + postFilter.containVideoType = false; + postFilter.containGalleryType = false; + break; + case Post.IMAGE_TYPE: + postFilter.containTextType = false; + postFilter.containLinkType = false; + postFilter.containImageType = true; + postFilter.containGifType = false; + postFilter.containVideoType = false; + postFilter.containGalleryType = false; + break; + case Post.GIF_TYPE: + postFilter.containTextType = false; + postFilter.containLinkType = false; + postFilter.containImageType = false; + postFilter.containGifType = true; + postFilter.containVideoType = false; + postFilter.containGalleryType = false; + break; + case Post.VIDEO_TYPE: + postFilter.containTextType = false; + postFilter.containLinkType = false; + postFilter.containImageType = false; + postFilter.containGifType = false; + postFilter.containVideoType = true; + postFilter.containGalleryType = false; + break; + case Post.GALLERY_TYPE: + postFilter.containTextType = false; + postFilter.containLinkType = false; + postFilter.containImageType = false; + postFilter.containGifType = false; + postFilter.containVideoType = false; + postFilter.containGalleryType = true; + break; + } - String flair = getIntent().getStringExtra(EXTRA_CONTAIN_FLAIR); - if (flair != null) { - postFilter.containFlairs = flair; + String flair = getIntent().getStringExtra(EXTRA_CONTAIN_FLAIR); + if (flair != null) { + postFilter.containFlairs = flair; + } } if (postType == PostPagingSource.TYPE_USER) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index d2d3d002..150ce763 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -1190,7 +1190,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter