restructure code to make room for the audioplayer

This commit is contained in:
Christian Schabesberger 2024-09-18 13:56:02 +02:00
parent 7dbe166484
commit d379d5872f
24 changed files with 154 additions and 187 deletions

View File

@ -27,11 +27,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModel
private const val TAG = "ActivityBrainSlug"
class ActivityBrainSlug(val viewModel: VideoPlayerViewModel) {
class ActivityBrainSlug(val viewModel: NewPlayerViewModel) {
val brainSlugScope = CoroutineScope(Dispatchers.Main + Job())

View File

@ -27,14 +27,14 @@ import android.widget.FrameLayout
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import dagger.hilt.android.AndroidEntryPoint
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.ui.VideoPlayerUI
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.ui.NewPlayerUI
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
@AndroidEntryPoint
class VideoPlayerView : FrameLayout {
var viewModel: VideoPlayerViewModel? = null
var viewModel: NewPlayerViewModel? = null
set(value) {
field = value
applyViewModel()
@ -59,7 +59,7 @@ class VideoPlayerView : FrameLayout {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
VideoPlayerTheme {
VideoPlayerUI(viewModel = viewModel)
NewPlayerUI(viewModel = viewModel)
}
}
}

View File

@ -28,31 +28,8 @@ import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.RepeatMode
import net.newpipe.newplayer.ui.ContentScale
data class GurkenItem(
val title: String,
val creator: String,
val id: String,
val uniqueId: Long,
val thumbnail: Uri?,
val lengthInS: Int
) {
companion object {
val DEFAULT = GurkenItem(
title = "",
creator = "",
id = "",
uniqueId = -1L,
thumbnail = null,
lengthInS = 0
)
}
}
@UnstableApi
data class VideoPlayerUIState(
data class NewPlayerUIState(
val uiMode: UIModeState,
val playing: Boolean,
val contentRatio: Float,
@ -80,7 +57,7 @@ data class VideoPlayerUIState(
val availableSubtitles: List<String>
) {
companion object {
val DEFAULT = VideoPlayerUIState(
val DEFAULT = NewPlayerUIState(
uiMode = UIModeState.PLACEHOLDER,
playing = false,
contentRatio = 16 / 9f,

View File

@ -21,16 +21,18 @@
package net.newpipe.newplayer.model
import android.os.Bundle
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.ui.ContentScale
interface VideoPlayerViewModel {
@OptIn(UnstableApi::class)
interface NewPlayerViewModel {
var newPlayer: NewPlayer?
val uiState: StateFlow<VideoPlayerUIState>
val uiState: StateFlow<NewPlayerUIState>
var minContentRatio: Float
var maxContentRatio: Float
var contentFitMode: ContentScale

View File

@ -1,19 +1,16 @@
package net.newpipe.newplayer.model
import android.os.Bundle
import androidx.media3.common.Player
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.RepeatMode
import net.newpipe.newplayer.ui.ContentScale
open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
open class NewPlayerViewModelDummy : NewPlayerViewModel {
override var newPlayer: NewPlayer? = null
override val uiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
override val uiState = MutableStateFlow(NewPlayerUIState.DEFAULT)
override var minContentRatio = 4F / 3F
override var maxContentRatio = 16F / 9F
override var contentFitMode = ContentScale.FIT_INSIDE

View File

@ -42,7 +42,6 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import javax.inject.Inject
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import net.newpipe.newplayer.utils.VideoSize
@ -59,13 +58,13 @@ private const val TAG = "VideoPlayerViewModel"
@UnstableApi
@HiltViewModel
class VideoPlayerViewModelImpl @Inject constructor(
class NewPlayerViewModelImpl @Inject constructor(
private val savedStateHandle: SavedStateHandle,
application: Application,
) : AndroidViewModel(application), VideoPlayerViewModel {
) : AndroidViewModel(application), NewPlayerViewModel {
// private
private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
private val mutableUiState = MutableStateFlow(NewPlayerUIState.DEFAULT)
private var currentContentRatio = 1F
private var playlistItemToBeMoved: Int? = null
@ -288,7 +287,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
val recoveredUiState =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) instanceState.getParcelable(
VIDEOPLAYER_UI_STATE, VideoPlayerUIState::class.java
VIDEOPLAYER_UI_STATE, NewPlayerUIState::class.java
)
else instanceState.getParcelable(VIDEOPLAYER_UI_STATE)

View File

@ -10,7 +10,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

View File

@ -57,10 +57,10 @@ import androidx.lifecycle.LifecycleEventObserver
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.StreamSelectUI
import net.newpipe.newplayer.ui.videoplayer.VideoPlayerControllerUI
import net.newpipe.newplayer.utils.LockScreenOrientation
import net.newpipe.newplayer.utils.getDefaultBrightness
import net.newpipe.newplayer.utils.setScreenBrightness
@ -69,8 +69,8 @@ private const val TAG = "VideoPlayerUI"
@OptIn(UnstableApi::class)
@Composable
fun VideoPlayerUI(
viewModel: VideoPlayerViewModel?,
fun NewPlayerUI(
viewModel: NewPlayerViewModel?,
) {
if (viewModel == null) {
VideoPlayerLoadingPlaceholder()
@ -276,6 +276,6 @@ fun PlaySurface(
@Composable
fun PlayerUIPreviewEmbeded() {
VideoPlayerTheme {
VideoPlayerUI(viewModel = VideoPlayerViewModelDummy())
NewPlayerUI(viewModel = NewPlayerViewModelDummy())
}
}

View File

@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer
package net.newpipe.newplayer.ui
import androidx.annotation.OptIn
import androidx.compose.foundation.layout.Arrangement
@ -39,16 +39,16 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.STREAMSELECT_UI_BACKGROUND_COLOR
import net.newpipe.newplayer.ui.videoplayer.streamselect.ChapterItem
import net.newpipe.newplayer.ui.videoplayer.streamselect.ChapterSelectTopBar
import net.newpipe.newplayer.ui.videoplayer.streamselect.StreamItem
import net.newpipe.newplayer.ui.videoplayer.streamselect.StreamSelectTopBar
import net.newpipe.newplayer.ui.videoplayer.streamselect.isActiveChapter
import net.newpipe.newplayer.ui.streamselect.ChapterItem
import net.newpipe.newplayer.ui.streamselect.ChapterSelectTopBar
import net.newpipe.newplayer.ui.streamselect.StreamItem
import net.newpipe.newplayer.ui.streamselect.StreamSelectTopBar
import net.newpipe.newplayer.ui.streamselect.isActiveChapter
import net.newpipe.newplayer.ui.videoplayer.STREAMSELECT_UI_BACKGROUND_COLOR
import net.newpipe.newplayer.utils.ReorderHapticFeedbackType
import net.newpipe.newplayer.utils.getInsets
import net.newpipe.newplayer.utils.rememberReorderHapticFeedback
@ -61,8 +61,8 @@ val ITEM_CORNER_SHAPE = RoundedCornerShape(10.dp)
@Composable
fun StreamSelectUI(
isChapterSelect: Boolean = false,
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
viewModel: NewPlayerViewModel,
uiState: NewPlayerUIState
) {
val insets = getInsets()
Surface(
@ -128,8 +128,8 @@ fun StreamSelectUI(
@Composable
fun ReorderableStreamItemsList(
padding: PaddingValues,
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
viewModel: NewPlayerViewModel,
uiState: NewPlayerUIState
) {
val haptic = rememberReorderHapticFeedback()
@ -176,8 +176,8 @@ fun VideoPlayerChannelSelectUIPreview() {
Surface(modifier = Modifier.fillMaxSize(), color = Color.Red) {
StreamSelectUI(
isChapterSelect = true,
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DUMMY
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY
)
}
}
@ -191,8 +191,8 @@ fun VideoPlayerStreamSelectUIPreview() {
Surface(modifier = Modifier.fillMaxSize(), color = Color.Red) {
StreamSelectUI(
isChapterSelect = false,
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DUMMY
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY
)
}
}

View File

@ -0,0 +1,27 @@
package net.newpipe.newplayer.ui.audioplayer
import androidx.annotation.OptIn
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.NewPlayerUI
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
@OptIn(UnstableApi::class)
@Composable
fun AudioPlayerUI(viewModel:NewPlayerViewModel, uiState: NewPlayerUIState) {
}
@OptIn(UnstableApi::class)
@Preview(device = "spec:width=1080px,height=700px,dpi=440,orientation=landscape")
@Composable
fun AudioPlayerUIPreviewEmbedded() {
VideoPlayerTheme {
AudioPlayerUI(viewModel = NewPlayerViewModelDummy(), uiState = NewPlayerUIState.DUMMY)
}
}

View File

@ -19,14 +19,13 @@
*/
package net.newpipe.newplayer.ui.videoplayer.streamselect
package net.newpipe.newplayer.ui.streamselect
import android.net.Uri
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -35,7 +34,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@ -43,19 +41,17 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.NewPlayerException
import net.newpipe.newplayer.R
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.ITEM_CORNER_SHAPE
import net.newpipe.newplayer.ui.ITEM_CORNER_SHAPE
import net.newpipe.newplayer.utils.Thumbnail
import net.newpipe.newplayer.utils.getLocale
import net.newpipe.newplayer.utils.getTimeStringFromMs

View File

@ -19,7 +19,7 @@
*/
package net.newpipe.newplayer.ui.videoplayer.streamselect
package net.newpipe.newplayer.ui.streamselect
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons

View File

@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer.streamselect
package net.newpipe.newplayer.ui.streamselect
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
@ -62,10 +62,10 @@ import androidx.compose.ui.unit.sp
import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.ui.CONTROLLER_UI_BACKGROUND_COLOR
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.ui.videoplayer.CONTROLLER_UI_BACKGROUND_COLOR
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.ITEM_CORNER_SHAPE
import net.newpipe.newplayer.ui.ITEM_CORNER_SHAPE
import net.newpipe.newplayer.utils.ReorderHapticFeedback
import net.newpipe.newplayer.utils.ReorderHapticFeedbackType
import net.newpipe.newplayer.utils.Thumbnail
@ -249,7 +249,7 @@ fun StreamItemPreview() {
Surface(modifier = Modifier.fillMaxSize(), color = Color.DarkGray) {
Box(modifier = Modifier.fillMaxSize()) {
StreamItem(
playlistItem = VideoPlayerUIState.DUMMY.currentlyPlaying!!,
playlistItem = NewPlayerUIState.DUMMY.currentlyPlaying!!,
onClicked = {},
reorderableScope = null,
haptic = null,

View File

@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer.streamselect
package net.newpipe.newplayer.ui.streamselect
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
@ -45,9 +45,9 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.RepeatMode
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getLocale
import net.newpipe.newplayer.utils.getPlaylistDurationInMS
@ -58,8 +58,8 @@ import net.newpipe.newplayer.utils.getTimeStringFromMs
@Composable
fun StreamSelectTopBar(
modifier: Modifier = Modifier,
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
viewModel: NewPlayerViewModel,
uiState: NewPlayerUIState
) {
TopAppBar(modifier = modifier,
@ -143,8 +143,8 @@ fun StreamSelectTopBarPreview() {
Surface(modifier = Modifier.fillMaxSize(), color = Color.DarkGray) {
StreamSelectTopBar(
modifier = Modifier.fillMaxSize(),
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DEFAULT
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DEFAULT
)
}
}

View File

@ -24,10 +24,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.ui.PreviewBackgroundSurface
import net.newpipe.newplayer.ui.VideoPlayerControllerUI
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.videoplayer.PreviewBackgroundSurface
import net.newpipe.newplayer.ui.videoplayer.VideoPlayerControllerUI
val video_player_primary = Color(0xFFE53935)
@ -76,8 +76,8 @@ fun VideoPlayerControllerUIPreviewEmbeddedColorPreview() {
VideoPlayerTheme {
PreviewBackgroundSurface {
VideoPlayerControllerUI(
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DEFAULT.copy(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DEFAULT.copy(
uiMode = UIModeState.EMBEDDED_VIDEO_CONTROLLER_UI,
playing = true,
seekerPosition = 0.3f,

View File

@ -23,8 +23,8 @@ package net.newpipe.newplayer.ui.videoplayer
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.EmbeddedGestureUI
import net.newpipe.newplayer.ui.videoplayer.gesture_ui.FullscreenGestureUI
@ -34,7 +34,7 @@ val INDICATOR_BACKGROUND_COLOR = Color.Black.copy(alpha = 0.3f)
@Composable
fun GestureUI(
modifier: Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
modifier: Modifier, viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
if (uiState.uiMode.fullscreen) {
FullscreenGestureUI(

View File

@ -18,22 +18,15 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui
package net.newpipe.newplayer.ui.videoplayer
import android.app.Activity
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.waterfall
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.CircularProgressIndicator
@ -43,18 +36,15 @@ 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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.BottomUI
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.ui.videoplayer.controller.BottomUI
import net.newpipe.newplayer.ui.videoplayer.controller.CenterUI
import net.newpipe.newplayer.ui.videoplayer.controller.TopUI
import net.newpipe.newplayer.utils.getInsets
val CONTROLLER_UI_BACKGROUND_COLOR = Color(0x75000000)
@ -62,7 +52,7 @@ val STREAMSELECT_UI_BACKGROUND_COLOR = Color(0xba000000)
@Composable
fun VideoPlayerControllerUI(
viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
val insets = getInsets()
@ -151,7 +141,7 @@ fun PreviewBackgroundSurface(
fun VideoPlayerControllerUIPreviewEmbedded() {
VideoPlayerTheme {
PreviewBackgroundSurface {
VideoPlayerControllerUI(VideoPlayerViewModelDummy(), VideoPlayerUIState.DEFAULT)
VideoPlayerControllerUI(NewPlayerViewModelDummy(), NewPlayerUIState.DEFAULT)
}
}
}
@ -161,7 +151,7 @@ fun VideoPlayerControllerUIPreviewEmbedded() {
fun VideoPlayerControllerUIPreviewLandscape() {
VideoPlayerTheme {
PreviewBackgroundSurface {
VideoPlayerControllerUI(VideoPlayerViewModelDummy(), VideoPlayerUIState.DEFAULT)
VideoPlayerControllerUI(NewPlayerViewModelDummy(), NewPlayerUIState.DEFAULT)
}
}
}
@ -171,7 +161,7 @@ fun VideoPlayerControllerUIPreviewLandscape() {
fun VideoPlayerControllerUIPreviewPortrait() {
VideoPlayerTheme {
PreviewBackgroundSurface {
VideoPlayerControllerUI(VideoPlayerViewModelDummy(), VideoPlayerUIState.DEFAULT)
VideoPlayerControllerUI(NewPlayerViewModelDummy(), NewPlayerUIState.DEFAULT)
}
}
}

View File

@ -18,11 +18,9 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer
package net.newpipe.newplayer.ui.videoplayer.controller
import android.app.Activity
import android.app.LocaleConfig
import android.icu.text.DecimalFormat
import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
@ -35,28 +33,23 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.os.ConfigurationCompat
import androidx.lifecycle.viewModelScope
import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.EmbeddedUiConfig
import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.seeker.ChapterSegment
import net.newpipe.newplayer.ui.seeker.DefaultSeekerColor
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
@ -67,7 +60,7 @@ private const val TAG = "BottomUI"
@Composable
fun BottomUI(
modifier: Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
modifier: Modifier, viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
Row(
verticalAlignment = Alignment.CenterVertically,
@ -155,8 +148,8 @@ fun VideoPlayerControllerBottomUIPreview() {
Surface(color = Color.Black) {
BottomUI(
modifier = Modifier,
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DUMMY.copy(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY.copy(
uiMode = UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI,
seekerPosition = 0.2f,
playbackPositionInMs = 3 * 60 * 1000,

View File

@ -18,15 +18,13 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer
package net.newpipe.newplayer.ui.videoplayer.controller
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
@ -39,7 +37,6 @@ import androidx.compose.material.icons.filled.SkipPrevious
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -50,16 +47,16 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
@Composable
fun CenterUI(
modifier: Modifier = Modifier,
viewModel: VideoPlayerViewModel,
uiState: VideoPlayerUIState
viewModel: NewPlayerViewModel,
uiState: NewPlayerUIState
) {
Row(
verticalAlignment = Alignment.CenterVertically,
@ -144,8 +141,8 @@ fun VideoPlayerControllerUICenterUIPreview() {
VideoPlayerTheme {
Surface(color = Color.Black) {
CenterUI(
viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DUMMY.copy(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY.copy(
isLoading = false,
playing = true,
currentPlaylistItemIndex = 1

View File

@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer
package net.newpipe.newplayer.ui.videoplayer.controller
import androidx.annotation.OptIn
import androidx.compose.foundation.layout.Box
@ -35,7 +35,6 @@ import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@ -44,8 +43,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusModifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
@ -54,14 +51,14 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
@OptIn(UnstableApi::class)
@Composable
fun DropDownMenu(viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState) {
fun DropDownMenu(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
var showMainMenu: Boolean by remember { mutableStateOf(false) }
val pixel_density = LocalDensity.current
@ -152,7 +149,7 @@ fun DropDownMenu(viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState) {
fun VideoPlayerControllerDropDownPreview() {
VideoPlayerTheme {
Box(Modifier.fillMaxSize()) {
DropDownMenu(VideoPlayerViewModelDummy(), VideoPlayerUIState.DUMMY)
DropDownMenu(NewPlayerViewModelDummy(), NewPlayerUIState.DUMMY)
}
}
}

View File

@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.ui.videoplayer
package net.newpipe.newplayer.ui.videoplayer.controller
import android.app.Activity
import androidx.annotation.OptIn
@ -50,16 +50,16 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
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
modifier: Modifier, viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
val embeddedUiConfig = getEmbeddedUiConfig(activity = LocalContext.current as Activity)
Row(
@ -140,7 +140,7 @@ fun VideoPlayerControllerTopUIPreview() {
VideoPlayerTheme {
Surface(color = Color.Black) {
TopUI(
modifier = Modifier, VideoPlayerViewModelDummy(), VideoPlayerUIState.DUMMY
modifier = Modifier, NewPlayerViewModelDummy(), NewPlayerUIState.DUMMY
)
}
}

View File

@ -38,9 +38,9 @@ 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.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getEmbeddedUiConfig
@ -48,7 +48,7 @@ private const val TAG = "EmbeddedGestureUI"
@Composable
fun EmbeddedGestureUI(
modifier: Modifier = Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
modifier: Modifier = Modifier, viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
var downwardMovementMode by remember {
@ -158,7 +158,7 @@ fun EmbeddedGestureUIPreview() {
Surface(modifier = Modifier.wrapContentSize(), color = Color.DarkGray) {
EmbeddedGestureUI(
modifier = Modifier,
viewModel = object : VideoPlayerViewModelDummy() {
viewModel = object : NewPlayerViewModelDummy() {
override fun switchToEmbeddedView() {
println("switch to fullscreen")
}
@ -171,7 +171,7 @@ fun EmbeddedGestureUIPreview() {
println("fast seek by $steps steps")
}
},
uiState = VideoPlayerUIState.DEFAULT,
uiState = NewPlayerUIState.DEFAULT,
)
}
}

View File

@ -45,9 +45,9 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelDummy
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getDefaultBrightness
@ -57,7 +57,7 @@ private enum class IndicatorMode {
@Composable
fun FullscreenGestureUI(
modifier: Modifier = Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
modifier: Modifier = Modifier, viewModel: NewPlayerViewModel, uiState: NewPlayerUIState
) {
var heightPx by remember {
@ -221,11 +221,11 @@ fun FullscreenGestureUIPreview() {
VideoPlayerTheme {
Surface(modifier = Modifier.wrapContentSize(), color = Color.DarkGray) {
FullscreenGestureUI(
modifier = Modifier, object : VideoPlayerViewModelDummy() {
modifier = Modifier, object : NewPlayerViewModelDummy() {
override fun fastSeek(steps: Int) {
println("fast seek by $steps steps")
}
}, VideoPlayerUIState.DEFAULT
}, NewPlayerUIState.DEFAULT
)
}
}
@ -255,7 +255,7 @@ fun FullscreenGestureUIPreviewInteractive() {
Surface(modifier = Modifier.wrapContentSize(), color = Color.Gray) {
FullscreenGestureUI(
modifier = Modifier,
object : VideoPlayerViewModelDummy() {
object : NewPlayerViewModelDummy() {
override fun hideUi() {
uiVisible = false
}
@ -280,7 +280,7 @@ fun FullscreenGestureUIPreviewInteractive() {
soundVolume = (soundVolume + changeRate).coerceIn(0f, 1f)
}
},
uiState = VideoPlayerUIState.DEFAULT.copy(
uiState = NewPlayerUIState.DEFAULT.copy(
uiMode = if (uiVisible) UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI
else UIModeState.FULLSCREEN_VIDEO,
fastSeekSeconds = seekSeconds,

View File

@ -22,22 +22,15 @@ package net.newpipe.newplayer.testapp
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.media3.common.MediaItem
import dagger.hilt.android.AndroidEntryPoint
import net.newpipe.newplayer.ActivityBrainSlug
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.PlayMode
import net.newpipe.newplayer.VideoPlayerView
import net.newpipe.newplayer.model.VideoPlayerViewModel
import net.newpipe.newplayer.model.VideoPlayerViewModelImpl
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelImpl
import net.newpipe.newplayer.testapp.databinding.ActivityMainBinding
import net.newpipe.newplayer.ui.ContentScale
import javax.inject.Inject
@ -45,7 +38,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
val videoPlayerViewModel: VideoPlayerViewModel by viewModels<VideoPlayerViewModelImpl>()
val newPlayerViewModel: NewPlayerViewModel by viewModels<NewPlayerViewModelImpl>()
@Inject
lateinit var newPlayer: NewPlayer
@ -96,10 +89,10 @@ class MainActivity : AppCompatActivity() {
newPlayer.addToPlaylist("yt_test")
}
videoPlayerViewModel.newPlayer = newPlayer
videoPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE
newPlayerViewModel.newPlayer = newPlayer
newPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE
activityBrainSlug = ActivityBrainSlug(videoPlayerViewModel)
activityBrainSlug = ActivityBrainSlug(newPlayerViewModel)
activityBrainSlug?.let {
it.embeddedPlayerView = binding.embeddedPlayer
it.addViewToHideOnFullscreen(binding.buttonsLayout as View)