Match WebGPU reader background and transition colors to the old reader (#3765)

Assisted-by: Claude:claude-opus-5
This commit is contained in:
AntsyLich
2026-08-15 02:50:56 +06:00
committed by GitHub
parent b1efee47f5
commit ed30766a9f
3 changed files with 34 additions and 29 deletions
@@ -82,6 +82,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.webgpu.WebGpuViewer
import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.isNightMode import eu.kanade.tachiyomi.util.system.isNightMode
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.readerBackgroundColor
import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.setComposeContent import eu.kanade.tachiyomi.util.view.setComposeContent
@@ -857,22 +858,13 @@ class ReaderActivity : BaseActivity() {
} }
} }
private val grayBackgroundColor = Color.rgb(0x20, 0x21, 0x25)
/* /*
* Initializes the reader subscriptions. * Initializes the reader subscriptions.
*/ */
init { init {
readerPreferences.readerTheme.changes() readerPreferences.readerTheme.changes()
.onEach { theme -> .onEach { theme ->
binding.readerContainer.setBackgroundColor( binding.readerContainer.setBackgroundColor(baseContext.readerBackgroundColor(theme))
when (theme) {
0 -> Color.WHITE
2 -> grayBackgroundColor
3 -> automaticBackgroundColor()
else -> Color.BLACK
},
)
} }
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
@@ -907,17 +899,6 @@ class ReaderActivity : BaseActivity() {
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
} }
/**
* Picks background color for [ReaderActivity] based on light/dark theme preference
*/
private fun automaticBackgroundColor(): Int {
return if (baseContext.isNightMode()) {
grayBackgroundColor
} else {
Color.WHITE
}
}
/** /**
* Sets the display profile to [path]. * Sets the display profile to [path].
*/ */
@@ -30,6 +30,7 @@ import ca.mpreg.webgpuviewer.transition.TransitionStackLeft
import ca.mpreg.webgpuviewer.transition.TransitionStackRight import ca.mpreg.webgpuviewer.transition.TransitionStackRight
import ca.mpreg.webgpuviewer.transition.TransitionStackUp import ca.mpreg.webgpuviewer.transition.TransitionStackUp
import ca.mpreg.webgpuviewer.viewer.ImagePage import ca.mpreg.webgpuviewer.viewer.ImagePage
import com.google.android.material.color.MaterialColors
import de.stefan_oltmann.kim.Kim import de.stefan_oltmann.kim.Kim
import de.stefan_oltmann.kim.android.readMetadata import de.stefan_oltmann.kim.android.readMetadata
import de.stefan_oltmann.kim.format.tiff.constant.TiffTag import de.stefan_oltmann.kim.format.tiff.constant.TiffTag
@@ -43,6 +44,8 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences.TransitionAnimati
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView.ZoomStartPosition import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView.ZoomStartPosition
import eu.kanade.tachiyomi.ui.reader.viewer.Viewer import eu.kanade.tachiyomi.ui.reader.viewer.Viewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation.NavigationRegion import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation.NavigationRegion
import eu.kanade.tachiyomi.util.system.createReaderThemeContext
import eu.kanade.tachiyomi.util.system.readerBackgroundColor
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
@@ -62,6 +65,14 @@ open class WebGpuViewer(
open val isContinuous: Boolean = false open val isContinuous: Boolean = false
private fun readerBackgroundColor(): Int = activity.baseContext.readerBackgroundColor(config.theme)
private fun readerOnBackgroundColor(): Int = MaterialColors.getColor(
activity.createReaderThemeContext(),
com.google.android.material.R.attr.colorOnBackground,
Color.WHITE,
)
private val scope = MainScope() private val scope = MainScope()
// Dedicated thread for decode worker to avoid blocking Dispatchers.Default pool // Dedicated thread for decode worker to avoid blocking Dispatchers.Default pool
@@ -773,12 +784,10 @@ open class WebGpuViewer(
null null
} }
val backgroundColor = when { val backgroundColor = if (config.automaticBackground) {
config.automaticBackground -> null null
config.theme == 0 -> 0xFFFFFFFF.toInt() } else {
config.theme == 1 -> 0xFF000000.toInt() readerBackgroundColor()
config.theme == 2 -> 0xFF808080.toInt()
else -> 0xFF000000.toInt()
} }
val firstImage = Image.createWithTrim( val firstImage = Image.createWithTrim(
@@ -848,10 +857,10 @@ open class WebGpuViewer(
val bitmap = createBitmap(pager.state.width, pager.state.height) val bitmap = createBitmap(pager.state.width, pager.state.height)
val canvas = Canvas(bitmap) val canvas = Canvas(bitmap)
canvas.drawColor(Color.BLACK) canvas.drawColor(readerBackgroundColor())
val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE color = readerOnBackgroundColor()
textSize = 48f textSize = 48f
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
} }
@@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.PowerManager import android.os.PowerManager
@@ -98,6 +99,20 @@ fun Context.createFileInCacheDir(name: String): File {
return file return file
} }
private val ReaderGrayBackgroundColor = Color.rgb(0x20, 0x21, 0x25)
/**
* Background color of the reader for the given [readerTheme] preference value.
*
* Automatic (3) resolves against the current night mode, matching the activity background.
*/
fun Context.readerBackgroundColor(readerTheme: Int): Int = when (readerTheme) {
0 -> Color.WHITE // White
2 -> ReaderGrayBackgroundColor // Gray
3 -> if (isNightMode()) ReaderGrayBackgroundColor else Color.WHITE // Automatic
else -> Color.BLACK // Black
}
/** /**
* Creates night mode Context depending on reader theme/background * Creates night mode Context depending on reader theme/background
* *