From faa15f8d09b157eeb03bb76d6fa2e61f08f2136b Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 14 Jul 2020 10:48:43 +0800 Subject: Optimize image loading in all ViewHolders in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter. --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 20 ++++++++++--- .../Adapter/PostRecyclerViewAdapter.java | 34 +++++++++++++++------- 2 files changed, 39 insertions(+), 15 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index f04fa355..bbf36110 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -705,7 +705,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter 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 mPost.getPreviewWidth()) { @@ -1276,7 +1280,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mPost.getPreviewWidth()) { + imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); + } else { + imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); + } } } else if (holder instanceof PostDetailLinkViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(mPost.getPreviewUrl()) @@ -1304,7 +1312,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mPost.getPreviewWidth()) { + imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailLinkViewHolder) holder).mImageView); + } else { + imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 023fec60..835d8af1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -100,13 +100,13 @@ import retrofit2.Retrofit; public class PostRecyclerViewAdapter extends PagedListAdapter 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 DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(@NonNull Post post, @NonNull Post t1) { @@ -542,7 +542,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 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.getPreviewWidth()) { + imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostVideoAndGifPreviewViewHolder) holder).imageView); + } else { + imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView); + } } } else if (holder instanceof PostLinkTypeViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener() { @@ -931,7 +939,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 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(); -- cgit v1.2.3