Migrate reader low brightness overlay to Compose

(cherry picked from commit d9c0b1ce7d1739da3945622f2d18b171a471fc2e)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt
This commit is contained in:
arkon 2023-10-24 22:21:17 -04:00 committed by Jobobby04
parent ae6586be2b
commit d949e738f0
5 changed files with 40 additions and 24 deletions

View File

@ -0,0 +1,26 @@
package eu.kanade.presentation.reader
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import kotlin.math.abs
@Composable
fun BrightnessOverlay(
value: Int,
) {
if (value >= 0) return
Canvas(
modifier = Modifier
.fillMaxSize()
.graphicsLayer {
alpha = abs(value) / 100f
}
) {
drawRect(Color.Black)
}
}

View File

@ -13,14 +13,10 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
@ -114,7 +110,7 @@ fun ReaderAppBars(
onClickChapterList: () -> Unit,
onClickPageLayout: () -> Unit,
onClickShiftPage: () -> Unit,
// SY <--
) {
val isRtl = viewer is R2LPagerViewer
val backgroundColor = MaterialTheme.colorScheme
@ -122,9 +118,7 @@ fun ReaderAppBars(
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
val appBarModifier = if (fullscreen) {
// SY -->
Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal))
// SY <--
Modifier.systemBarsPadding()
} else {
Modifier
}

View File

@ -51,6 +51,7 @@ import com.google.android.material.transition.platform.MaterialContainerTransfor
import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.manga.model.readingModeType
import eu.kanade.presentation.reader.BrightnessOverlay
import eu.kanade.presentation.reader.ChapterListDialog
import eu.kanade.presentation.reader.OrientationModeSelectDialog
import eu.kanade.presentation.reader.PageIndicatorText
@ -478,6 +479,10 @@ class ReaderActivity : BaseActivity() {
// SY <--
)
BrightnessOverlay(
value = state.brightnessOverlayValue,
)
val onDismissRequest = viewModel::closeDialog
when (state.dialog) {
is ReaderViewModel.Dialog.Loading -> {
@ -1294,17 +1299,9 @@ class ReaderActivity : BaseActivity() {
}
else -> WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
}
window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
// Set black overlay visibility.
if (value < 0) {
binding.brightnessOverlay.isVisible = true
val alpha = (abs(value) * 2.56).toInt()
binding.brightnessOverlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
} else {
binding.brightnessOverlay.isVisible = false
}
viewModel.setBrightnessOverlayValue(value)
}
/**

View File

@ -960,6 +960,10 @@ class ReaderViewModel @JvmOverloads constructor(
mutableState.update { it.copy(dialog = null) }
}
fun setBrightnessOverlayValue(value: Int) {
mutableState.update { it.copy(brightnessOverlayValue = value) }
}
/**
* Saves the image of the selected page on the pictures directory and notifies the UI of the result.
* There's also a notification to allow sharing the image somewhere else or deleting it.
@ -1244,6 +1248,7 @@ class ReaderViewModel @JvmOverloads constructor(
val viewer: Viewer? = null,
val dialog: Dialog? = null,
val menuVisible: Boolean = false,
val brightnessOverlayValue: Int = 0,
// SY -->
val currentPageText: String = "",

View File

@ -35,12 +35,6 @@
android:focusable="false"
android:visibility="gone" />
<View
android:id="@+id/brightness_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<androidx.compose.ui.platform.ComposeView
android:id="@+id/dialog_root"
android:layout_width="match_parent"