diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-11-02 13:35:28 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-11-02 13:35:28 +0000 |
commit | 90419413b9700038381d7abb61936909f74aaaf2 (patch) | |
tree | da4acf0f39cf367f16d756698df9f61acb27a20a /app | |
parent | be9bc8d014cbf8932e7ef9487f3f762102c3b433 (diff) | |
download | infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar.gz infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar.bz2 infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar.lz infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar.xz infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.tar.zst infinity-for-reddit-90419413b9700038381d7abb61936909f74aaaf2.zip |
Try optimizing image loading in PostRecyclerViewAdapter.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 448013f1..464a4ab1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -39,6 +39,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; @@ -1444,29 +1445,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie previewIndex = 0; } preview = previews.get(previewIndex); - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { for (int i = previews.size() - 1; i >= 1; i--) { preview = previews.get(i); if (mImageViewWidth >= preview.getPreviewWidth()) { - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { return preview; } } else { int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight(); - if (mImageViewWidth * height <= 10_000_000) { + if (mImageViewWidth * height <= 5_000_000) { + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); return preview; } } } } - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { int divisor = 2; do { preview.setPreviewWidth(preview.getPreviewWidth() / divisor); preview.setPreviewHeight(preview.getPreviewHeight() / divisor); divisor *= 2; - } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000); + } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000); } return preview; } @@ -1492,11 +1495,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) .into(((PostWithPreviewTypeViewHolder) holder).imageView); } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostWithPreviewTypeViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostWithPreviewTypeViewHolder) holder).imageView); - } + imageRequestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE).override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostWithPreviewTypeViewHolder) holder).imageView); } } } else if (holder instanceof PostCompactBaseViewHolder) { @@ -1740,6 +1739,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else { holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); } + mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView); ((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); if (holder instanceof PostVideoAutoplayViewHolder) { ((PostVideoAutoplayViewHolder) holder).mediaUri = null; |