From 9eaea6507d5180ccf8201cfb245c73785593003c Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 7 Apr 2021 00:34:36 -0400 Subject: [PATCH] Reader Smart BG no longer does gradient backgrounds in landscape --- .../ui/reader/viewer/pager/PagerPageHolder.kt | 2 +- .../kanade/tachiyomi/util/system/ImageUtil.kt | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 5ad3cdf395..848affee2a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -724,7 +724,7 @@ class PagerPageHolder( fun getBGType(readerTheme: Int, context: Context): Int { return if (readerTheme == 3) { if (context.isInNightMode()) 2 else 1 - } else 0 + } else 0 + (context.resources.configuration?.orientation ?: 0) * 10 } } } 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 08f89550f3..3ed26ad53a 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.util.system import android.content.Context +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Color import android.graphics.drawable.ColorDrawable @@ -203,31 +204,36 @@ object ImageUtil { if (topIsBlackStreak && bottomIsBlackStreak) { darkBG = true } + val isLandscape = context.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE if (darkBG) { - return if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) GradientDrawable( + return if (!isLandscape && isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(blackPixel, blackPixel, backgroundColor, backgroundColor) ) - else if (isWhite(image.getPixel(left, top)) && isWhite(image.getPixel(right, top))) GradientDrawable( + else if (!isLandscape && isWhite(image.getPixel(left, top)) && isWhite(image.getPixel(right, top))) GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(backgroundColor, backgroundColor, blackPixel, blackPixel) ) else ColorDrawable(blackPixel) } - if (topIsBlackStreak || ( - topLeftIsDark && topRightIsDark && - isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top)) && - (topMidIsDark || overallBlackPixels > 9) + if (!isLandscape && ( + topIsBlackStreak || ( + topLeftIsDark && topRightIsDark && + isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top)) && + (topMidIsDark || overallBlackPixels > 9) + ) ) ) { return GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(blackPixel, blackPixel, backgroundColor, backgroundColor) ) - } else if (bottomIsBlackStreak || ( - botLeftIsDark && botRightIsDark && - isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot)) && - (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9) + } else if (!isLandscape && ( + bottomIsBlackStreak || ( + botLeftIsDark && botRightIsDark && + isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot)) && + (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9) + ) ) ) { return GradientDrawable(