Migrate reader low brightness overlay to Compose
This commit is contained in:
parent
0a0b686119
commit
d9c0b1ce7d
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,8 @@ import androidx.compose.foundation.isSystemInDarkTheme
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.systemBars
|
import androidx.compose.foundation.layout.systemBarsPadding
|
||||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Bookmark
|
import androidx.compose.material.icons.outlined.Bookmark
|
||||||
import androidx.compose.material.icons.outlined.BookmarkBorder
|
import androidx.compose.material.icons.outlined.BookmarkBorder
|
||||||
@ -70,7 +68,7 @@ fun ReaderAppBars(
|
|||||||
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
|
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
|
||||||
|
|
||||||
val appBarModifier = if (fullscreen) {
|
val appBarModifier = if (fullscreen) {
|
||||||
Modifier.windowInsetsPadding(WindowInsets.systemBars)
|
Modifier.systemBarsPadding()
|
||||||
} else {
|
} else {
|
||||||
Modifier
|
Modifier
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import com.google.android.material.elevation.SurfaceColors
|
|||||||
import com.google.android.material.transition.platform.MaterialContainerTransform
|
import com.google.android.material.transition.platform.MaterialContainerTransform
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.applyInsetter
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
|
import eu.kanade.presentation.reader.BrightnessOverlay
|
||||||
import eu.kanade.presentation.reader.OrientationModeSelectDialog
|
import eu.kanade.presentation.reader.OrientationModeSelectDialog
|
||||||
import eu.kanade.presentation.reader.PageIndicatorText
|
import eu.kanade.presentation.reader.PageIndicatorText
|
||||||
import eu.kanade.presentation.reader.ReaderPageActionsDialog
|
import eu.kanade.presentation.reader.ReaderPageActionsDialog
|
||||||
@ -377,6 +378,10 @@ class ReaderActivity : BaseActivity() {
|
|||||||
onClickSettings = viewModel::openSettingsDialog,
|
onClickSettings = viewModel::openSettingsDialog,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BrightnessOverlay(
|
||||||
|
value = state.brightnessOverlayValue,
|
||||||
|
)
|
||||||
|
|
||||||
val onDismissRequest = viewModel::closeDialog
|
val onDismissRequest = viewModel::closeDialog
|
||||||
when (state.dialog) {
|
when (state.dialog) {
|
||||||
is ReaderViewModel.Dialog.Loading -> {
|
is ReaderViewModel.Dialog.Loading -> {
|
||||||
@ -903,17 +908,9 @@ class ReaderActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
else -> WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
else -> WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
|
window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
|
||||||
|
|
||||||
// Set black overlay visibility.
|
viewModel.setBrightnessOverlayValue(value)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -736,6 +736,10 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
mutableState.update { it.copy(dialog = null) }
|
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.
|
* 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.
|
* There's also a notification to allow sharing the image somewhere else or deleting it.
|
||||||
@ -894,6 +898,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
val viewer: Viewer? = null,
|
val viewer: Viewer? = null,
|
||||||
val dialog: Dialog? = null,
|
val dialog: Dialog? = null,
|
||||||
val menuVisible: Boolean = false,
|
val menuVisible: Boolean = false,
|
||||||
|
val brightnessOverlayValue: Int = 0,
|
||||||
) {
|
) {
|
||||||
val currentChapter: ReaderChapter?
|
val currentChapter: ReaderChapter?
|
||||||
get() = viewerChapters?.currChapter
|
get() = viewerChapters?.currChapter
|
||||||
|
@ -35,12 +35,6 @@
|
|||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:visibility="gone" />
|
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
|
<androidx.compose.ui.platform.ComposeView
|
||||||
android:id="@+id/dialog_root"
|
android:id="@+id/dialog_root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user