New option in data saving mode: Only disable preview in video and gif posts.

This commit is contained in:
Alex Ning 2021-01-07 15:36:23 +08:00
parent 5af4085409
commit 2f912a523e
8 changed files with 100 additions and 48 deletions

View File

@ -124,20 +124,21 @@ import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WR
public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements CacheManager { public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements CacheManager {
private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY = 1; private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY = 1;
private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW = 2; private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW = 2;
private static final int VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY = 3; private static final int VIEW_TYPE_POST_DETAIL_IMAGE = 3;
private static final int VIEW_TYPE_POST_DETAIL_LINK = 4; private static final int VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY = 4;
private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 5; private static final int VIEW_TYPE_POST_DETAIL_LINK = 5;
private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 6; private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6;
private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 7; private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7;
private static final int VIEW_TYPE_FIRST_LOADING = 8; private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8;
private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 9; private static final int VIEW_TYPE_FIRST_LOADING = 9;
private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 10; private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 10;
private static final int VIEW_TYPE_COMMENT = 11; private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 11;
private static final int VIEW_TYPE_COMMENT_FULLY_COLLAPSED = 12; private static final int VIEW_TYPE_COMMENT = 12;
private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 13; private static final int VIEW_TYPE_COMMENT_FULLY_COLLAPSED = 13;
private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 14; private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 14;
private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 15; private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 15;
private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 16; private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 16;
private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 17;
private AppCompatActivity mActivity; private AppCompatActivity mActivity;
private Retrofit mRetrofit; private Retrofit mRetrofit;
@ -178,6 +179,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mAutomaticallyTryRedgifs; private boolean mAutomaticallyTryRedgifs;
private boolean mDataSavingMode; private boolean mDataSavingMode;
private boolean mDisableImagePreview; private boolean mDisableImagePreview;
private boolean mOnlyDisablePreviewInVideoAndGifPosts;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading; private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed; private boolean isInitiallyLoadingFailed;
@ -513,6 +515,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR; mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
} }
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false); mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true; isInitiallyLoading = true;
@ -590,12 +593,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (!mAutoplayNsfwVideos && mPost.isNSFW()) { if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
} }
return VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY; return VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY;
} else { } else {
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW; return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
} }
case Post.IMAGE_TYPE: case Post.IMAGE_TYPE:
return VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY; return VIEW_TYPE_POST_DETAIL_IMAGE;
case Post.LINK_TYPE: case Post.LINK_TYPE:
return VIEW_TYPE_POST_DETAIL_LINK; return VIEW_TYPE_POST_DETAIL_LINK;
case Post.NO_PREVIEW_LINK_TYPE: case Post.NO_PREVIEW_LINK_TYPE:
@ -668,22 +671,27 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
switch (viewType) { switch (viewType) {
case VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY: case VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY:
if (mDataSavingMode) { if (mDataSavingMode) {
if (mDisableImagePreview) { if (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts) {
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false)); return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));
} }
return new PostDetailVideoAndGifPreviewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_and_gif_preview, parent, false)); return new PostDetailVideoAndGifPreviewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_and_gif_preview, parent, false));
} }
return new PostDetailVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_autoplay, parent, false)); return new PostDetailVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_autoplay, parent, false));
case VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW: case VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW:
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts)) {
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false)); return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));
} }
return new PostDetailVideoAndGifPreviewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_and_gif_preview, parent, false)); return new PostDetailVideoAndGifPreviewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_and_gif_preview, parent, false));
case VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY: case VIEW_TYPE_POST_DETAIL_IMAGE:
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false)); return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));
} }
return new PostDetailImageAndGifAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_image_and_gif_autoplay, parent, false)); return new PostDetailImageAndGifAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_image_and_gif_autoplay, parent, false));
case VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY:
if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts)) {
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));
}
return new PostDetailImageAndGifAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_image_and_gif_autoplay, parent, false));
case VIEW_TYPE_POST_DETAIL_LINK: case VIEW_TYPE_POST_DETAIL_LINK:
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false)); return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));

View File

