From a792a6e6ae0fff6a6f21afdba42b60feb574c1b2 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 22 May 2018 16:59:42 -0400 Subject: [PATCH] Fixed ThumbnailView sizing problems. Glide will use the dimensions of the target ImageView as the dimensions for the image it's loading. This caused problems in the case of ThumbnailView, as we were constantly changing the ImageView dimensions, meaning Glide may not have the most recent values (it may be called in between measure calls, for instance). To solve this, we now will always override the default image dimensions when we load an image. If no dimensions are present, we will default to the layout_width and layout_height of the ThumbnailView. Fixes #7810 --- .../securesms/components/ThumbnailView.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/ThumbnailView.java b/src/org/thoughtcrime/securesms/components/ThumbnailView.java index 3c25aab8b7..26b95e209a 100644 --- a/src/org/thoughtcrime/securesms/components/ThumbnailView.java +++ b/src/org/thoughtcrime/securesms/components/ThumbnailView.java @@ -10,6 +10,7 @@ import android.util.AttributeSet; import android.util.Log; import android.util.Pair; import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; @@ -225,10 +226,6 @@ public class ThumbnailView extends FrameLayout { boolean showControls, boolean isPreview, int naturalWidth, int naturalHeight) { - dimens[WIDTH] = naturalWidth; - dimens[HEIGHT] = naturalHeight; - invalidate(); - if (showControls) { getTransferControls().setSlide(slide); getTransferControls().setDownloadClickListener(new DownloadClickDispatcher()); @@ -263,6 +260,10 @@ public class ThumbnailView extends FrameLayout { this.slide = slide; + dimens[WIDTH] = naturalWidth; + dimens[HEIGHT] = naturalHeight; + invalidate(); + if (slide.getThumbnailUri() != null) buildThumbnailGlideRequest(glideRequests, slide).into(image); else if (slide.hasPlaceholder()) buildPlaceholderGlideRequest(glideRequests, slide).into(image); else glideRequests.clear(image); @@ -316,14 +317,31 @@ public class ThumbnailView extends FrameLayout { .diskCacheStrategy(DiskCacheStrategy.NONE), new FitCenter()); } - private GlideRequest applySizing(@NonNull GlideRequest request, @NonNull BitmapTransformation unavailableDimensSizing) { + private GlideRequest applySizing(@NonNull GlideRequest request, @NonNull BitmapTransformation fitting) { int[] size = new int[2]; fillTargetDimensions(size, dimens, bounds); if (size[WIDTH] == 0 && size[HEIGHT] == 0) { - return request.transforms(unavailableDimensSizing, new RoundedCorners(radius)); + size[WIDTH] = getDefaultWidth(); + size[HEIGHT] = getDefaultHeight(); } return request.override(size[WIDTH], size[HEIGHT]) - .transforms(new CenterCrop(), new RoundedCorners(radius)); + .transforms(fitting, new RoundedCorners(radius)); + } + + private int getDefaultWidth() { + ViewGroup.LayoutParams params = getLayoutParams(); + if (params != null) { + return Math.max(params.width, 0); + } + return 0; + } + + private int getDefaultHeight() { + ViewGroup.LayoutParams params = getLayoutParams(); + if (params != null) { + return Math.max(params.height, 0); + } + return 0; } private class ThumbnailClickDispatcher implements View.OnClickListener {