From 0672344cd7e8ddef3889ae04c4ac9430ded06d21 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Mon, 19 Oct 2020 01:49:53 +0200 Subject: [PATCH] Use view binding in PlayerActivity --- .../jellyfin/mobile/player/PlaybackMenus.kt | 18 ++++++---- .../jellyfin/mobile/player/PlayerActivity.kt | 31 +++++++++-------- app/src/main/res/layout/activity_player.xml | 33 ++++++++++++++++--- .../res/layout/exo_player_control_view.xml | 3 +- .../res/layout/overlay_brightness_volume.xml | 28 ---------------- 5 files changed, 59 insertions(+), 54 deletions(-) delete mode 100644 app/src/main/res/layout/overlay_brightness_volume.xml diff --git a/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt b/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt index a7414f1b5..551e209bf 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt @@ -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 { diff --git a/app/src/main/java/org/jellyfin/mobile/player/PlayerActivity.kt b/app/src/main/java/org/jellyfin/mobile/player/PlayerActivity.kt index 74d149d19..03d8c5004 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/PlayerActivity.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/PlayerActivity.kt @@ -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) diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml index d31fb4746..35318158c 100644 --- a/app/src/main/res/layout/activity_player.xml +++ b/app/src/main/res/layout/activity_player.xml @@ -2,8 +2,7 @@ + android:layout_height="match_parent"> - + tools:visibility="visible"> + + + + + + android:background="@color/playback_controls_background"> - - - - - -