@@ -45,6 +45,7 @@ import org.schabi.newpipe.local.dialog.PlaylistAppendDialog
4545import org.schabi.newpipe.local.dialog.PlaylistDialog
4646import org.schabi.newpipe.local.history.HistoryRecordManager
4747import org.schabi.newpipe.local.playlist.LocalPlaylistManager
48+ import org.schabi.newpipe.player.helper.PlayerHolder
4849import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue
4950import org.schabi.newpipe.player.playqueue.PlayQueue
5051import org.schabi.newpipe.player.playqueue.PlayQueueItem
@@ -60,7 +61,7 @@ data class LongPressAction(
6061 val type : Type ,
6162 @MainThread
6263 val action : suspend (context: Context ) -> Unit ,
63- val enabled : (isPlayerRunning: Boolean ) -> Boolean = { true }
64+ val enabled : () -> Boolean = { true }
6465) {
6566 enum class Type (
6667 /* *
@@ -95,11 +96,10 @@ data class LongPressAction(
9596 Remove (21 , R .string.play_queue_remove, Icons .Default .Delete )
9697 ;
9798
98- // TODO allow actions to return disposables
9999 // TODO add actions that use the whole list the item belongs to (see wholeListQueue)
100100
101101 fun buildAction (
102- enabled : (isPlayerRunning: Boolean ) -> Boolean = { true },
102+ enabled : () -> Boolean = { true },
103103 action : suspend (context: Context ) -> Unit
104104 ) = LongPressAction (this , action, enabled)
105105
@@ -119,10 +119,20 @@ data class LongPressAction(
119119 queue : suspend (Context ) -> PlayQueue
120120 ): List <LongPressAction > {
121121 return listOf (
122- Type .Enqueue .buildAction({ isPlayerRunning -> isPlayerRunning }) { context ->
122+ // TODO once NewPlayer will be used, make it so that the enabled states of Enqueue
123+ // and EnqueueNext are a State<> that changes realtime based on the actual evolving
124+ // player state
125+ Type .Enqueue .buildAction(
126+ enabled = { PlayerHolder .isPlayQueueReady }
127+ ) { context ->
123128 NavigationHelper .enqueueOnPlayer(context, queue(context))
124129 },
125- Type .EnqueueNext .buildAction({ isPlayerRunning -> isPlayerRunning }) { context ->
130+ Type .EnqueueNext .buildAction(
131+ enabled = {
132+ PlayerHolder .isPlayQueueReady &&
133+ (PlayerHolder .queuePosition < PlayerHolder .queueSize - 1 )
134+ }
135+ ) { context ->
126136 NavigationHelper .enqueueNextOnPlayer(context, queue(context))
127137 },
128138 Type .Background .buildAction { context ->
0 commit comments