From 16fc58bd16ae0c1c51002ec6d7cf24e936aa5f45 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 4 Jul 2020 16:07:25 -0400 Subject: [PATCH] Use custom view to handle manga info cover size (fixes #3354) --- .../ui/manga/chapter/MangaCoverImageView.kt | 24 +++++++++++++ app/src/main/res/layout/manga_info_header.xml | 35 ++++++------------- 2 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaCoverImageView.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaCoverImageView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaCoverImageView.kt new file mode 100644 index 000000000..988a98e8f --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaCoverImageView.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.ui.manga.chapter + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatImageView +import kotlin.math.min + +/** + * A custom ImageView for holding a manga cover with: + * - width: min(maxWidth attr, 33% of parent width) + * - height: 2:3 width:height ratio + * + * Should be defined with a width of match_parent. + */ +class MangaCoverImageView(context: Context, attrs: AttributeSet?) : AppCompatImageView(context, attrs) { + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + + val width = min(maxWidth, measuredWidth / 3) + val height = width / 2 * 3 + setMeasuredDimension(width, height) + } +} diff --git a/app/src/main/res/layout/manga_info_header.xml b/app/src/main/res/layout/manga_info_header.xml index 35590e01d..5f118a241 100644 --- a/app/src/main/res/layout/manga_info_header.xml +++ b/app/src/main/res/layout/manga_info_header.xml @@ -28,44 +28,31 @@ android:background="@drawable/manga_info_gradient" app:layout_constraintBottom_toBottomOf="parent" /> - - - - - +