Skip to content

Commit

Permalink
Dismiss playback actions popups on fragment detach (#4365)
Browse files Browse the repository at this point in the history
* Dismiss playback actions popups on fragment detach

* Update CONTRIBUTORS.md
  • Loading branch information
Olaren15 authored Jan 3, 2025
1 parent b6b2c03 commit d91d873
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 19 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [mohd-akram](https://github.com/mohd-akram)
- [3l0w](https://github.com/3l0w)
- [MajMongoose](https://github.com/majmongoose)
- [Olaren15](https://github.com/Olaren15)

# Emby Contributors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public class CustomPlaybackTransportControlGlue extends PlaybackTransportControl
protected void onDetachedFromHost() {
mHandler.removeCallbacks(mRefreshEndTime);
mHandler.removeCallbacks(mRefreshViewVisibility);

closedCaptionsAction.removePopup();
playbackSpeedAction.dismissPopup();
selectAudioAction.dismissPopup();
selectQualityAction.dismissPopup();
zoomAction.dismissPopup();

super.onDetachedFromHost();
}

Expand Down Expand Up @@ -169,6 +176,7 @@ protected void onBindRowViewHolder(RowPresenter.ViewHolder vh, Object item) {
super.onBindRowViewHolder(vh, item);
vh.setOnKeyListener(CustomPlaybackTransportControlGlue.this);
}

@Override
protected void onUnbindRowViewHolder(RowPresenter.ViewHolder vh) {
super.onUnbindRowViewHolder(vh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ClosedCaptionsAction(
context: Context,
customPlaybackTransportControlGlue: CustomPlaybackTransportControlGlue,
) : CustomAction(context, customPlaybackTransportControlGlue) {
private var popup: PopupMenu? = null

init {
initializeWithIcon(R.drawable.ic_select_subtitle)
}
Expand All @@ -34,7 +36,8 @@ class ClosedCaptionsAction(
}

videoPlayerAdapter.leanbackOverlayFragment.setFading(false)
PopupMenu(context, view, Gravity.END).apply {
removePopup()
popup = PopupMenu(context, view, Gravity.END).apply {
with(menu) {
var order = 0
add(0, -1, order++, context.getString(R.string.lbl_none)).apply {
Expand All @@ -51,11 +54,19 @@ class ClosedCaptionsAction(

setGroupCheckable(0, true, false)
}
setOnDismissListener { videoPlayerAdapter.leanbackOverlayFragment.setFading(true) }
setOnDismissListener {
videoPlayerAdapter.leanbackOverlayFragment.setFading(true)
popup = null
}
setOnMenuItemClickListener { item ->
playbackController.setSubtitleIndex(item.itemId)
true
}
}.show()
}
popup?.show()
}

fun removePopup() {
popup?.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PlaybackSpeedAction(
) : CustomAction(context, customPlaybackTransportControlGlue) {
private val speedController = VideoSpeedController(playbackController)
private val speeds = VideoSpeedController.SpeedSteps.entries.toTypedArray()
private var popup: PopupMenu? = null

init {
initializeWithIcon(R.drawable.ic_playback_speed)
Expand All @@ -30,17 +31,20 @@ class PlaybackSpeedAction(
view: View,
) {
videoPlayerAdapter.leanbackOverlayFragment.setFading(false)
val speedMenu = populateMenu(context, view, speedController)
dismissPopup()
popup = populateMenu(context, view, speedController)

speedMenu.setOnDismissListener { videoPlayerAdapter.leanbackOverlayFragment.setFading(true) }
popup?.setOnDismissListener {
videoPlayerAdapter.leanbackOverlayFragment.setFading(true)
popup = null
}

speedMenu.setOnMenuItemClickListener { menuItem ->
popup?.setOnMenuItemClickListener { menuItem ->
speedController.currentSpeed = speeds[menuItem.itemId]
speedMenu.dismiss()
true
}

speedMenu.show()
popup?.show()
}

private fun populateMenu(
Expand All @@ -57,4 +61,7 @@ class PlaybackSpeedAction(
menu.getItem(speeds.indexOf(speedController.currentSpeed)).isChecked = true
}

fun dismissPopup() {
popup?.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.playback.PlaybackController
import org.jellyfin.androidtv.ui.playback.PlaybackManager
import org.jellyfin.androidtv.ui.playback.overlay.CustomPlaybackTransportControlGlue
import org.jellyfin.androidtv.ui.playback.overlay.LeanbackOverlayFragment
import org.jellyfin.androidtv.ui.playback.overlay.VideoPlayerAdapter

class SelectAudioAction(
context: Context,
customPlaybackTransportControlGlue: CustomPlaybackTransportControlGlue,
private val playbackManager: PlaybackManager,
) : CustomAction(context, customPlaybackTransportControlGlue) {
private var popup: PopupMenu? = null

init {
initializeWithIcon(R.drawable.ic_select_audio)
}
Expand All @@ -31,7 +32,8 @@ class SelectAudioAction(
?: return
val currentAudioIndex = playbackController.audioStreamIndex

PopupMenu(context, view, Gravity.END).apply {
dismissPopup()
popup = PopupMenu(context, view, Gravity.END).apply {
with(menu) {
for (track in audioTracks) {
add(0, track.index, track.index, track.displayTitle).apply {
Expand All @@ -41,11 +43,19 @@ class SelectAudioAction(
setGroupCheckable(0, true, false)
}

setOnDismissListener { videoPlayerAdapter.leanbackOverlayFragment.setFading(true) }
setOnDismissListener {
videoPlayerAdapter.leanbackOverlayFragment.setFading(true)
popup = null
}
setOnMenuItemClickListener { item ->
playbackController.switchAudioStream(item.itemId)
true
}
}.show()
}
popup?.show()
}

fun dismissPopup() {
popup?.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SelectQualityAction(
private val previousQualitySelection = userPreferences[UserPreferences.maxBitrate]
private val qualityController = VideoQualityController(previousQualitySelection, userPreferences)
private val qualityProfiles = getQualityProfiles(context)
private var popup: PopupMenu? = null

init {
initializeWithIcon(R.drawable.ic_select_quality)
Expand All @@ -32,7 +33,8 @@ class SelectQualityAction(
view: View,
) {
videoPlayerAdapter.leanbackOverlayFragment.setFading(false)
PopupMenu(context, view, Gravity.END).apply {
dismissPopup()
popup = PopupMenu(context, view, Gravity.END).apply {
qualityProfiles.values.forEachIndexed { i, selected ->
menu.add(0, i, i, selected)
}
Expand All @@ -45,13 +47,21 @@ class SelectQualityAction(
}
}

setOnDismissListener { videoPlayerAdapter.leanbackOverlayFragment.setFading(true) }
setOnDismissListener {
videoPlayerAdapter.leanbackOverlayFragment.setFading(true)
popup = null
}
setOnMenuItemClickListener { menuItem ->
qualityController.currentQuality = qualityProfiles.keys.elementAt(menuItem.itemId)
playbackController.refreshStream()
dismiss()
true
}
}.show()
}
popup?.show()
}

fun dismissPopup() {
popup?.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jellyfin.androidtv.ui.playback.overlay.action
import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.PopupMenu
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.preference.constant.ZoomMode
import org.jellyfin.androidtv.ui.playback.PlaybackController
Expand All @@ -14,6 +15,8 @@ class ZoomAction(
context: Context,
customPlaybackTransportControlGlue: CustomPlaybackTransportControlGlue,
) : CustomAction(context, customPlaybackTransportControlGlue) {
private var popup: PopupMenu? = null

init {
initializeWithIcon(R.drawable.ic_aspect_ratio)
}
Expand All @@ -25,7 +28,8 @@ class ZoomAction(
view: View,
) {
videoPlayerAdapter.leanbackOverlayFragment.setFading(false)
val popup = popupMenu(context, view, Gravity.END) {
dismissPopup()
popup = popupMenu(context, view, Gravity.END) {
item(context.getString(R.string.lbl_fit)) {
playbackController.setZoom(ZoomMode.FIT)
}.apply {
Expand All @@ -44,8 +48,15 @@ class ZoomAction(
isChecked = playbackController.zoomMode == ZoomMode.STRETCH
}
}
popup.menu.setGroupCheckable(0, true, true)
popup.setOnDismissListener { videoPlayerAdapter.leanbackOverlayFragment.setFading(true) }
popup.show()
popup?.menu?.setGroupCheckable(0, true, true)
popup?.setOnDismissListener {
videoPlayerAdapter.leanbackOverlayFragment.setFading(true)
popup = null
}
popup?.show()
}

fun dismissPopup() {
popup?.dismiss()
}
}

0 comments on commit d91d873

Please sign in to comment.