get same orientation fullscreen fixed

This commit is contained in:
Christian Schabesberger 2024-07-24 15:15:45 +02:00
parent 61df2e3c72
commit 1375cfc877
2 changed files with 30 additions and 20 deletions

View File

@ -35,6 +35,12 @@ import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
class VideoPlayerView : FrameLayout { class VideoPlayerView : FrameLayout {
var viewModel: VideoPlayerViewModel? = null var viewModel: VideoPlayerViewModel? = null
set(value) {
field = value
applyViewModel()
}
val composeView:ComposeView
@JvmOverloads @JvmOverloads
constructor( constructor(
@ -43,8 +49,12 @@ class VideoPlayerView : FrameLayout {
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : super(context, attrs, defStyleAttr) { ) : super(context, attrs, defStyleAttr) {
val view = LayoutInflater.from(context).inflate(R.layout.video_player_view, this) val view = LayoutInflater.from(context).inflate(R.layout.video_player_view, this)
val composeView = view.findViewById<ComposeView>(R.id.video_player_compose_view) composeView = view.findViewById<ComposeView>(R.id.video_player_compose_view)
applyViewModel()
}
private fun applyViewModel() {
composeView.apply { composeView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent { setContent {
@ -53,6 +63,6 @@ class VideoPlayerView : FrameLayout {
} }
} }
} }
} }
} }

View File

@ -22,7 +22,6 @@ package net.newpipe.newplayer.testapp
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.webkit.RenderProcessGoneDetail
import android.widget.Button import android.widget.Button
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels import androidx.activity.viewModels
@ -52,15 +51,15 @@ class MainActivity : AppCompatActivity() {
enableEdgeToEdge() enableEdgeToEdge()
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
val video_view = findViewById<VideoPlayerView>(R.id.new_player_video_view) val embeddedPlayer = findViewById<VideoPlayerView>(R.id.new_player_video_view)
val start_stream_button = findViewById<Button>(R.id.start_stream_button) val startStreamButton = findViewById<Button>(R.id.start_stream_button)
val buttons_layout = findViewById<View>(R.id.buttons_layout) val buttonsLayout = findViewById<View>(R.id.buttons_layout)
val embedded_player_layout = findViewById<View>(R.id.player_column) val embeddedPlayerLayout = findViewById<View>(R.id.player_column)
val fullscreen_player = findViewById<VideoPlayerView>(R.id.fullscreen_player) val fullscreenPlayer = findViewById<VideoPlayerView>(R.id.fullscreen_player)
start_stream_button.setOnClickListener { startStreamButton.setOnClickListener {
newPlayer.playWhenReady = true newPlayer.playWhenReady = true
newPlayer.setStream(getString(R.string.ccc_6502_video)) newPlayer.setStream(getString(R.string.portrait_video_example))
} }
@ -80,16 +79,17 @@ class MainActivity : AppCompatActivity() {
v.setPadding(0, 0, 0, 0) v.setPadding(0, 0, 0, 0)
insets insets
} }
buttons_layout.visibility = View.GONE buttonsLayout.visibility = View.GONE
embedded_player_layout.visibility = View.GONE embeddedPlayerLayout.visibility = View.GONE
fullscreen_player.visibility = View.VISIBLE fullscreenPlayer.visibility = View.VISIBLE
fullscreen_player.viewModel = videoPlayerViewModel embeddedPlayer.viewModel = null
fullscreenPlayer.viewModel = videoPlayerViewModel
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
} }
val setupEmbeddedView = { val setupEmbeddedView = {
buttons_layout.visibility = View.VISIBLE buttonsLayout.visibility = View.VISIBLE
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
@ -102,11 +102,11 @@ class MainActivity : AppCompatActivity() {
insets insets
} }
buttons_layout.visibility = View.VISIBLE buttonsLayout.visibility = View.VISIBLE
embedded_player_layout.visibility = View.VISIBLE embeddedPlayerLayout.visibility = View.VISIBLE
fullscreen_player.visibility = View.GONE fullscreenPlayer.visibility = View.GONE
video_view.viewModel = videoPlayerViewModel fullscreenPlayer.viewModel = null
embeddedPlayer.viewModel = videoPlayerViewModel
windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
} }