@ -193,7 +193,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mLongPressToHideToolbarInCompactLayout; private boolean mLongPressToHideToolbarInCompactLayout;
private boolean mCompactLayoutToolbarHiddenByDefault; private boolean mCompactLayoutToolbarHiddenByDefault;
private boolean mDataSavingMode = false; private boolean mDataSavingMode = false;
private boolean mDisableImagePreview = false; private boolean mDisableImagePreview;
private boolean mOnlyDisablePreviewInVideoAndGifPosts;
private boolean mMarkPostsAsRead; private boolean mMarkPostsAsRead;
private boolean mMarkPostsAsReadAfterVoting; private boolean mMarkPostsAsReadAfterVoting;
private boolean mMarkPostsAsReadOnScroll; private boolean mMarkPostsAsReadOnScroll;
@ -259,6 +260,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR; mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
} }
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false); mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false); mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false); mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false);
@ -685,6 +687,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.GALLERY_TYPE) { } else if (post.getPostType() == Post.GALLERY_TYPE) {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp); ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
} }
} else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_outline_video_24dp);
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
} else { } else {
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
@ -924,16 +930,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post.getPostType() != Post.TEXT_TYPE && post.getPostType() != Post.NO_PREVIEW_LINK_TYPE && !(mDataSavingMode && mDisableImagePreview)) { if (post.getPostType() != Post.TEXT_TYPE && post.getPostType() != Post.NO_PREVIEW_LINK_TYPE && !(mDataSavingMode && mDisableImagePreview)) {
((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE);
if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) { if (post.getPostType() == Post.GALLERY_TYPE && post.getPreviews() != null && post.getPreviews().isEmpty()) {
((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
} ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_24dp);
if (post.getPostType() == Post.GALLERY_TYPE && post.getPreviews().isEmpty()) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
} else {
((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.VISIBLE);
} }
ArrayList<Post.Preview> previews = post.getPreviews(); ArrayList<Post.Preview> previews = post.getPreviews();
if (previews != null && !previews.isEmpty()) { if (previews != null && !previews.isEmpty()) {
if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) {
((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
}
loadImage(holder, post, previews.get(0)); loadImage(holder, post, previews.get(0));
} }
} }
@ -960,15 +966,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
case Post.IMAGE_TYPE: case Post.IMAGE_TYPE:
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.image); ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.image);
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_image_24dp);
} }
break; break;
case Post.LINK_TYPE: case Post.LINK_TYPE:
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.link); ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.link);
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_link);
} }
((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
@ -977,9 +983,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
break; break;
case Post.GIF_TYPE: case Post.GIF_TYPE:
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gif); ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gif);
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts)) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_image_24dp);
} else { } else {
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
} }
@ -987,9 +993,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
break; break;
case Post.VIDEO_TYPE: case Post.VIDEO_TYPE:
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.video); ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.video);
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts)) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_outline_video_24dp); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_outline_video_24dp);
} else { } else {
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
} }
@ -1002,14 +1008,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
String noPreviewLinkDomain = Uri.parse(noPreviewLinkUrl).getHost(); String noPreviewLinkDomain = Uri.parse(noPreviewLinkUrl).getHost();
((PostCompactBaseViewHolder) holder).linkTextView.setText(noPreviewLinkDomain); ((PostCompactBaseViewHolder) holder).linkTextView.setText(noPreviewLinkDomain);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_link);
break; break;
case Post.GALLERY_TYPE: case Post.GALLERY_TYPE:
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gallery); ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gallery);
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_24dp);
} }
break; break;
case Post.TEXT_TYPE: case Post.TEXT_TYPE:
@ -1316,6 +1322,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mDisableImagePreview = disableImagePreview; mDisableImagePreview = disableImagePreview;
} }
public void setOnlyDisablePreviewInVideoPosts(boolean onlyDisablePreviewInVideoAndGifPosts) {
mOnlyDisablePreviewInVideoAndGifPosts = onlyDisablePreviewInVideoAndGifPosts;
}
@Override @Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder); super.onViewRecycled(holder);
@ -1405,7 +1415,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE);
((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.GONE); ((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.GONE);
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.GONE); ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.GONE);
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.GONE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.GONE);
((PostCompactBaseViewHolder) holder).upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostCompactBaseViewHolder) holder).upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((PostCompactBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); ((PostCompactBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor);
((PostCompactBaseViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostCompactBaseViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
@ -2493,8 +2503,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
ProgressBar progressBar; ProgressBar progressBar;
ImageView imageView; ImageView imageView;
ImageView playButtonImageView; ImageView playButtonImageView;
FrameLayout noPreviewLinkImageFrameLayout; FrameLayout noPreviewPostImageFrameLayout;
ImageView noPreviewLinkImageView; ImageView noPreviewPostImageView;
Barrier imageBarrier; Barrier imageBarrier;
ConstraintLayout bottomConstraintLayout; ConstraintLayout bottomConstraintLayout;
ImageView upvoteButton; ImageView upvoteButton;
@ -2544,8 +2554,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
this.progressBar = progressBar; this.progressBar = progressBar;
this.imageView = imageView; this.imageView = imageView;
this.playButtonImageView = playButtonImageView; this.playButtonImageView = playButtonImageView;
this.noPreviewLinkImageFrameLayout = noPreviewLinkImageFrameLayout; this.noPreviewPostImageFrameLayout = noPreviewLinkImageFrameLayout;
this.noPreviewLinkImageView = noPreviewLinkImageView; this.noPreviewPostImageView = noPreviewLinkImageView;
this.imageBarrier = imageBarrier; this.imageBarrier = imageBarrier;
this.bottomConstraintLayout = bottomConstraintLayout; this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton; this.upvoteButton = upvoteButton;

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangeOnlyDisablePreviewInVideoAndGifPostsEvent {
public boolean onlyDisablePreviewInVideoAndGifPosts;
public ChangeOnlyDisablePreviewInVideoAndGifPostsEvent(boolean onlyDisablePreviewInVideoAndGifPosts) {
this.onlyDisablePreviewInVideoAndGifPosts = onlyDisablePreviewInVideoAndGifPosts;
}
}

View File

@ -88,6 +88,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEv
import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent;
import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent; import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent;
@ -1551,6 +1552,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
} }
@Subscribe
public void onChangeOnlyDisablePreviewInVideoAndGifPostsEvent(ChangeOnlyDisablePreviewInVideoAndGifPostsEvent changeOnlyDisablePreviewInVideoAndGifPostsEvent) {
if (mAdapter != null) {
mAdapter.setOnlyDisablePreviewInVideoPosts(changeOnlyDisablePreviewInVideoAndGifPostsEvent.onlyDisablePreviewInVideoAndGifPosts);
refreshAdapter();
}
}
@Subscribe @Subscribe
public void onChangeSwipeActionEvent(ChangeSwipeActionEvent changeSwipeActionEvent) { public void onChangeSwipeActionEvent(ChangeSwipeActionEvent changeSwipeActionEvent) {
swipeRightAction = changeSwipeActionEvent.swipeRightAction == -1 ? swipeRightAction : changeSwipeActionEvent.swipeRightAction; swipeRightAction = changeSwipeActionEvent.swipeRightAction == -1 ? swipeRightAction : changeSwipeActionEvent.swipeRightAction;

View File

@ -8,9 +8,10 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
@ -21,6 +22,7 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE); ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE);
SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW); SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW);
SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS);
if (dataSavingModeListPreference != null) { if (dataSavingModeListPreference != null) {
dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> { dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
@ -35,5 +37,12 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
} }
if (onlyDisablePreviewInVideoAndGifPostsPreference != null) {
onlyDisablePreviewInVideoAndGifPostsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeOnlyDisablePreviewInVideoAndGifPostsEvent((Boolean) newValue));
return true;
});
}
} }
} }

