Match WebGPU reader background and transition colors to the old reader (#3765)
Assisted-by: Claude:claude-opus-5
This commit is contained in:
@@ -82,6 +82,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.webgpu.WebGpuViewer
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.system.isNightMode
|
||||
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.toast
|
||||
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.
|
||||
*/
|
||||
init {
|
||||
readerPreferences.readerTheme.changes()
|
||||
.onEach { theme ->
|
||||
binding.readerContainer.setBackgroundColor(
|
||||
when (theme) {
|
||||
0 -> Color.WHITE
|
||||
2 -> grayBackgroundColor
|
||||
3 -> automaticBackgroundColor()
|
||||
else -> Color.BLACK
|
||||
},
|
||||
)
|
||||
binding.readerContainer.setBackgroundColor(baseContext.readerBackgroundColor(theme))
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
@@ -907,17 +899,6 @@ class ReaderActivity : BaseActivity() {
|
||||
.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].
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import ca.mpreg.webgpuviewer.transition.TransitionStackLeft
|
||||
import ca.mpreg.webgpuviewer.transition.TransitionStackRight
|
||||
import ca.mpreg.webgpuviewer.transition.TransitionStackUp
|
||||
import ca.mpreg.webgpuviewer.viewer.ImagePage
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import de.stefan_oltmann.kim.Kim
|
||||
import de.stefan_oltmann.kim.android.readMetadata
|
||||
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.Viewer
|
||||
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.MainScope
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
@@ -62,6 +65,14 @@ open class WebGpuViewer(
|
||||
|
||||
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()
|
||||
|
||||
// Dedicated thread for decode worker to avoid blocking Dispatchers.Default pool
|
||||
@@ -773,12 +784,10 @@ open class WebGpuViewer(
|
||||
null
|
||||
}
|
||||
|
||||
val backgroundColor = when {
|
||||
config.automaticBackground -> null
|
||||
config.theme == 0 -> 0xFFFFFFFF.toInt()
|
||||
config.theme == 1 -> 0xFF000000.toInt()
|
||||
config.theme == 2 -> 0xFF808080.toInt()
|
||||
else -> 0xFF000000.toInt()
|
||||
val backgroundColor = if (config.automaticBackground) {
|
||||
null
|
||||
} else {
|
||||
readerBackgroundColor()
|
||||
}
|
||||
|
||||
val firstImage = Image.createWithTrim(
|
||||
@@ -848,10 +857,10 @@ open class WebGpuViewer(
|
||||
|
||||
val bitmap = createBitmap(pager.state.width, pager.state.height)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawColor(Color.BLACK)
|
||||
canvas.drawColor(readerBackgroundColor())
|
||||
|
||||
val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = Color.WHITE
|
||||
color = readerOnBackgroundColor()
|
||||
textSize = 48f
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
@@ -98,6 +99,20 @@ fun Context.createFileInCacheDir(name: String): 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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user