diff options
Diffstat (limited to 'app/src/main/java')
11 files changed, 171 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java index 29675703..7c7f450c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java @@ -41,4 +41,8 @@ public interface FragmentCommunicator { default void changePostFilter(PostFilter postFilter) { } + + default void filterPosts() { + + }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java index d6842991..4b06c261 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java @@ -28,6 +28,7 @@ public class PostFilter implements Parcelable { public boolean containsTextType = true; public boolean containsLinkType = true; public boolean containsImageType = true; + public boolean containsGifType = true; public boolean containsVideoType = true; public boolean containsGalleryType = true; @@ -72,6 +73,9 @@ public class PostFilter implements Parcelable { if (!postFilter.containsImageType && post.getPostType() == Post.IMAGE_TYPE) { return false; } + if (!postFilter.containsGifType && post.getPostType() == Post.GIF_TYPE) { + return false; + } if (!postFilter.containsVideoType && post.getPostType() == Post.VIDEO_TYPE) { return false; } 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 0f3b2b38..8fef2ae8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -65,6 +65,12 @@ public class CustomizePostFilterActivity extends BaseActivity { TextView postTypeImageTextView; @BindView(R.id.post_type_image_check_box_customize_post_filter_activity) MaterialCheckBox postTypeImageCheckBox; + @BindView(R.id.post_type_gif_linear_layout_customize_post_filter_activity) + LinearLayout postTypeGifLinearLayout; + @BindView(R.id.post_type_gif_text_view_customize_post_filter_activity) + TextView postTypeGifTextView; + @BindView(R.id.post_type_gif_check_box_customize_post_filter_activity) + MaterialCheckBox postTypeGifCheckBox; @BindView(R.id.post_type_video_linear_layout_customize_post_filter_activity) LinearLayout postTypeVideoLinearLayout; @BindView(R.id.post_type_video_text_view_customize_post_filter_activity) @@ -182,6 +188,10 @@ public class CustomizePostFilterActivity extends BaseActivity { postTypeImageCheckBox.performClick(); }); + postTypeGifLinearLayout.setOnClickListener(view -> { + postTypeGifCheckBox.performClick(); + }); + postTypeVideoLinearLayout.setOnClickListener(view -> { postTypeVideoCheckBox.performClick(); }); @@ -217,6 +227,7 @@ public class CustomizePostFilterActivity extends BaseActivity { postTypeTextTextView.setTextColor(primaryTextColor); postTypeLinkTextView.setTextColor(primaryTextColor); postTypeImageTextView.setTextColor(primaryTextColor); + postTypeGifTextView.setTextColor(primaryTextColor); postTypeVideoTextView.setTextColor(primaryTextColor); postTypeGalleryTextView.setTextColor(primaryTextColor); onlyNSFWTextView.setTextColor(primaryTextColor); @@ -288,6 +299,7 @@ public class CustomizePostFilterActivity extends BaseActivity { postFilter.containsTextType = postTypeTextCheckBox.isChecked(); postFilter.containsLinkType = postTypeLinkCheckBox.isChecked(); postFilter.containsImageType = postTypeImageCheckBox.isChecked(); + postFilter.containsGifType = postTypeGifCheckBox.isChecked(); postFilter.containsVideoType = postTypeVideoCheckBox.isChecked(); postFilter.containsGalleryType = postTypeGalleryCheckBox.isChecked(); postFilter.onlyNSFW = onlyNSFWSwitch.isChecked(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java index 633683f3..bd855e40 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java @@ -161,47 +161,58 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec name = getIntent().getStringExtra(EXTRA_NAME); postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE); - int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE); - switch (filter) { - case Post.NSFW_TYPE: - toolbar.setSubtitle(R.string.nsfw); - break; - case Post.TEXT_TYPE: - toolbar.setSubtitle(R.string.text); - break; - case Post.LINK_TYPE: - case Post.NO_PREVIEW_LINK_TYPE: - toolbar.setSubtitle(R.string.link); - break; - case Post.IMAGE_TYPE: - toolbar.setSubtitle(R.string.image); - break; - case Post.VIDEO_TYPE: - toolbar.setSubtitle(R.string.video); - break; - case Post.GIF_TYPE: - toolbar.setSubtitle(R.string.gif); - break; - case Post.GALLERY_TYPE: - toolbar.setSubtitle(R.string.gallery); - } + int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000); PostFilter postFilter = new PostFilter(); switch (filter) { case Post.NSFW_TYPE: postFilter.onlyNSFW = true; + break; case Post.TEXT_TYPE: postFilter.containsTextType = true; + postFilter.containsLinkType = false; + postFilter.containsImageType = false; + postFilter.containsGifType = false; + postFilter.containsVideoType = false; + postFilter.containsGalleryType = false; break; case Post.LINK_TYPE: + postFilter.containsTextType = false; postFilter.containsLinkType = true; + postFilter.containsImageType = false; + postFilter.containsGifType = false; + postFilter.containsVideoType = false; + postFilter.containsGalleryType = false; break; case Post.IMAGE_TYPE: + postFilter.containsTextType = false; + postFilter.containsLinkType = false; postFilter.containsImageType = true; + postFilter.containsGifType = false; + postFilter.containsVideoType = false; + postFilter.containsGalleryType = false; + break; + case Post.GIF_TYPE: + postFilter.containsTextType = false; + postFilter.containsLinkType = false; + postFilter.containsImageType = false; + postFilter.containsGifType = true; + postFilter.containsVideoType = false; + postFilter.containsGalleryType = false; break; case Post.VIDEO_TYPE: + postFilter.containsTextType = false; + postFilter.containsLinkType = false; + postFilter.containsImageType = false; + postFilter.containsGifType = false; postFilter.containsVideoType = true; + postFilter.containsGalleryType = false; break; case Post.GALLERY_TYPE: + postFilter.containsTextType = false; + postFilter.containsLinkType = false; + postFilter.containsImageType = false; + postFilter.containsGifType = false; + postFilter.containsVideoType = false; postFilter.containsGalleryType = true; break; } @@ -453,7 +464,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec super.onActivityResult(requestCode, resultCode, data); if (requestCode == CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) { if (mFragment != null) { - ((PostFragment) mFragment).changePostFilter(data.getParcelableExtra(CustomizePostFilterActivity.RETURN_EXTRA_POST_FILTER)); + mFragment.changePostFilter(data.getParcelableExtra(CustomizePostFilterActivity.RETURN_EXTRA_POST_FILTER)); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 15de5a52..2d139293 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -594,6 +594,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: fab.setImageResource(R.drawable.ic_hide_read_posts_24dp); break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + fab.setImageResource(R.drawable.ic_filter_24dp); + break; default: fab.setImageResource(R.drawable.ic_add_day_night_24dp); break; @@ -633,6 +636,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb sectionsPagerAdapter.hideReadPosts(); } break; + case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; default: postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); break; @@ -1213,6 +1221,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } break; } + case FABMoreOptionsBottomSheetFragment.FAB_FILTER_POSTS: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; + } } } @@ -1536,5 +1550,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb currentFragment.hideReadPosts(); } } + + void filterPosts() { + PostFragment currentFragment = getCurrentFragment(); + if (currentFragment != null) { + currentFragment.filterPosts(); + } + } } } 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 70cea4fb..1771b8dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -713,6 +713,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: fab.setImageResource(R.drawable.ic_hide_read_posts_24dp); break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + fab.setImageResource(R.drawable.ic_filter_24dp); + break; default: fab.setImageResource(R.drawable.ic_add_day_night_24dp); break; @@ -753,6 +756,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp sectionsPagerAdapter.hideReadPosts(); } break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; default: postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); break; @@ -1136,6 +1144,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp if (sectionsPagerAdapter != null) { sectionsPagerAdapter.hideReadPosts(); } + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_FILTER_POSTS: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; } } } @@ -1334,6 +1349,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } } + void filterPosts() { + if (fragmentManager != null) { + Fragment fragment = fragmentManager.findFragmentByTag("f0"); + if (fragment instanceof PostFragment) { + ((PostFragment) fragment).filterPosts(); + } + } + } + @Override public int getItemCount() { return 2; 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 c871f8e7..3ddf99f5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -736,6 +736,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: fab.setImageResource(R.drawable.ic_hide_read_posts_24dp); break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + fab.setImageResource(R.drawable.ic_filter_24dp); + break; default: fab.setImageResource(R.drawable.ic_add_day_night_24dp); break; @@ -775,6 +778,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele sectionsPagerAdapter.hideReadPosts(); } break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; default: PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); @@ -1108,6 +1116,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele if (sectionsPagerAdapter != null) { sectionsPagerAdapter.hideReadPosts(); } + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_FILTER_POSTS: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; } } } @@ -1445,6 +1460,15 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } } + + void filterPosts() { + if (fragmentManager != null) { + Fragment fragment = fragmentManager.findFragmentByTag("f0"); + if (fragment instanceof PostFragment) { + ((PostFragment) fragment).filterPosts(); + } + } + } } private void lockSwipeRightToGoBack() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java index a7311736..3dccf361 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java @@ -26,6 +26,7 @@ public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogF public static final int FAB_OPTION_GO_TO_USER = 6; public static final int FAB_RANDOM = 7; public static final int FAB_HIDE_READ_POSTS = 8; + public static final int FAB_FILTER_POSTS = 9; @BindView(R.id.submit_post_text_view_fab_more_options_bottom_sheet_fragment) TextView submitPostTextView; @@ -45,6 +46,8 @@ public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogF TextView randomTextView; @BindView(R.id.hide_read_posts_text_view_fab_more_options_bottom_sheet_fragment) TextView hideReadPostsTextView; + @BindView(R.id.filter_posts_text_view_fab_more_options_bottom_sheet_fragment) + TextView filterPostsTextView; private FABOptionSelectionCallback activity; public FABMoreOptionsBottomSheetFragment() { @@ -104,6 +107,11 @@ public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogF dismiss(); }); + filterPostsTextView.setOnClickListener(view -> { + activity.fabOptionSelected(FAB_FILTER_POSTS); + dismiss(); + }); + return rootView; } 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 0757b5da..6edeb8e8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -1257,6 +1257,38 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Override + public void filterPosts() { + if (postType == PostDataSource.TYPE_SEARCH) { + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + startActivity(intent); + } else if (postType == PostDataSource.TYPE_SUBREDDIT) { + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + startActivity(intent); + } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) { + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditPath); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + startActivity(intent); + } else if (postType == PostDataSource.TYPE_USER) { + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, username); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where); + startActivity(intent); + } else { + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + startActivity(intent); + } + } + @Subscribe public void onPostUpdateEvent(PostUpdateEventToPostList event) { PagedList<Post> posts = mAdapter.getCurrentList(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 96b0ef7b..b55c9277 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.post; import android.net.Uri; import android.os.AsyncTask; import android.text.Html; +import android.util.Log; import org.json.JSONArray; import org.json.JSONException; @@ -247,6 +248,9 @@ public class ParsePost { //Video post JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY); int postType = Post.VIDEO_TYPE; + if (!redditVideoObject.has(JSONUtils.HLS_URL_KEY)) { + Log.i("afasd", "s " + redditVideoObject); + } String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString(); String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 7f5389b6..5751af30 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -196,6 +196,7 @@ public class SharedPreferencesUtils { public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER = 6; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM = 7; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS = 8; + public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS = 9; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME = 0; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 1; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX = 2; @@ -210,6 +211,7 @@ public class SharedPreferencesUtils { public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER = 6; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM = 7; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS = 8; + public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS = 9; public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; public static final String NSFW_BASE = "_nsfw"; |