68 lines
No EOL
2.1 KiB
Kotlin
68 lines
No EOL
2.1 KiB
Kotlin
/* NewPlayer
|
|
*
|
|
* @author Christian Schabesberger
|
|
*
|
|
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
|
|
*
|
|
* NewPlayer is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* NewPlayer is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package net.newpipe.newplayer
|
|
|
|
import android.content.Context
|
|
import android.util.AttributeSet
|
|
import android.view.LayoutInflater
|
|
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.ui.theme.VideoPlayerTheme
|
|
|
|
@AndroidEntryPoint
|
|
class VideoPlayerView : FrameLayout {
|
|
|
|
var viewModel: VideoPlayerViewModel? = null
|
|
set(value) {
|
|
field = value
|
|
applyViewModel()
|
|
}
|
|
|
|
val composeView:ComposeView
|
|
|
|
@JvmOverloads
|
|
constructor(
|
|
context: Context,
|
|
attrs: AttributeSet? = null,
|
|
defStyleAttr: Int = 0
|
|
) : super(context, attrs, defStyleAttr) {
|
|
val view = LayoutInflater.from(context).inflate(R.layout.video_player_view, this)
|
|
composeView = view.findViewById<ComposeView>(R.id.video_player_compose_view)
|
|
|
|
applyViewModel()
|
|
}
|
|
|
|
private fun applyViewModel() {
|
|
composeView.apply {
|
|
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
|
setContent {
|
|
VideoPlayerTheme {
|
|
VideoPlayerUI(viewModel = viewModel)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |