From d7a2a6b8558d5ffb3157c4e3e4e61870f84e834c Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 19 Dec 2022 16:20:42 +0100 Subject: [PATCH] Fix jumps with media preview for some devices --- .../fedilab/android/ui/drawer/StatusAdapter.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 82df20bf..13f82ed7 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1163,15 +1163,15 @@ public class StatusAdapter extends RecyclerView.Adapter float mediaH = -1.0f; if (attachment.measuredWidth > 0) { + float viewWidth = attachment.measuredWidth; if (attachment.meta != null && attachment.meta.small != null) { - float viewWidth = attachment.measuredWidth; mediaH = attachment.meta.small.height; float mediaW = attachment.meta.small.width; if (mediaW != 0) { ratio = viewWidth / mediaW; } } - loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, mediaH, ratio, statusToDeal, attachment, singleMedia); + loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, viewWidth, mediaH, ratio, statusToDeal, attachment, singleMedia); } else { int finalMediaPosition = mediaPosition; layoutMediaBinding.media.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -1181,20 +1181,20 @@ public class StatusAdapter extends RecyclerView.Adapter attachment.measuredWidth = layoutMediaBinding.media.getWidth(); float ratio = 1.0f; float mediaH = -1.0f; + float viewWidth = attachment.measuredWidth; if (attachment.meta != null && attachment.meta.small != null) { - float viewWidth = attachment.measuredWidth; mediaH = attachment.meta.small.height; float mediaW = attachment.meta.small.width; if (mediaW != 0) { ratio = viewWidth / mediaW; } } - loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, finalMediaPosition, mediaH, ratio, statusToDeal, attachment, singleMedia); + loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, finalMediaPosition, viewWidth, mediaH, ratio, statusToDeal, attachment, singleMedia); } }); } } else { - loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, -1.f, -1.f, statusToDeal, attachment, singleMedia); + loadAndAddAttachment(context, layoutMediaBinding, holder, adapter, mediaPosition, -1.f, -1.f, -1.f, statusToDeal, attachment, singleMedia); } mediaPosition++; if (fullAttachement || singleMedia) { @@ -1966,7 +1966,7 @@ public class StatusAdapter extends RecyclerView.Adapter private static void loadAndAddAttachment(Context context, LayoutMediaBinding layoutMediaBinding, StatusViewHolder holder, RecyclerView.Adapter adapter, - int mediaPosition, float mediaH, float ratio, + int mediaPosition, float viewWidth, float mediaH, float ratio, Status statusToDeal, Attachment attachment, boolean singleImage) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5); @@ -2037,6 +2037,7 @@ public class StatusAdapter extends RecyclerView.Adapter requestBuilder = requestBuilder.apply(new RequestOptions().transform(new GlideFocus(focusX, focusY))); } else { requestBuilder = requestBuilder.placeholder(R.color.transparent_grey); + requestBuilder = requestBuilder.apply(new RequestOptions().override((int) viewWidth, (int) mediaH)); requestBuilder = requestBuilder.fitCenter(); } requestBuilder.into(layoutMediaBinding.media);