aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-07-14 02:48:43 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-07-14 02:48:43 +0000
commitfaa15f8d09b157eeb03bb76d6fa2e61f08f2136b (patch)
tree810eb4ae5a87965e4a638edadb62eeb6b3c529a1 /app
parentb1c6223233ea38cfcfbb2a7505a33364f8ce9922 (diff)
downloadinfinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar.gz
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar.bz2
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar.lz
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar.xz
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.tar.zst
infinity-for-reddit-faa15f8d09b157eeb03bb76d6fa2e61f08f2136b.zip
Optimize image loading in all ViewHolders in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java34
2 files changed, 39 insertions, 15 deletions
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<Recy
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) mPost.getPreviewWidth() / mPost.getPreviewHeight());
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
- mGlide.load(mPost.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ 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())
@@ -1304,7 +1312,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView);
+ if (mImageViewWidth > 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<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();