Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use view binding in PlayerActivity #201

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/java/org/jellyfin/mobile/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,31 @@ 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
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) }

Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -131,7 +136,7 @@ class PlayerActivity : AppCompatActivity() {
setupFullscreenSwitcher()

// Create playback menus
playbackMenus = PlaybackMenus(this)
playbackMenus = PlaybackMenus(this, playerBinding, playerControlsBinding)

// Set controller timeout
suppressControllerAutoHide(false)
Expand Down
33 changes: 28 additions & 5 deletions app/src/main/res/layout/activity_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/exo_player_control_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 0 additions & 28 deletions app/src/main/res/layout/overlay_brightness_volume.xml

This file was deleted.