mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
New option: Disable Image Preview in Data Saving Mode.
This commit is contained in:
parent
7e446c9fcb
commit
a4b95aee24
@ -178,6 +178,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
private boolean mMuteNSFWVideo;
|
||||
private boolean mAutomaticallyTryRedgifs;
|
||||
private boolean mDataSavingMode;
|
||||
private boolean mDisableImagePreview;
|
||||
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
||||
private boolean isInitiallyLoading;
|
||||
private boolean isInitiallyLoadingFailed;
|
||||
@ -488,6 +489,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
|
||||
}
|
||||
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
|
||||
|
||||
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
||||
isInitiallyLoading = true;
|
||||
@ -643,12 +645,27 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
case VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY:
|
||||
if (mDataSavingMode) {
|
||||
if (mDisableImagePreview) {
|
||||
return new PostDetailNoPreviewLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview_link, 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));
|
||||
case VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW:
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
return new PostDetailNoPreviewLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview_link, 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:
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
return new PostDetailNoPreviewLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview_link, 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:
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
return new PostDetailNoPreviewLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview_link, parent, false));
|
||||
}
|
||||
return new PostDetailLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_link, parent, false));
|
||||
case VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK:
|
||||
return new PostDetailNoPreviewLinkViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview_link, parent, false));
|
||||
@ -913,8 +930,35 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
}
|
||||
|
||||
} else if (holder instanceof PostDetailNoPreviewLinkViewHolder) {
|
||||
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
|
||||
if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE);
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
|
||||
} else {
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setVisibility(View.GONE);
|
||||
switch (mPost.getPostType()) {
|
||||
case Post.VIDEO_TYPE:
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mTypeTextView.setText(R.string.video);
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mNoPreviewLinkImageView.setImageResource(R.drawable.ic_outline_video_24dp);
|
||||
break;
|
||||
case Post.IMAGE_TYPE:
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mTypeTextView.setText(R.string.image);
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mNoPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
break;
|
||||
case Post.GIF_TYPE:
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mTypeTextView.setText(R.string.gif);
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mNoPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
break;
|
||||
case Post.LINK_TYPE:
|
||||
case Post.NO_PREVIEW_LINK_TYPE:
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mTypeTextView.setText(R.string.link);
|
||||
break;
|
||||
case Post.GALLERY_TYPE:
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mTypeTextView.setText(R.string.gallery);
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mNoPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
|
||||
((PostDetailNoPreviewLinkViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
|
||||
@ -3029,15 +3073,57 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
mNoPreviewLinkImageView.setBackgroundColor(mNoPreviewLinkBackgroundColor);
|
||||
|
||||
mNoPreviewLinkImageView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(mPost.getUrl());
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl()));
|
||||
} else {
|
||||
intent.setData(uri);
|
||||
if (mPost != null) {
|
||||
if (mPost.getPostType() == Post.VIDEO_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (mPost.isGfycat()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
|
||||
} else if (mPost.isRedgifs()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
|
||||
} else {
|
||||
intent.setData(Uri.parse(mPost.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
|
||||
}
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (mPost.getPostType() == Post.IMAGE_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mPost.getUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
|
||||
+ "-" + mPost.getId() + ".jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (mPost.getPostType() == Post.GIF_TYPE){
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
|
||||
+ "-" + mPost.getId() + ".gif");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(mPost.getUrl());
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl()));
|
||||
} else {
|
||||
intent.setData(uri);
|
||||
}
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (mPost.getPostType() == Post.GALLERY_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
||||
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, mPost.getGallery());
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
private boolean mLongPressToHideToolbarInCompactLayout;
|
||||
private boolean mCompactLayoutToolbarHiddenByDefault;
|
||||
private boolean mDataSavingMode = false;
|
||||
private boolean mDisableImagePreview = false;
|
||||
private Drawable mCommentIcon;
|
||||
private NetworkState networkState;
|
||||
private ExoCreator mExoCreator;
|
||||
@ -247,6 +248,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
|
||||
}
|
||||
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
|
||||
|
||||
mPostLayout = postLayout;
|
||||
|
||||
@ -354,6 +356,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == VIEW_TYPE_POST_CARD_VIDEO_AUTOPLAY_TYPE) {
|
||||
if (mDataSavingMode) {
|
||||
return new PostWithPreviewTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_with_preview, parent, false));
|
||||
}
|
||||
return new PostVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_video_type_autoplay, parent, false));
|
||||
} else if (viewType == VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE
|
||||
|| viewType == VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE
|
||||
@ -631,19 +636,34 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
Post.Preview preview = getSuitablePreview(post.getPreviews());
|
||||
if (preview != null) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
|
||||
if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder, post, preview);
|
||||
} else {
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_outline_video_24dp);
|
||||
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
|
||||
} else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
|
||||
} else if (post.getPostType() == Post.LINK_TYPE) {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link);
|
||||
} else if (post.getPostType() == Post.GALLERY_TYPE) {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
|
||||
}
|
||||
} else {
|
||||
Post.Preview preview = getSuitablePreview(post.getPreviews());
|
||||
if (preview != null) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
|
||||
if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder, post, preview);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostTextTypeViewHolder) {
|
||||
if (!post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
|
||||
@ -840,7 +860,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
break;
|
||||
}
|
||||
|
||||
if (post.getPostType() != Post.TEXT_TYPE && post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) {
|
||||
if (post.getPostType() != Post.TEXT_TYPE && post.getPostType() != Post.NO_PREVIEW_LINK_TYPE && !(mDataSavingMode && mDisableImagePreview)) {
|
||||
((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE);
|
||||
if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) {
|
||||
((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
@ -877,9 +897,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
switch (post.getPostType()) {
|
||||
case Post.IMAGE_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.image);
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
}
|
||||
break;
|
||||
case Post.LINK_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.link);
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link);
|
||||
}
|
||||
|
||||
((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
|
||||
String domain = Uri.parse(post.getUrl()).getHost();
|
||||
@ -887,11 +915,23 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
break;
|
||||
case Post.GIF_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gif);
|
||||
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
} else {
|
||||
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
break;
|
||||
case Post.VIDEO_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.video);
|
||||
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_outline_video_24dp);
|
||||
} else {
|
||||
((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
break;
|
||||
case Post.NO_PREVIEW_LINK_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.link);
|
||||
@ -901,9 +941,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
String noPreviewLinkDomain = Uri.parse(noPreviewLinkUrl).getHost();
|
||||
((PostCompactBaseViewHolder) holder).linkTextView.setText(noPreviewLinkDomain);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link);
|
||||
break;
|
||||
case Post.GALLERY_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gallery);
|
||||
if (mDataSavingMode && mDisableImagePreview) {
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
|
||||
((PostCompactBaseViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
|
||||
}
|
||||
break;
|
||||
case Post.TEXT_TYPE:
|
||||
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.text);
|
||||
@ -1176,6 +1221,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
mDataSavingMode = dataSavingMode;
|
||||
}
|
||||
|
||||
public void setDisableImagePreview(boolean disableImagePreview) {
|
||||
mDisableImagePreview = disableImagePreview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
@ -2259,6 +2308,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
ImageView imageView;
|
||||
ImageView playButtonImageView;
|
||||
FrameLayout noPreviewLinkImageFrameLayout;
|
||||
ImageView noPreviewLinkImageView;
|
||||
Barrier imageBarrier;
|
||||
ConstraintLayout bottomConstraintLayout;
|
||||
ImageView upvoteButton;
|
||||
@ -2309,6 +2359,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
this.imageView = imageView;
|
||||
this.playButtonImageView = playButtonImageView;
|
||||
this.noPreviewLinkImageFrameLayout = noPreviewLinkImageFrameLayout;
|
||||
this.noPreviewLinkImageView = noPreviewLinkImageView;
|
||||
this.imageBarrier = imageBarrier;
|
||||
this.bottomConstraintLayout = bottomConstraintLayout;
|
||||
this.upvoteButton = upvoteButton;
|
||||
@ -2473,80 +2524,40 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
switch (post.getPostType()) {
|
||||
case Post.IMAGE_TYPE: {
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
|
||||
+ "-" + post.getId() + ".jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case Post.LINK_TYPE: {
|
||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(post.getUrl());
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl()));
|
||||
} else {
|
||||
intent.setData(uri);
|
||||
}
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case Post.GIF_TYPE: {
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (post.isGfycat()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
|
||||
} else if (post.isRedgifs()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
|
||||
} else {
|
||||
intent.setData(Uri.parse(post.getVideoUrl()));
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
|
||||
+ "-" + post.getId() + ".gif");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
break;
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
|
||||
}
|
||||
case Post.VIDEO_TYPE: {
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (post.isGfycat()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
|
||||
} else if (post.isRedgifs()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
|
||||
} else {
|
||||
intent.setData(Uri.parse(post.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
|
||||
}
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case Post.GALLERY_TYPE: {
|
||||
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
noPreviewLinkImageFrameLayout.setOnClickListener(view -> {
|
||||
int position = getAdapterPosition();
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (post.getPostType() == Post.GALLERY_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
} else {
|
||||
} else if (post.getPostType() == Post.IMAGE_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
|
||||
+ "-" + post.getId() + ".jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (post.getPostType() == Post.GIF_TYPE){
|
||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
|
||||
+ "-" + post.getId() + ".gif");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(post.getUrl());
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
@ -2556,10 +2567,19 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||
mActivity.startActivity(intent);
|
||||
} else if (post.getPostType() == Post.GALLERY_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
||||
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
|
||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
noPreviewLinkImageFrameLayout.setOnClickListener(view -> {
|
||||
imageView.performClick();
|
||||
});
|
||||
|
||||
upvoteButton.setOnClickListener(view -> {
|
||||
if (mAccessToken == null) {
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeDisableImagePreviewEvent {
|
||||
public boolean disableImagePreview;
|
||||
|
||||
public ChangeDisableImagePreviewEvent(boolean disableImagePreview) {
|
||||
this.disableImagePreview = disableImagePreview;
|
||||
}
|
||||
}
|
@ -74,6 +74,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeCompactLayoutToolbarHiddenByDefaultEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDataSavingModeEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDisableImagePreviewEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeLongPressToHideToolbarInCompactLayoutEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
|
||||
@ -1306,6 +1307,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeDisableImagePreviewEvent(ChangeDisableImagePreviewEvent changeDisableImagePreviewEvent) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.setDisableImagePreview(changeDisableImagePreviewEvent.disableImagePreview);
|
||||
refreshAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshAdapter() {
|
||||
int previousPosition = -1;
|
||||
if (mLinearLayoutManager != null) {
|
||||
|
@ -4,10 +4,12 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDataSavingModeEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDisableImagePreviewEvent;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
@ -18,6 +20,7 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
|
||||
setPreferencesFromResource(R.xml.data_saving_mode_preferences, rootKey);
|
||||
|
||||
ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE);
|
||||
SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW);
|
||||
|
||||
if (dataSavingModeListPreference != null) {
|
||||
dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
@ -25,5 +28,12 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (disableImagePreviewPreference != null) {
|
||||
disableImagePreviewPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new ChangeDisableImagePreviewEvent((Boolean) newValue));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -139,6 +139,7 @@ public class SharedPreferencesUtils {
|
||||
public static final String SUBREDDIT_FILTER_POPULAR_AND_ALL = "subreddit_filter_popular_and_all";
|
||||
public static final String UFO_CAPTURING_ANIMATION = "ufo_capturing_animation";
|
||||
public static final String HIDE_SUBREDDIT_DESCRIPTION = "hide_subreddit_description";
|
||||
public static final String DISABLE_IMAGE_PREVIEW = "disable_image_preview";
|
||||
|
||||
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";
|
||||
|
5
app/src/main/res/drawable/ic_gallery_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_gallery_24dp.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20,4v12L8,16L8,4h12m0,-2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM11.5,11.67l1.69,2.26 2.48,-3.1L19,15L9,15zM2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6L2,6z"/>
|
||||
</vector>
|
@ -503,6 +503,7 @@
|
||||
<string name="settings_subreddit_filter_popular_and_all">In r/popular and r/all</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_disable_image_preview_title">Disable Image Preview in Data Saving Mode</string>
|
||||
|
||||
<string name="no_link_available">Cannot get the link</string>
|
||||
|
||||
|
@ -2,6 +2,11 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<Preference
|
||||
app:icon="@drawable/ic_info_preference_24dp"
|
||||
app:summary="@string/settings_data_saving_mode_info_summary"
|
||||
app:enabled="false" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="0"
|
||||
app:key="data_saving_mode"
|
||||
@ -10,9 +15,9 @@
|
||||
app:entryValues="@array/settings_data_saving_mode_values"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<Preference
|
||||
app:icon="@drawable/ic_info_preference_24dp"
|
||||
app:summary="@string/settings_data_saving_mode_info_summary"
|
||||
app:enabled="false" />
|
||||
<SwitchPreference
|
||||
app:defaultValue="false"
|
||||
app:key="disable_image_preview"
|
||||
android:title="@string/settings_disable_image_preview_title" />
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user