From b5b75558b583b705f1e07322e47d66e13c1a136c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 23 Jul 2024 13:26:27 +0200 Subject: [PATCH] apply fullscreenmode again --- .../newplayer/model/VideoPlayerViewModel.kt | 17 ++++- .../newpipe/newplayer/testapp/MainActivity.kt | 70 ++++++++----------- .../main/res/layout-land/activity_main.xml | 21 ++++-- .../src/main/res/layout/activity_main.xml | 48 +++++++++---- 4 files changed, 97 insertions(+), 59 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt b/new-player/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt index d61bac8..304201c 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt @@ -72,6 +72,7 @@ interface VideoPlayerViewModel { var minContentRatio: Float var maxContentRatio: Float var contentFitMode: ContentScale + var fullscreenListener: FullscreenListener? fun initUIState(instanceState: Bundle) fun play() @@ -80,6 +81,10 @@ interface VideoPlayerViewModel { fun nextStream() fun switchToFullscreen() fun switchToEmbeddedView() + + interface FullscreenListener { + fun onFullscreenToggle(isFullscreen: Boolean) + } } @HiltViewModel @@ -90,8 +95,11 @@ class VideoPlayerViewModelImpl @Inject constructor( // private private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT) + private var currentContentRatio = 1F //interface + override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null + override var newPlayer: NewPlayer? = null set(value) { field = value @@ -161,10 +169,12 @@ class VideoPlayerViewModelImpl @Inject constructor( fun updateContentRatio(videoSize: VideoSize) { val newRatio = videoSize.getRatio() - Log.d(TAG, "Update Content ratio: $newRatio") + val ratio = if(newRatio.isNaN()) currentContentRatio else newRatio + currentContentRatio = ratio + Log.d(TAG, "Update Content ratio: $ratio") mutableUiState.update { it.copy( - contentRatio = newRatio, + contentRatio = currentContentRatio, uiRatio = getUiRatio() ) } @@ -208,12 +218,14 @@ class VideoPlayerViewModelImpl @Inject constructor( } override fun switchToEmbeddedView() { + fullscreenListener?.onFullscreenToggle(false) mutableUiState.update { it.copy(fullscreen = false) } } override fun switchToFullscreen() { + fullscreenListener?.onFullscreenToggle(true) mutableUiState.update { it.copy(fullscreen = true) } @@ -237,6 +249,7 @@ class VideoPlayerViewModelImpl @Inject constructor( override var minContentRatio = 4F / 3F override var maxContentRatio = 16F / 9F override var contentFitMode = ContentScale.FIT_INSIDE + override var fullscreenListener: VideoPlayerViewModel.FullscreenListener? = null override fun initUIState(instanceState: Bundle) { println("dummy impl") diff --git a/test-app/src/main/java/net/newpipe/newplayer/testapp/MainActivity.kt b/test-app/src/main/java/net/newpipe/newplayer/testapp/MainActivity.kt index ae2ea13..ba6506b 100644 --- a/test-app/src/main/java/net/newpipe/newplayer/testapp/MainActivity.kt +++ b/test-app/src/main/java/net/newpipe/newplayer/testapp/MainActivity.kt @@ -21,11 +21,14 @@ 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.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat import dagger.hilt.android.AndroidEntryPoint import net.newpipe.newplayer.NewPlayer import net.newpipe.newplayer.VideoPlayerView @@ -48,56 +51,43 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) val video_view = findViewById(R.id.new_player_video_view) + val start_stream_button = findViewById