From f5aa8a03e59ae53a7d1ff09df608447e33fcdbd2 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Sep 2022 14:40:45 +0200 Subject: [PATCH] Fix issue #319 - Fix jumps when setting fit preview images --- .../fedilab/android/helper/MediaHelper.java | 21 ++++++++++++++++++- .../android/ui/drawer/StatusAdapter.java | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java index b21703cf..932e6180 100644 --- a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java @@ -34,6 +34,7 @@ import android.text.format.DateFormat; import android.view.View; import android.webkit.MimeTypeMap; import android.webkit.URLUtil; +import android.widget.RelativeLayout; import android.widget.Toast; import androidx.annotation.Nullable; @@ -57,6 +58,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.List; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; @@ -65,6 +67,7 @@ import java.util.concurrent.atomic.AtomicInteger; import app.fedilab.android.BuildConfig; import app.fedilab.android.R; import app.fedilab.android.activities.ComposeActivity; +import app.fedilab.android.client.entities.api.Attachment; import app.fedilab.android.databinding.DatetimePickerBinding; import app.fedilab.android.databinding.PopupRecordBinding; import es.dmoral.toasty.Toasty; @@ -396,5 +399,21 @@ public class MediaHelper { void scheduledAt(String scheduledDate); } - + /** + * Returns the max height of a list of media + * + * @param attachmentList - List + * @return int - The max height + */ + public static int returnMaxHeightForPreviews(Context context, List attachmentList) { + int maxHeight = RelativeLayout.LayoutParams.WRAP_CONTENT; + if (attachmentList != null && attachmentList.size() > 0) { + for (Attachment attachment : attachmentList) { + if (attachment.meta != null && attachment.meta.small != null && attachment.meta.small.height > maxHeight) { + maxHeight = (int) Helper.convertDpToPixel(attachment.meta.small.height, context); + } + } + } + return maxHeight; + } } 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 c00c406e..666b32c2 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 @@ -1079,7 +1079,7 @@ public class StatusAdapter extends RecyclerView.Adapter LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false); RelativeLayout.LayoutParams lp; if (fullAttachement) { - lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, MediaHelper.returnMaxHeightForPreviews(context, statusToDeal.media_attachments)); layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) Helper.convertDpToPixel(200, context)); @@ -1197,7 +1197,7 @@ public class StatusAdapter extends RecyclerView.Adapter return true; }); if (fullAttachement) { - lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, MediaHelper.returnMaxHeightForPreviews(context, statusToDeal.media_attachments)); layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { lp = new RelativeLayout.LayoutParams((int) Helper.convertDpToPixel(200, context), (int) Helper.convertDpToPixel(200, context));