prepare desired library layout

This commit is contained in:
Christian Schabesberger 2024-07-18 13:45:28 +02:00
parent 74fe0042c7
commit 330d0ecd96
6 changed files with 29 additions and 21 deletions

View File

@ -1,11 +1,20 @@
package net.newpipe.newplayer package net.newpipe.newplayer
import android.app.Application
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
interface NewPlayer { interface NewPlayer {
val player: Player
interface Listener { data class Builder(val app: Application) {
fun build(): NewPlayer {
return NewPlayerImpl(ExoPlayer.Builder(app).build())
}
} }
} }
class NewPlayerImpl { class NewPlayerImpl(internal_player: Player) : NewPlayer {
override val player = internal_player
} }

View File

@ -5,8 +5,10 @@ import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.findFragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import net.newpipe.newplayer.internal.VideoPlayerFragment
import net.newpipe.newplayer.internal.model.VideoPlayerViewModel import net.newpipe.newplayer.internal.model.VideoPlayerViewModel
import net.newpipe.newplayer.internal.model.VideoPlayerViewModelImpl import net.newpipe.newplayer.internal.model.VideoPlayerViewModelImpl
@ -19,6 +21,5 @@ 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.player_copose_view)
} }
} }

View File

@ -27,6 +27,7 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent import dagger.hilt.components.SingletonComponent
import net.newpipe.newplayer.NewPlayer
import javax.inject.Singleton import javax.inject.Singleton
@Module @Module
@ -34,7 +35,7 @@ import javax.inject.Singleton
object VideoPlayerComponent { object VideoPlayerComponent {
@Provides @Provides
@Singleton @Singleton
fun provideVideoPlayer(app: Application) : Player { fun provideNewPlayer(app: Application) : NewPlayer {
return ExoPlayer.Builder(app).build() return NewPlayer.Builder(app).build()
} }
} }

View File

@ -49,8 +49,6 @@ class VideoPlayerFragment() : Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val window = activity?.window!! val window = activity?.window!!
val insetsController = WindowCompat.getInsetsController(window, window.decorView) val insetsController = WindowCompat.getInsetsController(window, window.decorView)
insetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE insetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

View File

@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import net.newpipe.newplayer.internal.utils.VideoSize import net.newpipe.newplayer.internal.utils.VideoSize
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import net.newpipe.newplayer.NewPlayer
val VIDEOPLAYER_UI_STATE = "video_player_ui_state" val VIDEOPLAYER_UI_STATE = "video_player_ui_state"
@ -60,6 +61,7 @@ data class VideoPlayerUIState(
} }
interface VideoPlayerViewModel { interface VideoPlayerViewModel {
val new_player: NewPlayer?
val player: Player? val player: Player?
val uiState: StateFlow<VideoPlayerUIState> val uiState: StateFlow<VideoPlayerUIState>
var listener: Listener? var listener: Listener?
@ -88,26 +90,22 @@ interface VideoPlayerViewModel {
@HiltViewModel @HiltViewModel
class VideoPlayerViewModelImpl @Inject constructor( class VideoPlayerViewModelImpl @Inject constructor(
private val savedStateHandle: SavedStateHandle, private val savedStateHandle: SavedStateHandle,
override val player: Player, override val new_player: NewPlayer,
application: Application application: Application
) : AndroidViewModel(application), VideoPlayerViewModel { ) : AndroidViewModel(application), VideoPlayerViewModel {
val app = getApplication<Application>() // private
private val app = getApplication<Application>()
private val mutableUiState = MutableStateFlow( private val mutableUiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
VideoPlayerUIState.DEFAULT
)
private val mutableEvent = MutableSharedFlow<VideoPlayerViewModel.Events>() private val mutableEvent = MutableSharedFlow<VideoPlayerViewModel.Events>()
private var current_video_size = VideoSize.DEFAULT
override val events: SharedFlow<VideoPlayerViewModel.Events> = mutableEvent //interface
override val uiState = mutableUiState.asStateFlow() override val uiState = mutableUiState.asStateFlow()
override val events: SharedFlow<VideoPlayerViewModel.Events> = mutableEvent
override var listener: VideoPlayerViewModel.Listener? = null override var listener: VideoPlayerViewModel.Listener? = null
override val player = new_player.player
var current_video_size = VideoSize.DEFAULT
init { init {
@ -203,6 +201,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
companion object { companion object {
val dummy = object : VideoPlayerViewModel { val dummy = object : VideoPlayerViewModel {
override val new_player = null
override val player = null override val player = null
override val uiState = MutableStateFlow(VideoPlayerUIState.DEFAULT) override val uiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
override var listener: VideoPlayerViewModel.Listener? = null override var listener: VideoPlayerViewModel.Listener? = null

View File

@ -21,7 +21,7 @@
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/player_frament_view" android:id="@+id/video_player_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="50dp" android:minHeight="50dp"