mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-29 21:37:56 +01:00 
			
		
		
		
	Migrate reader low brightness overlay to Compose
This commit is contained in:
		| @@ -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.Column | ||||
| import androidx.compose.foundation.layout.Spacer | ||||
| import androidx.compose.foundation.layout.WindowInsets | ||||
| import androidx.compose.foundation.layout.fillMaxHeight | ||||
| import androidx.compose.foundation.layout.systemBars | ||||
| import androidx.compose.foundation.layout.windowInsetsPadding | ||||
| import androidx.compose.foundation.layout.systemBarsPadding | ||||
| import androidx.compose.material.icons.Icons | ||||
| import androidx.compose.material.icons.outlined.Bookmark | ||||
| import androidx.compose.material.icons.outlined.BookmarkBorder | ||||
| @@ -70,7 +68,7 @@ fun ReaderAppBars( | ||||
|         .copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f) | ||||
|  | ||||
|     val appBarModifier = if (fullscreen) { | ||||
|         Modifier.windowInsetsPadding(WindowInsets.systemBars) | ||||
|         Modifier.systemBarsPadding() | ||||
|     } else { | ||||
|         Modifier | ||||
|     } | ||||
|   | ||||
| @@ -42,6 +42,7 @@ import com.google.android.material.elevation.SurfaceColors | ||||
| import com.google.android.material.transition.platform.MaterialContainerTransform | ||||
| import dev.chrisbanes.insetter.applyInsetter | ||||
| import eu.kanade.domain.base.BasePreferences | ||||
| import eu.kanade.presentation.reader.BrightnessOverlay | ||||
| import eu.kanade.presentation.reader.OrientationModeSelectDialog | ||||
| import eu.kanade.presentation.reader.PageIndicatorText | ||||
| import eu.kanade.presentation.reader.ReaderPageActionsDialog | ||||
| @@ -377,6 +378,10 @@ class ReaderActivity : BaseActivity() { | ||||
|                 onClickSettings = viewModel::openSettingsDialog, | ||||
|             ) | ||||
|  | ||||
|             BrightnessOverlay( | ||||
|                 value = state.brightnessOverlayValue, | ||||
|             ) | ||||
|  | ||||
|             val onDismissRequest = viewModel::closeDialog | ||||
|             when (state.dialog) { | ||||
|                 is ReaderViewModel.Dialog.Loading -> { | ||||
| @@ -903,17 +908,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) | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|   | ||||
| @@ -736,6 +736,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. | ||||
| @@ -894,6 +898,7 @@ class ReaderViewModel @JvmOverloads constructor( | ||||
|         val viewer: Viewer? = null, | ||||
|         val dialog: Dialog? = null, | ||||
|         val menuVisible: Boolean = false, | ||||
|         val brightnessOverlayValue: Int = 0, | ||||
|     ) { | ||||
|         val currentChapter: ReaderChapter? | ||||
|             get() = viewerChapters?.currChapter | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user