Skip to content

Commit cec06d2

Browse files
committed
Implement background/popup/play from here
1 parent 768fa8b commit cec06d2

7 files changed

Lines changed: 35 additions & 11 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ protected void showInfoItemDialog(final StreamInfoItem item) {
329329
openLongPressMenuInActivity(
330330
requireActivity(),
331331
LongPressable.fromStreamInfoItem(item),
332-
LongPressAction.fromStreamInfoItem(item)
332+
// TODO generalize obtaining queue from here when fully migrating to Compose
333+
LongPressAction.fromStreamInfoItem(item, null)
333334
);
334335
}
335336

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ protected void showInfoItemDialog(final StreamInfoItem item) {
153153
openLongPressMenuInActivity(
154154
activity,
155155
LongPressable.fromStreamInfoItem(item),
156-
// TODO handle play queue starting at
157-
LongPressAction.fromStreamInfoItem(item)
156+
LongPressAction.fromStreamInfoItem(item, () -> getPlayQueueStartingAt(item))
158157
);
159158
}
160159

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
395395
openLongPressMenuInActivity(
396396
requireActivity(),
397397
LongPressable.fromStreamEntity(item.streamWithState.stream),
398-
LongPressAction.fromStreamEntity(item.streamWithState.stream),
398+
// TODO queueFromHere: allow playing the whole feed starting from one stream
399+
LongPressAction.fromStreamEntity(item.streamWithState.stream, null),
399400
)
400401
return true
401402
}

app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private void showInfoItemDialog(final StreamStatisticsEntry item) {
319319
openLongPressMenuInActivity(
320320
requireActivity(),
321321
LongPressable.fromStreamEntity(item.getStreamEntity()),
322-
LongPressAction.fromStreamStatisticsEntry(item)
322+
LongPressAction.fromStreamStatisticsEntry(item, () -> getPlayQueueStartingAt(item))
323323
);
324324
}
325325

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,9 @@ protected void showInfoItemDialog(final PlaylistStreamEntry item) {
801801
openLongPressMenuInActivity(
802802
requireActivity(),
803803
LongPressable.fromStreamEntity(item.getStreamEntity()),
804-
// TODO getPlayQueueStartingAt(), resumePlayback=true
805804
LongPressAction.fromPlaylistStreamEntry(
806805
item,
806+
() -> getPlayQueueStartingAt(item),
807807
() -> deleteItem(item),
808808
() -> changeThumbnailStreamId(item.getStreamEntity().getUid(), true)
809809
)

app/src/main/java/org/schabi/newpipe/ui/components/items/stream/StreamListItem.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ fun StreamListItem(
7979
if (showLongPressMenu) {
8080
LongPressMenu(
8181
longPressable = LongPressable.fromStreamInfoItem(stream),
82-
longPressActions = LongPressAction.fromStreamInfoItem(stream),
82+
// TODO queueFromHere: allow playing the whole list starting from one stream
83+
longPressActions = LongPressAction.fromStreamInfoItem(stream, null),
8384
onDismissRequest = { showLongPressMenu = false },
8485
)
8586
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ data class LongPressAction(
111111
)
112112
}
113113

114+
private fun buildPlayerFromHereActionList(queueFromHere: () -> PlayQueue): List<LongPressAction> {
115+
return listOf(
116+
Type.BackgroundFromHere.buildAction { context ->
117+
NavigationHelper.playOnBackgroundPlayer(context, queueFromHere(), true)
118+
},
119+
Type.PopupFromHere.buildAction { context ->
120+
NavigationHelper.playOnPopupPlayer(context, queueFromHere(), true)
121+
},
122+
Type.PlayFromHere.buildAction { context ->
123+
NavigationHelper.playOnMainPlayer(context, queueFromHere(), false)
124+
},
125+
)
126+
}
127+
114128
private fun buildShareActionList(item: InfoItem): List<LongPressAction> {
115129
return listOf(
116130
Type.Share.buildAction { context ->
@@ -133,13 +147,18 @@ data class LongPressAction(
133147
)
134148
}
135149

150+
/**
151+
* @param queueFromHere returns a play queue for the list that contains [item], with the
152+
* queue index pointing to [item], used to build actions like "Play playlist from here".
153+
*/
136154
@JvmStatic
137155
fun fromStreamInfoItem(
138156
item: StreamInfoItem,
157+
queueFromHere: (() -> PlayQueue)?,
139158
/* TODO isKodiEnabled: Boolean, */
140-
/* TODO wholeListQueue: (() -> PlayQueue)? */
141159
): List<LongPressAction> {
142160
return buildPlayerActionList { SinglePlayQueue(item) } +
161+
(queueFromHere?.let { buildPlayerFromHereActionList(queueFromHere) } ?: listOf()) +
143162
buildShareActionList(item) +
144163
listOf(
145164
Type.Download.buildAction { context ->
@@ -205,18 +224,20 @@ data class LongPressAction(
205224
@JvmStatic
206225
fun fromStreamEntity(
207226
item: StreamEntity,
227+
queueFromHere: (() -> PlayQueue)?,
208228
): List<LongPressAction> {
209229
// TODO decide if it's fine to just convert to StreamInfoItem here (it poses an
210230
// unnecessary dependency on the extractor, when we want to just look at data; maybe
211231
// using something like LongPressable would work)
212-
return fromStreamInfoItem(item.toStreamInfoItem())
232+
return fromStreamInfoItem(item.toStreamInfoItem(), queueFromHere)
213233
}
214234

215235
@JvmStatic
216236
fun fromStreamStatisticsEntry(
217237
item: StreamStatisticsEntry,
238+
queueFromHere: (() -> PlayQueue)?,
218239
): List<LongPressAction> {
219-
return fromStreamEntity(item.streamEntity) +
240+
return fromStreamEntity(item.streamEntity, queueFromHere) +
220241
listOf(
221242
Type.Delete.buildAction { context ->
222243
HistoryRecordManager(context)
@@ -236,11 +257,12 @@ data class LongPressAction(
236257
@JvmStatic
237258
fun fromPlaylistStreamEntry(
238259
item: PlaylistStreamEntry,
260+
queueFromHere: (() -> PlayQueue)?,
239261
// TODO possibly embed these two actions here
240262
onDelete: Runnable,
241263
onSetAsPlaylistThumbnail: Runnable,
242264
): List<LongPressAction> {
243-
return fromStreamEntity(item.streamEntity) +
265+
return fromStreamEntity(item.streamEntity, queueFromHere) +
244266
listOf(
245267
Type.Delete.buildAction { onDelete.run() },
246268
Type.SetAsPlaylistThumbnail.buildAction { onSetAsPlaylistThumbnail.run() }

0 commit comments

Comments
 (0)