From 52892da065c9b793c727e033770463783bf9cad9 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 26 Apr 2020 00:44:31 -0400 Subject: [PATCH] Theme fixes for reader Smart by theme now changes its background color on day/night switch, white theme is now actually #FFFFFF on background Continous Vertical always uses black between pages, even if using light theme Fix animated gif backgrounds --- .../ui/reader/loader/HttpPageLoader.kt | 9 ++----- .../tachiyomi/ui/reader/model/ReaderPage.kt | 2 +- .../ui/reader/viewer/pager/PagerPageHolder.kt | 24 +++++++++++++++---- .../viewer/webtoon/WebtoonPageHolder.kt | 10 ++++---- .../util/system/ContextExtensions.kt | 6 +++++ .../kanade/tachiyomi/util/system/ImageUtil.kt | 7 +++--- app/src/main/res/values-night/themes.xml | 7 ++---- app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/themes.xml | 1 + 9 files changed, 43 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt index 9b6248b8bd..535fae9a71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage +import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerPageHolder import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.system.ImageUtil import rx.Completable @@ -38,14 +39,8 @@ class HttpPageLoader( */ private val queue = PriorityBlockingQueue() - /** - * Current active subscriptions. - */ private val subscriptions = CompositeSubscription() - /** - * Preferences helper. - */ private val preferences by injectLazy() private val preloadSize = 4 @@ -233,7 +228,7 @@ class HttpPageLoader( page.bg = ImageUtil.autoSetBackground( image, readerTheme == 2, preferences.context ) - page.bgAlwaysWhite = readerTheme == 2 + page.bgType = PagerPageHolder.getBGType(readerTheme, preferences.context) stream.close() } page.stream = { chapterCache.getImageFile(imageUrl).inputStream() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ReaderPage.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ReaderPage.kt index eab73a60a4..fbca23521a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ReaderPage.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/model/ReaderPage.kt @@ -10,7 +10,7 @@ class ReaderPage( imageUrl: String? = null, var stream: (() -> InputStream)? = null, var bg: Drawable? = null, - var bgAlwaysWhite: Boolean? = null + var bgType: Int? = null ) : Page(index, url, imageUrl, null) { lateinit var chapter: ReaderChapter 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 4a7cfcaae5..e392a945ed 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import android.annotation.SuppressLint +import android.content.Context import android.content.Intent import android.graphics.BitmapFactory import android.graphics.PointF @@ -39,6 +40,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.ZoomType import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.system.isInNightMode import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visible @@ -255,8 +257,10 @@ class PagerPageHolder( if (!isAnimated) { if (viewer.config.readerTheme >= 2) { val imageView = initSubsamplingImageView() - if (page.bg != null && - page.bgAlwaysWhite == (viewer.config.readerTheme == 2)) { + if (page.bg != null && page.bgType == getBGType( + viewer.config.readerTheme, + context + )) { imageView.setImage(ImageSource.inputStream(openStream!!)) imageView.background = page.bg } @@ -270,7 +274,7 @@ class PagerPageHolder( launchUI { imageView.background = setBG(bytesArray) page.bg = imageView.background - page.bgAlwaysWhite = viewer.config.readerTheme == 2 + page.bgType = getBGType(viewer.config.readerTheme, context) } } } else { @@ -281,8 +285,12 @@ class PagerPageHolder( } else { val imageView = initImageView() imageView.setImage(openStream!!) - if (viewer.config.readerTheme >= 2 && page.bg != null) + if (viewer.config.readerTheme >= 2 && page.bg != null) { imageView.background = page.bg + } else if (viewer.config.readerTheme < 2) { + imageView.background = + ColorDrawable(ThemeUtil.readerBackgroundColor(viewer.config.readerTheme)) + } } } // Keep the Rx stream alive to close the input stream only when unsubscribed @@ -512,4 +520,12 @@ class PagerPageHolder( }) .into(this) } + + companion object { + fun getBGType(readerTheme: Int, context: Context): Int { + return if (readerTheme == 3) { + if (context.isInNightMode()) 2 else 1 + } else 0 + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index 9791798dac..4721e6811f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon import android.annotation.SuppressLint import android.content.Intent import android.content.res.Resources +import android.graphics.Color import android.graphics.drawable.Drawable import android.net.Uri import android.view.Gravity @@ -33,6 +34,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.visible import rx.Observable import rx.Subscription @@ -113,6 +115,7 @@ class WebtoonPageHolder( init { frame.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + frame.setBackgroundColor(Color.BLACK) } /** @@ -126,14 +129,13 @@ class WebtoonPageHolder( private fun refreshLayoutParams() { frame.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { - if (!viewer.isContinuous) { - bottomMargin = 15.dpToPx - } - val margin = Resources.getSystem().displayMetrics.widthPixels * (viewer.config.sidePadding / 100f) marginEnd = margin.toInt() marginStart = margin.toInt() } + if (!viewer.isContinuous) { + frame.updatePaddingRelative(bottom = 15.dpToPx) + } } /** 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 535607110b..efd7790fb8 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 @@ -8,6 +8,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.res.Configuration import android.content.res.Resources import android.net.ConnectivityManager import android.net.Uri @@ -202,3 +203,8 @@ fun Context.openInBrowser(url: String) { toast(e.message) } } + +fun Context.isInNightMode(): Boolean { + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return currentNightMode == Configuration.UI_MODE_NIGHT_YES +} 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 ffb3fde9d2..d29f508fb4 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 @@ -6,6 +6,7 @@ import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable +import eu.kanade.tachiyomi.R import java.io.InputStream import java.net.URLConnection import kotlin.math.abs @@ -56,9 +57,9 @@ object ImageUtil { return null } - fun autoSetBackground(image: Bitmap?, useWhiteAlways: Boolean, context: Context): Drawable { - val backgroundColor = if (useWhiteAlways) Color.WHITE else - context.getResourceColor(android.R.attr.colorBackground) + fun autoSetBackground(image: Bitmap?, alwaysUseWhite: Boolean, context: Context): Drawable { + val backgroundColor = if (alwaysUseWhite) Color.WHITE else + context.getResourceColor(R.attr.readerBackground) if (image == null) return ColorDrawable(backgroundColor) if (image.width < 50 || image.height < 50) return ColorDrawable(backgroundColor) diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 69a2e3eca6..fa3e17e721 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -15,13 +15,10 @@ @color/colorAmoledPrimary @color/colorAmoledPrimary @color/colorAmoledPrimary - @color/md_black_1000 + @color/colorAmoledPrimary + @color/colorAmoledPrimary - @color/textColorPrimary - @color/text_color_secondary - @color/colorAccent @color/colorAmoledPrimary - 16dp \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 0509d94f32..8b7fbbe1e2 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -12,6 +12,7 @@ + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 1d2eb0bb74..be78a805a3 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -22,6 +22,7 @@ @color/text_color_inverse_secondary @color/text_color_inverse_hint @color/background + @color/colorPrimary ?colorAccent @color/divider @drawable/line_divider