From 4481c54376fbdedc26e29a7942cd8752567ef4a3 Mon Sep 17 00:00:00 2001 From: S97 <39028181+saud-97@users.noreply.github.com> Date: Wed, 18 May 2022 00:19:38 +0300 Subject: [PATCH] Fixed Splitting Height for Tall Images (#7148) * Fixed Splitting Height for Tall Images #7140 * Update app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt Co-authored-by: FourTOne5 <59261191+FourTOne5@users.noreply.github.com> Co-authored-by: FourTOne5 <59261191+FourTOne5@users.noreply.github.com> --- .../eu/kanade/tachiyomi/util/system/ContextExtensions.kt | 5 +++-- .../main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 94b69e9d06..e430a0c3bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -47,6 +47,7 @@ import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File +import kotlin.math.max import kotlin.math.roundToInt private const val TABLET_UI_MIN_SCREEN_WIDTH_DP = 720 @@ -162,8 +163,8 @@ fun Context.hasPermission(permission: String) = ContextCompat.checkSelfPermissio } } -val getDisplayHeightInPx: Int - get() = Resources.getSystem().displayMetrics.heightPixels +val getDisplayMaxHeightInPx: Int + get() = Resources.getSystem().displayMetrics.let { max(it.heightPixels, it.widthPixels) } /** * Converts to dp. diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index 1844475127..9fec3729c7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -201,9 +201,9 @@ object ImageUtil { val imageHeight = options.outHeight val imageWidth = options.outWidth - val splitHeight = getDisplayHeightInPx + val splitHeight = getDisplayMaxHeightInPx // -1 so it doesn't try to split when imageHeight = getDisplayHeightInPx - val partCount = (imageHeight - 1) / getDisplayHeightInPx + 1 + val partCount = (imageHeight - 1) / getDisplayMaxHeightInPx + 1 logcat { "Splitting ${imageHeight}px height image into $partCount part with estimated ${splitHeight}px per height" }