intermediate commit

This commit is contained in:
Christian Schabesberger 2024-08-08 16:12:56 +02:00
parent 1cbbee6b80
commit cb39937594
8 changed files with 43 additions and 21 deletions

View File

@ -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
)
}
}

View File

@ -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 {

View File

@ -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")
}

View File

@ -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 = {})
}
}

View File

@ -169,7 +169,7 @@ fun VideoPlayerUI(
fastSeek = viewModel::fastSeek,
finishFastSeek = viewModel::finishFastSeek,
volumeChange = viewModel::volumeChange,
brightnesChange = viewModel::brightnesChange
internalBrightnesChange = viewModel::brightnesChange
)
}
}

View File

@ -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 = {})
}
}

View File

@ -160,10 +160,9 @@ fun VideoPlayerControllerBottomUIPreview() {
bufferedPercentage = 0.4f,
switchToFullscreen = { },
switchToEmbeddedView = { },
seekPositionChanged = {}
) {
}
seekPositionChanged = {},
seekingFinished = {}
)
}
}
}

View File

@ -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()