mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Optimize image loading in all ViewHolders in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter.
This commit is contained in:
parent
b1c6223233
commit
faa15f8d09
@ -705,7 +705,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) mPost.getPreviewWidth() / mPost.getPreviewHeight());
|
||||
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
|
||||
if (mImageViewWidth > mPost.getPreviewWidth()) {
|
||||
mGlide.load(mPost.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
} else {
|
||||
mGlide.load(mPost.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
}
|
||||
((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
|
||||
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
|
||||
@ -1241,7 +1245,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
}
|
||||
});
|
||||
|
||||
if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
|
||||
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
|
||||
} else {
|
||||
if (mImageViewWidth > mPost.getPreviewWidth()) {
|
||||
@ -1276,7 +1280,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
} else {
|
||||
imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
if (mImageViewWidth > mPost.getPreviewWidth()) {
|
||||
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
} else {
|
||||
imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostDetailLinkViewHolder) {
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
|
||||
@ -1303,11 +1311,15 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostDetailLinkViewHolder) holder).mImageView);
|
||||
} else {
|
||||
if (mImageViewWidth > mPost.getPreviewWidth()) {
|
||||
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailLinkViewHolder) holder).mImageView);
|
||||
} else {
|
||||
imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePost(Post post) {
|
||||
mPost = post;
|
||||
|
@ -100,13 +100,13 @@ import retrofit2.Retrofit;
|
||||
public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHolder> implements CacheManager {
|
||||
private static final int VIEW_TYPE_POST_CARD_VIDEO_AUTOPLAY_TYPE = 1;
|
||||
private static final int VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE = 2;
|
||||
private static final int VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE = 4;
|
||||
private static final int VIEW_TYPE_POST_CARD_LINK_TYPE = 5;
|
||||
private static final int VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE = 6;
|
||||
private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 7;
|
||||
private static final int VIEW_TYPE_POST_COMPACT = 8;
|
||||
private static final int VIEW_TYPE_ERROR = 9;
|
||||
private static final int VIEW_TYPE_LOADING = 10;
|
||||
private static final int VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE = 3;
|
||||
private static final int VIEW_TYPE_POST_CARD_LINK_TYPE = 4;
|
||||
private static final int VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE = 5;
|
||||
private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 6;
|
||||
private static final int VIEW_TYPE_POST_COMPACT = 7;
|
||||
private static final int VIEW_TYPE_ERROR = 8;
|
||||
private static final int VIEW_TYPE_LOADING = 9;
|
||||
private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull Post post, @NonNull Post t1) {
|
||||
@ -542,7 +542,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
if (holder instanceof PostVideoAutoplayViewHolder) {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) post.getPreviewWidth() / post.getPreviewHeight());
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
|
||||
mGlide.load(post.getPreviewUrl()).apply(RequestOptions.noTransformation()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
if (mImageViewWidth > post.getPreviewWidth()) {
|
||||
mGlide.load(post.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
} else {
|
||||
mGlide.load(post.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
}
|
||||
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl()));
|
||||
} else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
|
||||
@ -867,7 +871,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
});
|
||||
|
||||
if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
|
||||
if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
|
||||
} else {
|
||||
@ -903,7 +907,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
|
||||
} else {
|
||||
imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
|
||||
if (mImageViewWidth > post.getPreviewWidth()) {
|
||||
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
|
||||
} else {
|
||||
imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostLinkTypeViewHolder) {
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
|
||||
@ -931,7 +939,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostLinkTypeViewHolder) holder).imageView);
|
||||
} else {
|
||||
imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostLinkTypeViewHolder) holder).imageView);
|
||||
if (mImageViewWidth > post.getPreviewWidth()) {
|
||||
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostLinkTypeViewHolder) holder).imageView);
|
||||
} else {
|
||||
imageRequestBuilder.into(((PostLinkTypeViewHolder) holder).imageView);
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostCompactBaseViewHolder) {
|
||||
String previewUrl = post.getThumbnailPreviewUrl().equals("") ? post.getPreviewUrl() : post.getThumbnailPreviewUrl();
|
||||
|
Loading…
Reference in New Issue
Block a user