From 81d17227317f8a0decad11ca91fc8dd77d2ea784 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 30 Jun 2024 16:52:21 +0200 Subject: [PATCH] correctly scale gifs in FocusDialog (#4537) Found while testing #4528 The problem seems to be that Glide does not scale GIFs as it does static images. This workaround makes sure they still show up correctly. before / after --- .../components/compose/dialog/FocusDialog.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt index 6cfbeedfc..d4c0848e7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt @@ -50,10 +50,10 @@ fun T.makeFocusDialog( .downsample(DownsampleStrategy.CENTER_INSIDE) .listener(object : RequestListener { override fun onLoadFailed( - p0: GlideException?, - p1: Any?, - p2: Target, - p3: Boolean + error: GlideException?, + model: Any?, + target: Target, + isFirstResource: Boolean ): Boolean { return false } @@ -68,15 +68,20 @@ fun T.makeFocusDialog( val width = resource.intrinsicWidth val height = resource.intrinsicHeight - dialogBinding.focusIndicator.setImageSize(width, height) + val viewWidth = dialogBinding.imageView.width + val viewHeight = dialogBinding.imageView.height + + val scaledHeight = (viewWidth.toFloat() / width.toFloat()) * height + + dialogBinding.focusIndicator.setImageSize(viewWidth, scaledHeight.toInt()) // We want the dialog to be a little taller than the image, so you can slide your thumb past the image border, // but if it's *too* much taller that looks weird. See if a threshold has been crossed: if (width > height) { val maxHeight = dialogBinding.focusIndicator.maxAttractiveHeight() - if (dialogBinding.imageView.height > maxHeight) { - val verticalShrinkLayout = FrameLayout.LayoutParams(width, maxHeight) + if (viewHeight > maxHeight) { + val verticalShrinkLayout = FrameLayout.LayoutParams(viewWidth, maxHeight) dialogBinding.imageView.layoutParams = verticalShrinkLayout dialogBinding.focusIndicator.layoutParams = verticalShrinkLayout }