From c254aa6fcc511eb572f8337a776e4d9cee0cfe8e Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 8 Jul 2021 00:12:11 +0200 Subject: [PATCH] Make Automatic Reader Theme pick background/text color based on dark mode preference (#5505) * Make Automatic Reader Theme pick background/text color based on theme * Use extension method --- .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 12 ++++++++++++ .../ui/reader/viewer/ReaderTransitionView.kt | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index f3bedcaefd..74a97dad20 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -854,6 +854,7 @@ class ReaderActivity : BaseRxActivity() when (preferences.readerTheme().get()) { 0 -> android.R.color.white 2 -> R.color.reader_background_dark + 3 -> automaticBackgroundColor() else -> android.R.color.black } ) @@ -902,6 +903,17 @@ class ReaderActivity : BaseRxActivity() .launchIn(lifecycleScope) } + /** + * Picks background color for [ReaderActivity] based on light/dark theme preference + */ + private fun automaticBackgroundColor(): Int { + return if (baseContext.isNightMode()) { + R.color.reader_background_dark + } else { + android.R.color.white + } + } + /** * Sets the visibility of the bottom page indicator according to [visible]. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt index d1d8a541c4..570eda886c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderTransitionView.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ReaderTransitionViewBinding import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition +import eu.kanade.tachiyomi.util.system.isNightMode import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -23,7 +24,6 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At binding = ReaderTransitionViewBinding.inflate(LayoutInflater.from(context), this, true) layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) } - fun bind(transition: ChapterTransition) { when (transition) { is ChapterTransition.Prev -> bindPrevChapterTransition(transition) @@ -34,6 +34,7 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At val color = when (Injekt.get().readerTheme().get()) { 0 -> context.getColor(android.R.color.black) + 3 -> context.getColor(automaticTextColor()) else -> context.getColor(android.R.color.white) } listOf(binding.upperText, binding.warningText, binding.lowerText).forEach { @@ -41,6 +42,17 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At } } + /** + * Picks text color for [ReaderActivity] based on light/dark theme preference + */ + private fun automaticTextColor(): Int { + return if (context.isNightMode()) { + android.R.color.white + } else { + android.R.color.black + } + } + /** * Binds a previous chapter transition on this view and subscribes to the page load status. */