open streem selection ui

This commit is contained in:
Christian Schabesberger 2024-08-29 11:08:12 +02:00
parent 8ad95be57a
commit 8684bf95e1
8 changed files with 46 additions and 25 deletions

View File

@ -54,6 +54,6 @@ 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()
}

View File

@ -65,7 +65,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
private var uiVisibilityJob: Job? = null
private var progressUpdaterJob: Job? = null
// this is necesary to restore the embedded view UI configuration when returning from fullscreen
// this is necesary to restore the embedded view UI configuration when returning from fullscreen
private var embeddedUiConfig: EmbeddedUiConfig? = null
private val audioManager =
@ -166,8 +166,10 @@ class VideoPlayerViewModelImpl @Inject constructor(
val currentMode = mutableUiState.value.uiMode.toPlayMode()
if (currentMode != newMode) {
mutableUiState.update {
it.copy(uiMode = UIModeState.fromPlayMode(newMode),
embeddedUiConfig = embeddedUiConfig)
it.copy(
uiMode = UIModeState.fromPlayMode(newMode),
embeddedUiConfig = embeddedUiConfig
)
}
}
}
@ -357,21 +359,20 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
}
override fun openStreamSelection(selectChapter: Boolean) {
mutableUiState.update {
it.copy(
uiMode = if (selectChapter) it.uiMode.getChapterSelectUiState()
else it.uiMode.getStreamSelectUiState()
)
override fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig) {
println("gurken openSelection ${embeddedUiConfig}")
uiVisibilityJob?.cancel()
if (!uiState.value.uiMode.fullscreen) {
this.embeddedUiConfig = embeddedUiConfig
}
updateUiMode(
if (selectChapter) uiState.value.uiMode.getChapterSelectUiState()
else uiState.value.uiMode.getStreamSelectUiState()
)
}
override fun closeStreamSelection() {
mutableUiState.update {
it.copy(
uiMode = it.uiMode.getUiHiddenState()
)
}
updateUiMode(uiState.value.uiMode.getUiHiddenState())
}
override fun switchToEmbeddedView() {
@ -381,6 +382,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
}
override fun switchToFullscreen(embeddedUiConfig: EmbeddedUiConfig) {
println("gurken fullscreen: ${embeddedUiConfig}")
uiVisibilityJob?.cancel()
finishFastSeek()

View File

@ -69,7 +69,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

@ -55,6 +55,7 @@ import net.newpipe.newplayer.ui.videoplayer.CenterUI
import net.newpipe.newplayer.ui.videoplayer.TopUI
import net.newpipe.newplayer.ui.videoplayer.GestureUI
import net.newpipe.newplayer.utils.getDefaultBrightness
import net.newpipe.newplayer.utils.getInsets
val CONTROLLER_UI_BACKGROUND_COLOR = Color(0x75000000)
@ -76,8 +77,7 @@ fun VideoPlayerControllerUI(
viewModel.brightnessChange(rateChange, systemBrightness)
}
val insets =
WindowInsets.systemBars.union(WindowInsets.displayCutout).union(WindowInsets.waterfall)
val insets = getInsets()
AnimatedVisibility(uiState.uiMode.controllerUiVisible) {
Surface(

View File

@ -98,9 +98,7 @@ fun VideoPlayerUI(
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars =
false
} else {
println("gurken dings")
uiState.embeddedUiConfig?.let {
println("gurken bumbs")
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars =
it.systemBarInLightMode
}

View File

@ -34,6 +34,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
@ -68,6 +69,7 @@ import net.newpipe.newplayer.utils.BitmapThumbnail
import net.newpipe.newplayer.utils.OnlineThumbnail
import net.newpipe.newplayer.utils.Thumbnail
import net.newpipe.newplayer.utils.VectorThumbnail
import net.newpipe.newplayer.utils.getInsets
@Composable
fun StreamSelectUI(
@ -75,7 +77,13 @@ fun StreamSelectUI(
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
) {
Surface(modifier = Modifier.fillMaxSize(), color = CONTROLLER_UI_BACKGROUND_COLOR) {
val insets = getInsets()
Surface(
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(insets),
color = CONTROLLER_UI_BACKGROUND_COLOR
) {
Scaffold(
topBar = {
if (isChapterSelect) {
@ -150,7 +158,7 @@ private fun ChapterItem(
when (thumbnail) {
is OnlineThumbnail -> AsyncImage(
model = thumbnail.url,
contentDescription =contentDescription
contentDescription = contentDescription
)
is BitmapThumbnail -> Image(
@ -206,7 +214,7 @@ private fun StreamItem(
when (thumbnail) {
is OnlineThumbnail -> AsyncImage(
model = thumbnail.url,
contentDescription =contentDescription
contentDescription = contentDescription
)
is BitmapThumbnail -> Image(

View File

@ -20,6 +20,7 @@
package net.newpipe.newplayer.ui.videoplayer
import android.app.Activity
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
@ -38,6 +39,7 @@ import androidx.compose.runtime.Composable
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.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
@ -49,6 +51,7 @@ 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(
@ -56,6 +59,7 @@ fun TopUI(
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
) {
val embeddedUiConfig = getEmbeddedUiConfig(activity = LocalContext.current as Activity)
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
@ -88,7 +92,7 @@ fun TopUI(
)
}
IconButton(
onClick = { viewModel.openStreamSelection(selectChapter = true) },
onClick = { viewModel.openStreamSelection(selectChapter = true, embeddedUiConfig) },
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.MenuBook,
@ -96,7 +100,7 @@ fun TopUI(
)
}
IconButton(
onClick = { viewModel.openStreamSelection(selectChapter = false) },
onClick = { viewModel.openStreamSelection(selectChapter = false, embeddedUiConfig) },
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.List,

View File

@ -25,6 +25,11 @@ import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.view.WindowManager
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.waterfall
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
@ -94,6 +99,10 @@ fun getEmbeddedUiConfig(activity: Activity): EmbeddedUiConfig {
)
}
@Composable
fun getInsets() =
WindowInsets.systemBars.union(WindowInsets.displayCutout).union(WindowInsets.waterfall)
private const val HOURS_PER_DAY = 24
private const val MINUTES_PER_HOUR = 60
private const val SECONDS_PER_MINUTE = 60