-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire up view for Playback speed controls
Wires up the view component for playback speed controls, based on the pattern used in various other action items.
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/org/jellyfin/androidtv/ui/playback/overlay/action/PlaybackSpeedAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jellyfin.androidtv.ui.playback.overlay.action | ||
|
||
import android.content.Context | ||
import org.jellyfin.androidtv.ui.playback.overlay.CustomPlaybackTransportControlGlue | ||
import org.jellyfin.androidtv.ui.playback.PlaybackController | ||
import org.jellyfin.androidtv.ui.playback.overlay.LeanbackOverlayFragment | ||
import android.view.Gravity | ||
import android.view.MenuItem | ||
import android.view.View | ||
import android.widget.PopupMenu | ||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.ui.playback.VideoSpeedController | ||
|
||
class PlaybackSpeedAction( | ||
context: Context, | ||
customPlaybackTransportControlGlue: CustomPlaybackTransportControlGlue | ||
) : CustomAction(context, customPlaybackTransportControlGlue) { | ||
private val speeds = VideoSpeedController.Companion.SpeedSteps.values() | ||
|
||
init { | ||
initializeWithIcon(R.drawable.exo_ic_speed) | ||
} | ||
|
||
override fun handleClickAction( | ||
playbackController: PlaybackController, | ||
leanbackOverlayFragment: LeanbackOverlayFragment, | ||
context: Context, view: View | ||
) { | ||
val speedController = VideoSpeedController(playbackController) | ||
val speedMenu = populateMenu(context, view, speedController) | ||
|
||
speedMenu.setOnDismissListener { leanbackOverlayFragment.setFading(true) } | ||
|
||
speedMenu.setOnMenuItemClickListener { menuItem -> | ||
speedController.setNewSpeed(speeds[menuItem.itemId]) | ||
speedMenu.dismiss() | ||
return@setOnMenuItemClickListener true | ||
} | ||
|
||
speedMenu.show() | ||
} | ||
|
||
private fun populateMenu( | ||
context: Context, | ||
view: View, | ||
speedController: VideoSpeedController | ||
): PopupMenu { | ||
val speedMenu = PopupMenu(context, view, Gravity.END) | ||
val menu = speedMenu.menu | ||
speeds.forEachIndexed { i, speed -> | ||
menu.add(0, i, i, String.format("%.2fx", speed.value)) | ||
} | ||
|
||
menu.setGroupCheckable(0, true, true) | ||
menu.getItem(speeds.indexOf(speedController.getCurrentSpeed())).isChecked = true | ||
return speedMenu | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters