intermediate commit
This commit is contained in:
parent
1cbbee6b80
commit
cb39937594
|
@ -40,7 +40,9 @@ data class VideoPlayerUIState(
|
|||
val playbackPositionInMs: Long,
|
||||
val fastseekSeconds: Int,
|
||||
val soundVolume: Float,
|
||||
val brightnes: Float
|
||||
|
||||
// when null use system value
|
||||
val brightnes: Float?
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
val DEFAULT = VideoPlayerUIState(
|
||||
|
@ -58,7 +60,7 @@ data class VideoPlayerUIState(
|
|||
playbackPositionInMs = 0,
|
||||
fastseekSeconds = 0,
|
||||
soundVolume = 0f,
|
||||
brightnes = 0f
|
||||
brightnes = null
|
||||
)
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ interface VideoPlayerViewModel {
|
|||
fun embeddedDraggedDown(offset: Float)
|
||||
fun fastSeek(count: Int)
|
||||
fun finishFastSeek()
|
||||
fun brightnesChange(changeRate: Float)
|
||||
fun brightnesChange(changeRate: Float, currentValue: Float)
|
||||
fun volumeChange(changeRate: Float)
|
||||
|
||||
interface Listener {
|
||||
|
|
|
@ -69,7 +69,6 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
|||
var callbackListeners: MutableList<VideoPlayerViewModel.Listener?> = ArrayList()
|
||||
|
||||
init {
|
||||
|
||||
val soundVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat() /
|
||||
audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC).toFloat()
|
||||
mutableUiState.update {
|
||||
|
@ -304,7 +303,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun brightnesChange(changeRate: Float) {
|
||||
override fun brightnesChange(changeRate: Float, currentValue: Float) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
@ -407,7 +406,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
|||
println("dummy impl")
|
||||
}
|
||||
|
||||
override fun brightnesChange(changeRate: Float) {
|
||||
override fun brightnesChange(changeRate: Float, currentValue: Float) {
|
||||
println("dummy impl")
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ fun VideoPlayerControllerUI(
|
|||
embeddedDraggedDownBy: (Float) -> Unit,
|
||||
fastSeek: (Int) -> Unit,
|
||||
finishFastSeek: () -> Unit,
|
||||
brightnesChange: (Float) -> Unit,
|
||||
brightnesChange: (Float, Float) -> Unit,
|
||||
volumeChange: (Float) -> Unit
|
||||
) {
|
||||
|
||||
|
@ -88,6 +88,10 @@ fun VideoPlayerControllerUI(
|
|||
}
|
||||
}
|
||||
|
||||
val internalBrightnesChange = { rateChange: Float ->
|
||||
|
||||
}
|
||||
|
||||
val insets =
|
||||
WindowInsets.systemBars
|
||||
.union(WindowInsets.displayCutout)
|
||||
|
@ -110,7 +114,7 @@ fun VideoPlayerControllerUI(
|
|||
embeddedDraggedDownBy = embeddedDraggedDownBy,
|
||||
fastSeek = fastSeek,
|
||||
fastSeekFinished = finishFastSeek,
|
||||
brightnesChange = brightnesChange,
|
||||
brightnesChange = internalBrightnesChange,
|
||||
volumeChange = volumeChange
|
||||
)
|
||||
}
|
||||
|
@ -151,7 +155,7 @@ fun VideoPlayerControllerUI(
|
|||
fastSeek = fastSeek,
|
||||
fastSeekFinished = finishFastSeek,
|
||||
volumeChange = volumeChange,
|
||||
brightnesChange = brightnesChange
|
||||
brightnesChange = internalBrightnesChange
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
|
@ -250,7 +254,7 @@ fun VideoPlayerControllerUIPreviewEmbedded() {
|
|||
embeddedDraggedDownBy = {},
|
||||
fastSeek = {},
|
||||
finishFastSeek = {},
|
||||
brightnesChange = {},
|
||||
internalBrightnesChange = { a, b ->},
|
||||
volumeChange = {})
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +289,7 @@ fun VideoPlayerControllerUIPreviewLandscape() {
|
|||
embeddedDraggedDownBy = {},
|
||||
fastSeek = {},
|
||||
finishFastSeek = {},
|
||||
brightnesChange = {},
|
||||
internalBrightnesChange = { a, b -> },
|
||||
volumeChange = {})
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +325,7 @@ fun VideoPlayerControllerUIPreviewPortrait() {
|
|||
embeddedDraggedDownBy = {},
|
||||
fastSeek = {},
|
||||
finishFastSeek = {},
|
||||
brightnesChange = {},
|
||||
internalBrightnesChange = { a, b -> },
|
||||
volumeChange = {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ fun VideoPlayerUI(
|
|||
fastSeek = viewModel::fastSeek,
|
||||
finishFastSeek = viewModel::finishFastSeek,
|
||||
volumeChange = viewModel::volumeChange,
|
||||
brightnesChange = viewModel::brightnesChange
|
||||
internalBrightnesChange = viewModel::brightnesChange
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@
|
|||
|
||||
package net.newpipe.newplayer.ui.theme
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import net.newpipe.newplayer.ui.PreviewBackgroundSurface
|
||||
|
@ -99,7 +96,7 @@ fun VideoPlayerControllerUIPreviewEmbeddedColorPreview() {
|
|||
embeddedDraggedDownBy = {},
|
||||
fastSeek = {},
|
||||
finishFastSeek = {},
|
||||
brightnesChange = {},
|
||||
internalBrightnesChange = {},
|
||||
volumeChange = {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,10 +160,9 @@ fun VideoPlayerControllerBottomUIPreview() {
|
|||
bufferedPercentage = 0.4f,
|
||||
switchToFullscreen = { },
|
||||
switchToEmbeddedView = { },
|
||||
seekPositionChanged = {}
|
||||
) {
|
||||
|
||||
}
|
||||
seekPositionChanged = {},
|
||||
seekingFinished = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,9 +20,11 @@
|
|||
|
||||
package net.newpipe.newplayer.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.view.WindowManager
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
@ -41,6 +43,25 @@ fun LockScreenOrientation(orientation: Int) {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Composable
|
||||
fun getScreenBrightnes() : Float {
|
||||
val activity = LocalContext.current.findActivity()!!
|
||||
val window = activity.window
|
||||
val layout = window.attributes as WindowManager.LayoutParams
|
||||
return layout.screenBrightness
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Composable
|
||||
fun SetScreenBrightnes(value:Float) {
|
||||
val activity = LocalContext.current.findActivity()!!
|
||||
val window = activity.window
|
||||
val layout = window.attributes as WindowManager.LayoutParams
|
||||
layout.screenBrightness = value
|
||||
window.attributes = layout
|
||||
}
|
||||
|
||||
fun Context.findActivity(): Activity? = when (this) {
|
||||
is Activity -> this
|
||||
is ContextWrapper -> baseContext.findActivity()
|
||||
|
|
Loading…
Reference in New Issue