From 427fbfdf5e58478bd9b6d35e3137f2a22db9fd96 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 3 Dec 2023 15:56:51 -0500 Subject: [PATCH] Minor cleanup --- .../presentation/reader/ReaderContentOverlay.kt | 16 +++++++++++----- .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 8 +++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/reader/ReaderContentOverlay.kt b/app/src/main/java/eu/kanade/presentation/reader/ReaderContentOverlay.kt index a1ef262226..4f72ac9af1 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ReaderContentOverlay.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ReaderContentOverlay.kt @@ -5,6 +5,7 @@ import androidx.annotation.IntRange import androidx.compose.foundation.Canvas import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Color @@ -15,14 +16,19 @@ import kotlin.math.abs fun ReaderContentOverlay( @IntRange(from = -100, to = 100) brightness: Int, @ColorInt color: Int?, - colorBlendMode: BlendMode? = BlendMode.SrcOver, + colorBlendMode: BlendMode?, + modifier: Modifier = Modifier, ) { if (brightness < 0) { + val brightnessAlpha = remember(brightness) { + abs(brightness) / 100f + } + Canvas( - modifier = Modifier + modifier = modifier .fillMaxSize() .graphicsLayer { - alpha = abs(brightness) / 100f + alpha = brightnessAlpha }, ) { drawRect(Color.Black) @@ -31,12 +37,12 @@ fun ReaderContentOverlay( if (color != null) { Canvas( - modifier = Modifier + modifier = modifier .fillMaxSize(), ) { drawRect( color = Color(color), - blendMode = colorBlendMode, + blendMode = colorBlendMode ?: BlendMode.SrcOver, ) } } 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 dbd732fa17..c67a490840 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 @@ -88,7 +88,6 @@ import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchNonCancellable import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.system.logcat -import tachiyomi.domain.manga.model.Manga import tachiyomi.i18n.MR import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt @@ -183,7 +182,7 @@ class ReaderActivity : BaseActivity() { .map { it.manga } .distinctUntilChanged() .filterNotNull() - .onEach(::setManga) + .onEach { updateViewer() } .launchIn(lifecycleScope) viewModel.state @@ -486,10 +485,9 @@ class ReaderActivity : BaseActivity() { } /** - * Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer - * and the toolbar title. + * Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer. */ - private fun setManga(manga: Manga) { + private fun updateViewer() { val prevViewer = viewModel.state.value.viewer val newViewer = ReadingMode.toViewer(viewModel.getMangaReadingMode(), this)