From 049f9fa6257421f191ca54536d54d331504b7139 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 17 Nov 2021 19:08:13 +0200 Subject: [PATCH] Fix cover image in lists --- .../kotatsu/base/ui/widgets/CoverImageView.kt | 45 +++++-------------- app/src/main/res/layout/item_manga_list.xml | 6 +-- .../res/layout/item_manga_list_details.xml | 2 +- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/base/ui/widgets/CoverImageView.kt b/app/src/main/java/org/koitharu/kotatsu/base/ui/widgets/CoverImageView.kt index d387a761b..a4e7bf748 100644 --- a/app/src/main/java/org/koitharu/kotatsu/base/ui/widgets/CoverImageView.kt +++ b/app/src/main/java/org/koitharu/kotatsu/base/ui/widgets/CoverImageView.kt @@ -6,7 +6,7 @@ import android.widget.LinearLayout import androidx.appcompat.widget.AppCompatImageView import androidx.core.content.withStyledAttributes import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.utils.ext.resolveAdjustedSize +import kotlin.math.roundToInt class CoverImageView @JvmOverloads constructor( @@ -17,47 +17,22 @@ class CoverImageView @JvmOverloads constructor( init { context.withStyledAttributes(attrs, R.styleable.CoverImageView, defStyleAttr) { - orientation = getInt(R.styleable.CoverImageView_android_orientation, HORIZONTAL) + orientation = getInt(R.styleable.CoverImageView_android_orientation, orientation) } } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val w: Int - val h: Int + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + val desiredWidth: Int + val desiredHeight: Int if (orientation == VERTICAL) { - val desiredHeight = (drawable?.intrinsicHeight?.coerceAtLeast(0) ?: 0) + - paddingTop + paddingBottom - h = resolveAdjustedSize( - desiredHeight.coerceAtLeast(suggestedMinimumHeight), - maxHeight, - heightMeasureSpec - ) - val desiredWidth = - (h * ASPECT_RATIO_WIDTH / ASPECT_RATIO_HEIGHT).toInt() + paddingLeft + paddingRight - w = resolveAdjustedSize( - desiredWidth.coerceAtLeast(suggestedMinimumWidth), - maxWidth, - widthMeasureSpec - ) + desiredHeight = measuredHeight + desiredWidth = (desiredHeight * ASPECT_RATIO_WIDTH / ASPECT_RATIO_HEIGHT).roundToInt() } else { - val desiredWidth = (drawable?.intrinsicWidth?.coerceAtLeast(0) ?: 0) + - paddingLeft + paddingRight - w = resolveAdjustedSize( - desiredWidth.coerceAtLeast(suggestedMinimumWidth), - maxWidth, - widthMeasureSpec - ) - val desiredHeight = - (w * ASPECT_RATIO_HEIGHT / ASPECT_RATIO_WIDTH).toInt() + paddingTop + paddingBottom - h = resolveAdjustedSize( - desiredHeight.coerceAtLeast(suggestedMinimumHeight), - maxHeight, - heightMeasureSpec - ) + desiredWidth = measuredWidth + desiredHeight = (desiredWidth * ASPECT_RATIO_HEIGHT / ASPECT_RATIO_WIDTH).roundToInt() } - val widthSize = resolveSizeAndState(w, widthMeasureSpec, 0) - val heightSize = resolveSizeAndState(h, heightMeasureSpec, 0) - setMeasuredDimension(widthSize, heightSize) + setMeasuredDimension(desiredWidth, desiredHeight) } companion object { diff --git a/app/src/main/res/layout/item_manga_list.xml b/app/src/main/res/layout/item_manga_list.xml index 333115285..a7be870fb 100644 --- a/app/src/main/res/layout/item_manga_list.xml +++ b/app/src/main/res/layout/item_manga_list.xml @@ -11,15 +11,15 @@ diff --git a/app/src/main/res/layout/item_manga_list_details.xml b/app/src/main/res/layout/item_manga_list_details.xml index 63d959bf8..d27a4668e 100644 --- a/app/src/main/res/layout/item_manga_list_details.xml +++ b/app/src/main/res/layout/item_manga_list_details.xml @@ -10,7 +10,7 @@