Skip to content

Commit d76976b

Browse files
committed
Only show Enqueue and EnqueueNext if player open
1 parent 79cd8df commit d76976b

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressAction.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import org.schabi.newpipe.local.dialog.PlaylistAppendDialog
4545
import org.schabi.newpipe.local.dialog.PlaylistDialog
4646
import org.schabi.newpipe.local.history.HistoryRecordManager
4747
import org.schabi.newpipe.local.playlist.LocalPlaylistManager
48+
import org.schabi.newpipe.player.helper.PlayerHolder
4849
import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue
4950
import org.schabi.newpipe.player.playqueue.PlayQueue
5051
import 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 ->

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import org.schabi.newpipe.error.ErrorInfo
8888
import org.schabi.newpipe.error.ErrorUtil
8989
import org.schabi.newpipe.error.UserAction.LONG_PRESS_MENU_ACTION
9090
import org.schabi.newpipe.extractor.stream.StreamType
91+
import org.schabi.newpipe.player.helper.PlayerHolder
9192
import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar
9293
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.EnqueueNext
9394
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.ShowChannelDetails
@@ -273,7 +274,7 @@ private fun LongPressMenuContent(
273274
icon = action.type.icon,
274275
text = stringResource(action.type.label),
275276
onClick = { runActionAndDismiss(action) },
276-
enabled = action.enabled(false),
277+
enabled = action.enabled(),
277278
modifier = Modifier
278279
.height(buttonHeight)
279280
.fillMaxWidth()

0 commit comments

Comments
 (0)