bring back embeded config

This commit is contained in:
Christian Schabesberger 2024-09-06 21:52:10 +02:00
parent 3dc5ca3e10
commit 33b0360507
8 changed files with 46 additions and 13 deletions

View File

@ -42,7 +42,7 @@ interface VideoPlayerViewModel {
fun pause()
fun prevStream()
fun nextStream()
fun switchToFullscreen()
fun switchToFullscreen(embeddedUiConfig: EmbeddedUiConfig)
fun switchToEmbeddedView()
fun onBackPressed()
fun showUi()
@ -54,7 +54,7 @@ interface VideoPlayerViewModel {
fun finishFastSeek()
fun brightnessChange(changeRate: Float, systemBrightness: Float)
fun volumeChange(changeRate: Float)
fun openStreamSelection(selectChapter: Boolean)
fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig)
fun closeStreamSelection()
fun chapterSelected(chapterId: Int)
fun streamSelected(streamId: Int)

View File

@ -438,8 +438,11 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
}
override fun openStreamSelection(selectChapter: Boolean) {
override fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig) {
uiVisibilityJob?.cancel()
if (!uiState.value.uiMode.fullscreen) {
this.embeddedUiConfig = embeddedUiConfig
}
updateUiMode(
if (selectChapter) uiState.value.uiMode.getChapterSelectUiState()
else uiState.value.uiMode.getStreamSelectUiState()
@ -472,10 +475,11 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
}
override fun switchToFullscreen() {
override fun switchToFullscreen(embeddedUiConfig: EmbeddedUiConfig) {
uiVisibilityJob?.cancel()
finishFastSeek()
this.embeddedUiConfig = embeddedUiConfig
updateUiMode(UIModeState.FULLSCREEN_VIDEO)
}

View File

@ -36,7 +36,7 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
println("dummy impl")
}
override fun switchToFullscreen() {
override fun switchToFullscreen(embeddedUiConfig: EmbeddedUiConfig) {
println("dummy impl")
}
@ -61,7 +61,7 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
}
override fun fastSeek(steps: Int) {
println("dummy impl, steps: $steps")
println("dummy impl: steps: $steps")
}
override fun finishFastSeek() {
@ -76,7 +76,7 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
println("dummy impl")
}
override fun openStreamSelection(selectChapter: Boolean) {
override fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig) {
println("dummy impl")
}

View File

@ -95,6 +95,7 @@ fun VideoPlayerUI(
// Setup fullscreen
LaunchedEffect(uiState.uiMode.fullscreen) {
if (uiState.uiMode.fullscreen) {
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars =

View File

@ -57,6 +57,7 @@ import net.newpipe.newplayer.ui.seeker.Seeker
import net.newpipe.newplayer.ui.seeker.SeekerColors
import net.newpipe.newplayer.ui.seeker.Segment
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getEmbeddedUiConfig
import net.newpipe.newplayer.utils.getLocale
import net.newpipe.newplayer.utils.getTimeStringFromMs
@ -86,11 +87,12 @@ fun BottomUI(
Text(getTimeStringFromMs(uiState.durationInMs, getLocale() ?: locale))
val embeddedUiConfig = getEmbeddedUiConfig(LocalContext.current as Activity)
IconButton(
onClick = if (uiState.uiMode.fullscreen) viewModel::switchToEmbeddedView
else {
{ // <- head of lambda ... yea kotlin is weird
viewModel.switchToFullscreen()
viewModel.switchToFullscreen(embeddedUiConfig)
}
}
) {

View File

@ -53,12 +53,13 @@ import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.theme.video_player_onSurface
import net.newpipe.newplayer.utils.getEmbeddedUiConfig
@Composable
fun TopUI(
modifier: Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
) {
val embeddedUiConfig = getEmbeddedUiConfig(activity = LocalContext.current as Activity)
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
@ -99,7 +100,7 @@ fun TopUI(
}
AnimatedVisibility(visible = uiState.chapters.isNotEmpty()) {
IconButton(
onClick = { viewModel.openStreamSelection(selectChapter = true) },
onClick = { viewModel.openStreamSelection(selectChapter = true, embeddedUiConfig) },
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.MenuBook,
@ -111,7 +112,8 @@ fun TopUI(
IconButton(
onClick = {
viewModel.openStreamSelection(
selectChapter = false
selectChapter = false,
embeddedUiConfig
)
},
) {

View File

@ -21,7 +21,8 @@
package net.newpipe.newplayer.ui.videoplayer.gesture_ui
import android.util.Log
import android.app.Activity
import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
@ -35,11 +36,13 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getEmbeddedUiConfig
private const val TAG = "EmbeddedGestureUI"
@ -52,6 +55,8 @@ fun EmbeddedGestureUI(
mutableStateOf(false)
}
val embeddedUiConfig = getEmbeddedUiConfig(LocalContext.current as Activity)
val handleMovement = { movement: TouchedPosition ->
Log.d(TAG, "${movement.x}:${movement.y}")
if (0 < movement.y) {
@ -61,7 +66,7 @@ fun EmbeddedGestureUI(
// this check is there to allow a temporary move up in the downward gesture
if (downwardMovementMode == false) {
viewModel.switchToFullscreen()
viewModel.switchToFullscreen(embeddedUiConfig)
} else {
viewModel.embeddedDraggedDown(movement.y)
}

View File

@ -89,6 +89,25 @@ fun getLocale(): Locale? {
return ConfigurationCompat.getLocales(configuration).get(0)
}
@Composable
@ReadOnlyComposable
fun getEmbeddedUiConfig(activity: Activity): EmbeddedUiConfig {
val window = activity.window
val view = LocalView.current
val isLightStatusBar = WindowCompat.getInsetsController(
window,
view
).isAppearanceLightStatusBars
val screenOrientation = activity.requestedOrientation
val defaultBrightness = getDefaultBrightness(activity)
return EmbeddedUiConfig(
systemBarInLightMode = isLightStatusBar,
brightness = defaultBrightness,
screenOrientation = screenOrientation
)
}
@Composable
fun getInsets() =
WindowInsets.systemBars.union(WindowInsets.displayCutout).union(WindowInsets.waterfall)