mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-10-26 16:45:26 +00:00
Merge pull request #201 from jellyfin/player-viewbinding
Use view binding in PlayerActivity
This commit is contained in:
5 files changed
+59
-54
No files matched your search
@@ -10,20 +10,26 @@ import androidx.core.view.get
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.size
|
||||
import org.jellyfin.mobile.R
|
||||
import org.jellyfin.mobile.databinding.ActivityPlayerBinding
|
||||
import org.jellyfin.mobile.databinding.ExoPlayerControlViewBinding
|
||||
import org.jellyfin.mobile.player.source.ExoPlayerTracksGroup
|
||||
import org.jellyfin.mobile.player.source.JellyfinMediaSource
|
||||
|
||||
/**
|
||||
* Provides a menu UI for audio, subtitle and video stream selection
|
||||
*/
|
||||
class PlaybackMenus(private val activity: PlayerActivity) : PopupMenu.OnDismissListener {
|
||||
private val lockScreenButton: View = activity.findViewById(R.id.lock_screen_button)
|
||||
private val audioStreamsButton: View = activity.findViewById(R.id.audio_streams_button)
|
||||
private val subtitlesButton: View = activity.findViewById(R.id.subtitles_button)
|
||||
private val infoButton: View = activity.findViewById(R.id.info_button)
|
||||
class PlaybackMenus(
|
||||
private val activity: PlayerActivity,
|
||||
private val playerBinding: ActivityPlayerBinding,
|
||||
private val playerControlsBinding: ExoPlayerControlViewBinding
|
||||
) : PopupMenu.OnDismissListener {
|
||||
private val lockScreenButton: View by playerControlsBinding::lockScreenButton
|
||||
private val audioStreamsButton: View by playerControlsBinding::audioStreamsButton
|
||||
private val subtitlesButton: View by playerControlsBinding::subtitlesButton
|
||||
private val infoButton: View by playerControlsBinding::infoButton
|
||||
private val playbackInfo: TextView by playerBinding::playbackInfo
|
||||
private val audioStreamsMenu: PopupMenu = createAudioStreamsMenu()
|
||||
private val subtitlesMenu: PopupMenu = createSubtitlesMenu()
|
||||
private val playbackInfo: TextView = activity.findViewById(R.id.playback_info)
|
||||
|
||||
init {
|
||||
lockScreenButton.setOnClickListener {
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||
import com.google.android.exoplayer2.ui.PlayerView
|
||||
import org.jellyfin.mobile.AppPreferences
|
||||
import org.jellyfin.mobile.R
|
||||
import org.jellyfin.mobile.databinding.ActivityPlayerBinding
|
||||
import org.jellyfin.mobile.databinding.ExoPlayerControlViewBinding
|
||||
import org.jellyfin.mobile.utils.*
|
||||
import org.jellyfin.mobile.utils.Constants.DEFAULT_CENTER_OVERLAY_TIMEOUT_MS
|
||||
import org.jellyfin.mobile.utils.Constants.DEFAULT_CONTROLS_TIMEOUT_MS
|
||||
@@ -30,21 +32,22 @@ import org.jellyfin.mobile.utils.Constants.DEFAULT_SEEK_TIME_MS
|
||||
import org.koin.android.ext.android.inject
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
private val appPreferences: AppPreferences by inject()
|
||||
private val viewModel: PlayerViewModel by viewModels()
|
||||
private val playerView: PlayerView by lazyView(R.id.player_view)
|
||||
private val playerControlsView: View by lazyView(R.id.player_controls)
|
||||
private val playerOverlay: View by lazyView(R.id.player_overlay)
|
||||
private val loadingIndicator: View by lazyView(R.id.loading_indicator)
|
||||
private val titleTextView: TextView by lazyView(R.id.track_title)
|
||||
private val fullscreenSwitcher: ImageButton by lazyView(R.id.fullscreen_switcher)
|
||||
private val unlockScreenButton: ImageButton by lazyView(R.id.unlock_screen_button)
|
||||
private val gestureIndicatorOverlayLayout: LinearLayout by lazyView(R.id.gesture_overlay_layout)
|
||||
private val gestureIndicatorOverlayImage: ImageView by lazyView(R.id.gesture_overlay_image)
|
||||
private val gestureIndicatorOverlayProgress: ProgressBar by lazyView(R.id.gesture_overlay_progress)
|
||||
private lateinit var playerBinding: ActivityPlayerBinding
|
||||
private val playerView: PlayerView get() = playerBinding.playerView
|
||||
private val playerOverlay: View get() = playerBinding.playerOverlay
|
||||
private val loadingIndicator: View get() = playerBinding.loadingIndicator
|
||||
private val unlockScreenButton: ImageButton get() = playerBinding.unlockScreenButton
|
||||
private val gestureIndicatorOverlayLayout: LinearLayout get() = playerBinding.gestureOverlayLayout
|
||||
private val gestureIndicatorOverlayImage: ImageView get() = playerBinding.gestureOverlayImage
|
||||
private val gestureIndicatorOverlayProgress: ProgressBar get() = playerBinding.gestureOverlayProgress
|
||||
private lateinit var playerControlsBinding: ExoPlayerControlViewBinding
|
||||
private val playerControlsView: View get() = playerControlsBinding.root
|
||||
private val titleTextView: TextView get() = playerControlsBinding.trackTitle
|
||||
private val fullscreenSwitcher: ImageButton get() = playerControlsBinding.fullscreenSwitcher
|
||||
private lateinit var playbackMenus: PlaybackMenus
|
||||
private val audioManager: AudioManager by lazy { (getSystemService(Context.AUDIO_SERVICE) as AudioManager) }
|
||||
|
||||
@@ -89,7 +92,9 @@ class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_player)
|
||||
playerBinding = ActivityPlayerBinding.inflate(layoutInflater)
|
||||
setContentView(playerBinding.root)
|
||||
playerControlsBinding = ExoPlayerControlViewBinding.bind(findViewById(R.id.player_controls))
|
||||
|
||||
// Handle system window insets
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { _, insets ->
|
||||
@@ -131,7 +136,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
setupFullscreenSwitcher()
|
||||
|
||||
// Create playback menus
|
||||
playbackMenus = PlaybackMenus(this)
|
||||
playbackMenus = PlaybackMenus(this, playerBinding, playerControlsBinding)
|
||||
|
||||
// Set controller timeout
|
||||
suppressControllerAutoHide(false)
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:viewBindingIgnore="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.exoplayer2.ui.PlayerView
|
||||
android:id="@+id/player_view"
|
||||
@@ -16,10 +15,34 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include
|
||||
layout="@layout/overlay_brightness_volume"
|
||||
<LinearLayout
|
||||
android:id="@+id/gesture_overlay_layout"
|
||||
android:layout_width="@dimen/exo_gesture_overlay_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/playback_info_background"
|
||||
android:clickable="false"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
tools:visibility="visible">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/gesture_overlay_image"
|
||||
android:layout_width="@dimen/exo_gesture_overlay_image_size"
|
||||
android:layout_height="@dimen/exo_gesture_overlay_image_size"
|
||||
android:layout_marginVertical="16dp"
|
||||
tools:srcCompat="@drawable/ic_brightness_white_24dp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gesture_overlay_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="4dp"
|
||||
tools:progress="50" />
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading_indicator"
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
android:id="@+id/player_controls"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/playback_controls_background"
|
||||
tools:viewBindingIgnore="true">
|
||||
android:background="@color/playback_controls_background">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/track_title"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/gesture_overlay_layout"
|
||||
android:layout_width="@dimen/exo_gesture_overlay_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/playback_info_background"
|
||||
android:clickable="false"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/gesture_overlay_image"
|
||||
android:layout_width="@dimen/exo_gesture_overlay_image_size"
|
||||
android:layout_height="@dimen/exo_gesture_overlay_image_size"
|
||||
android:layout_marginVertical="16dp"
|
||||
tools:srcCompat="@drawable/ic_brightness_white_24dp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gesture_overlay_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="4dp"
|
||||
tools:progress="50" />
|
||||
</LinearLayout>
|
||||
Reference in new issue
Block a user