Skip to content

Commit bef134c

Browse files
committed
Implement background/popup/play from here
1 parent d820a8f commit bef134c

File tree

7 files changed

+35
-11
lines changed

7 files changed

+35
-11
lines changed

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
@@ -108,6 +108,20 @@ data class LongPressAction(
108108
)
109109
}
110110

111+
private fun buildPlayerFromHereActionList(queueFromHere: () -> PlayQueue): List<LongPressAction> {
112+
return listOf(
113+
Type.BackgroundFromHere.buildAction { context ->
114+
NavigationHelper.playOnBackgroundPlayer(context, queueFromHere(), true)
115+
},
116+
Type.PopupFromHere.buildAction { context ->
117+
NavigationHelper.playOnPopupPlayer(context, queueFromHere(), true)
118+
},
119+
Type.PlayFromHere.buildAction { context ->
120+
NavigationHelper.playOnMainPlayer(context, queueFromHere(), false)
121+
},
122+
)
123+
}
124+
111125
private fun buildShareActionList(item: InfoItem): List<LongPressAction> {
112126
return listOf(
113127
Type.Share.buildAction { context ->
@@ -130,13 +144,18 @@ data class LongPressAction(
130144
)
131145
}
132146

147+
/**
148+
* @param queueFromHere returns a play queue for the list that contains [item], with the
149+
* queue index pointing to [item], used to build actions like "Play playlist from here".
150+
*/
133151
@JvmStatic
134152
fun fromStreamInfoItem(
135153
item: StreamInfoItem,
154+
queueFromHere: (() -> PlayQueue)?,
136155
/* TODO isKodiEnabled: Boolean, */
137-
/* TODO wholeListQueue: (() -> PlayQueue)? */
138156
): List<LongPressAction> {
139157
return buildPlayerActionList { SinglePlayQueue(item) } +
158+
(queueFromHere?.let { buildPlayerFromHereActionList(queueFromHere) } ?: listOf()) +
140159
buildShareActionList(item) +
141160
listOf(
142161
Type.Download.buildAction { context ->
@@ -192,18 +211,20 @@ data class LongPressAction(
192211
@JvmStatic
193212
fun fromStreamEntity(
194213
item: StreamEntity,
214+
queueFromHere: (() -> PlayQueue)?,
195215
): List<LongPressAction> {
196216
// TODO decide if it's fine to just convert to StreamInfoItem here (it poses an
197217
// unnecessary dependency on the extractor, when we want to just look at data; maybe
198218
// using something like LongPressable would work)
199-
return fromStreamInfoItem(item.toStreamInfoItem())
219+
return fromStreamInfoItem(item.toStreamInfoItem(), queueFromHere)
200220
}
201221

202222
@JvmStatic
203223
fun fromStreamStatisticsEntry(
204224
item: StreamStatisticsEntry,
225+
queueFromHere: (() -> PlayQueue)?,
205226
): List<LongPressAction> {
206-
return fromStreamEntity(item.streamEntity) +
227+
return fromStreamEntity(item.streamEntity, queueFromHere) +
207228
listOf(
208229
Type.Delete.buildAction { context ->
209230
HistoryRecordManager(context)
@@ -223,11 +244,12 @@ data class LongPressAction(
223244
@JvmStatic
224245
fun fromPlaylistStreamEntry(
225246
item: PlaylistStreamEntry,
247+
queueFromHere: (() -> PlayQueue)?,
226248
// TODO possibly embed these two actions here
227249
onDelete: Runnable,
228250
onSetAsPlaylistThumbnail: Runnable,
229251
): List<LongPressAction> {
230-
return fromStreamEntity(item.streamEntity) +
252+
return fromStreamEntity(item.streamEntity, queueFromHere) +
231253
listOf(
232254
Type.Delete.buildAction { onDelete.run() },
233255
Type.SetAsPlaylistThumbnail.buildAction { onSetAsPlaylistThumbnail.run() }

0 commit comments

Comments
 (0)