View File

@ -149,6 +149,7 @@ public class SharedPreferencesUtils {
public static final String LANGUAGE_DEFAULT_VALUE = "auto"; public static final String LANGUAGE_DEFAULT_VALUE = "auto";
public static final String ENABLE_SEARCH_HISTORY = "enable_search_history"; public static final String ENABLE_SEARCH_HISTORY = "enable_search_history";
public static final String POST_FILTER = "post_filter"; public static final String POST_FILTER = "post_filter";
public static final String ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS = "only_disable_preview_in_video_and_gif_posts";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="application_name" translatable="false">Infinity</string> <string name="application_name" translatable="false">Infinity</string>
<string name="login_activity_label">Login</string> <string name="login_activity_label">Login</string>
<string name="search_activity_label">Search</string> <string name="search_activity_label" translatable="false"> </string>
<string name="comment_activity_label">Send Comment</string> <string name="comment_activity_label">Send Comment</string>
<string name="comment_activity_label_is_replying">Reply</string> <string name="comment_activity_label_is_replying">Reply</string>
<string name="post_text_activity_label">Text Post</string> <string name="post_text_activity_label">Text Post</string>
@ -517,6 +517,7 @@
<string name="settings_credits_ufo_capturing_animation_title">UFO Capturing Animation</string> <string name="settings_credits_ufo_capturing_animation_title">UFO Capturing Animation</string>
<string name="settings_hide_subreddit_description_title">Hide Subreddit Description</string> <string name="settings_hide_subreddit_description_title">Hide Subreddit Description</string>
<string name="settings_disable_image_preview_title">Disable Image Preview in Data Saving Mode</string> <string name="settings_disable_image_preview_title">Disable Image Preview in Data Saving Mode</string>
<string name="settings_only_disable_preview_in_video_and_gif_posts_title">Only Disable Preview in Video and Gif Posts</string>
<string name="settings_swipe_action_swipe_left_title">Swipe Left</string> <string name="settings_swipe_action_swipe_left_title">Swipe Left</string>
<string name="settings_swipe_action_swipe_right_title">Swipe Right</string> <string name="settings_swipe_action_swipe_right_title">Swipe Right</string>
<string name="settings_swipe_action_info_summary">Not applicable to post feed with more than 1 column or post detail.</string> <string name="settings_swipe_action_info_summary">Not applicable to post feed with more than 1 column or post detail.</string>

View File

@ -20,4 +20,9 @@
app:key="disable_image_preview" app:key="disable_image_preview"
android:title="@string/settings_disable_image_preview_title" /> android:title="@string/settings_disable_image_preview_title" />
<SwitchPreference
app:defaultValue="false"
app:key="only_disable_preview_in_video_and_gif_posts"
android:title="@string/settings_only_disable_preview_in_video_and_gif_posts_title" />
</PreferenceScreen> </PreferenceScreen>