New option in FAB: Filter Posts. Add Gif option in PostFilter.

This commit is contained in:
Alex Ning 2020-12-22 23:56:20 +08:00
parent 71a7852c79
commit efa960013a
15 changed files with 224 additions and 25 deletions

View File

@ -41,4 +41,8 @@ public interface FragmentCommunicator {
default void changePostFilter(PostFilter postFilter) {
}
default void filterPosts() {
};
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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));
}
}
}

View File

@ -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();
}
}
}
}

View File

@ -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;

View File

@ -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() {

View File

@ -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;
}

View File

@ -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();

View File

@ -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);

View File

@ -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";

View File

@ -133,6 +133,36 @@
</LinearLayout>
<LinearLayout
android:id="@+id/post_type_gif_linear_layout_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="32dp"
android:paddingEnd="8dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/post_type_gif_text_view_customize_post_filter_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="@string/post_type_gif"
android:fontFamily="?attr/font_default"
android:textSize="?attr/font_default" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/post_type_gif_check_box_customize_post_filter_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:id="@+id/post_type_video_linear_layout_customize_post_filter_activity"
android:layout_width="match_parent"

View File

@ -26,6 +26,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:subtitle="@string/filtered_posts_activity_subtitle"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />

View File

@ -182,6 +182,25 @@
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/filter_posts_text_view_fab_more_options_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/filter_posts"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
app:drawableStartCompat="@drawable/ic_filter_24dp"
android:drawablePadding="48dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -35,6 +35,7 @@
<string name="give_award_activity_label">Give Award</string>
<string name="subreddit_filter_popular_and_all_activity_label">r/all and r/popular</string>
<string name="customize_post_filter_activity_label">Post Filter</string>
<string name="filtered_posts_activity_subtitle">Filtered Posts</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@ -199,6 +200,7 @@
<string name="bottom_sheet_post_link">Link</string>
<string name="bottom_sheet_post_image">Image</string>
<string name="bottom_sheet_post_video">Video</string>
<string name="post_type_gif">Gif</string>
<string name="post_type_gallery">Gallery</string>
<string name="select_from_gallery">Select a picture</string>
@ -952,6 +954,7 @@
<string name="select_video_quality">Select Video Quality</string>
<string name="hide_read_posts">Hide Read Posts</string>
<string name="filter_posts">Filter Posts</string>
<string name="only_nsfw">Only NSFW</string>
<string name="only_spoiler">Only Spoiler</string>