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 playbackPositionInMs: Long,
val fastseekSeconds: Int, val fastseekSeconds: Int,
val soundVolume: Float, val soundVolume: Float,
val brightnes: Float
// when null use system value
val brightnes: Float?
) : Parcelable { ) : Parcelable {
companion object { companion object {
val DEFAULT = VideoPlayerUIState( val DEFAULT = VideoPlayerUIState(
@ -58,7 +60,7 @@ data class VideoPlayerUIState(
playbackPositionInMs = 0, playbackPositionInMs = 0,
fastseekSeconds = 0, fastseekSeconds = 0,
soundVolume = 0f, soundVolume = 0f,
brightnes = 0f brightnes = null
) )
} }
} }

View File

@ -50,7 +50,7 @@ interface VideoPlayerViewModel {
fun embeddedDraggedDown(offset: Float) fun embeddedDraggedDown(offset: Float)
fun fastSeek(count: Int) fun fastSeek(count: Int)
fun finishFastSeek() fun finishFastSeek()
fun brightnesChange(changeRate: Float) fun brightnesChange(changeRate: Float, currentValue: Float)
fun volumeChange(changeRate: Float) fun volumeChange(changeRate: Float)
interface Listener { interface Listener {

View File

@ -69,7 +69,6 @@ class VideoPlayerViewModelImpl @Inject constructor(
var callbackListeners: MutableList<VideoPlayerViewModel.Listener?> = ArrayList() var callbackListeners: MutableList<VideoPlayerViewModel.Listener?> = ArrayList()
init { init {
val soundVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat() / val soundVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat() /
audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC).toFloat() audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC).toFloat()
mutableUiState.update { 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") TODO("Not yet implemented")
} }
@ -407,7 +406,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
println("dummy impl") println("dummy impl")
} }
override fun brightnesChange(changeRate: Float) { override fun brightnesChange(changeRate: Float, currentValue: Float) {
println("dummy impl") println("dummy impl")
} }

View File

@ -78,7 +78,7 @@ fun VideoPlayerControllerUI(
embeddedDraggedDownBy: (Float) -> Unit, embeddedDraggedDownBy: (Float) -> Unit,
fastSeek: (Int) -> Unit, fastSeek: (Int) -> Unit,
finishFastSeek: () -> Unit, finishFastSeek: () -> Unit,
brightnesChange: (Float) -> Unit, brightnesChange: (Float, Float) -> Unit,
volumeChange: (Float) -> Unit volumeChange: (Float) -> Unit
) { ) {
@ -88,6 +88,10 @@ fun VideoPlayerControllerUI(
} }
} }
val internalBrightnesChange = { rateChange: Float ->
}
val insets = val insets =
WindowInsets.systemBars WindowInsets.systemBars
.union(WindowInsets.displayCutout) .union(WindowInsets.displayCutout)
@ -110,7 +114,7 @@ fun VideoPlayerControllerUI(
embeddedDraggedDownBy = embeddedDraggedDownBy, embeddedDraggedDownBy = embeddedDraggedDownBy,
fastSeek = fastSeek, fastSeek = fastSeek,
fastSeekFinished = finishFastSeek, fastSeekFinished = finishFastSeek,
brightnesChange = brightnesChange, brightnesChange = internalBrightnesChange,
volumeChange = volumeChange volumeChange = volumeChange
) )
} }
@ -151,7 +155,7 @@ fun VideoPlayerControllerUI(
fastSeek = fastSeek, fastSeek = fastSeek,
fastSeekFinished = finishFastSeek, fastSeekFinished = finishFastSeek,
volumeChange = volumeChange, volumeChange = volumeChange,
brightnesChange = brightnesChange brightnesChange = internalBrightnesChange
) )
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
@ -250,7 +254,7 @@ fun VideoPlayerControllerUIPreviewEmbedded() {
embeddedDraggedDownBy = {}, embeddedDraggedDownBy = {},
fastSeek = {}, fastSeek = {},
finishFastSeek = {}, finishFastSeek = {},
brightnesChange = {}, internalBrightnesChange = { a, b ->},
volumeChange = {}) volumeChange = {})
} }
} }
@ -285,7 +289,7 @@ fun VideoPlayerControllerUIPreviewLandscape() {
embeddedDraggedDownBy = {}, embeddedDraggedDownBy = {},
fastSeek = {}, fastSeek = {},
finishFastSeek = {}, finishFastSeek = {},
brightnesChange = {}, internalBrightnesChange = { a, b -> },
volumeChange = {}) volumeChange = {})
} }
} }
@ -321,7 +325,7 @@ fun VideoPlayerControllerUIPreviewPortrait() {
embeddedDraggedDownBy = {}, embeddedDraggedDownBy = {},
fastSeek = {}, fastSeek = {},
finishFastSeek = {}, finishFastSeek = {},
brightnesChange = {}, internalBrightnesChange = { a, b -> },
volumeChange = {}) volumeChange = {})
} }
} }

View File

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

View File

@ -20,10 +20,7 @@
package net.newpipe.newplayer.ui.theme 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.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.ui.PreviewBackgroundSurface import net.newpipe.newplayer.ui.PreviewBackgroundSurface
@ -99,7 +96,7 @@ fun VideoPlayerControllerUIPreviewEmbeddedColorPreview() {
embeddedDraggedDownBy = {}, embeddedDraggedDownBy = {},
fastSeek = {}, fastSeek = {},
finishFastSeek = {}, finishFastSeek = {},
brightnesChange = {}, internalBrightnesChange = {},
volumeChange = {}) volumeChange = {})
} }
} }

View File

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

View File

@ -20,9 +20,11 @@
package net.newpipe.newplayer.utils package net.newpipe.newplayer.utils
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.ContextWrapper import android.content.ContextWrapper
import android.view.WindowManager
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext 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) { fun Context.findActivity(): Activity? = when (this) {
is Activity -> this is Activity -> this
is ContextWrapper -> baseContext.findActivity() is ContextWrapper -> baseContext.findActivity()