Skip to content

Commit 87727e7

Browse files
committed
Implement getPlayQueueStartingAt for Compose ItemList too
1 parent a4c2e03 commit 87727e7

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
1919
import org.schabi.newpipe.extractor.stream.StreamInfoItem
2020
import org.schabi.newpipe.info_list.ItemViewMode
2121
import org.schabi.newpipe.ktx.findFragmentActivity
22+
import org.schabi.newpipe.player.playqueue.PlayQueue
2223
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
2324
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
2425
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
2526
import org.schabi.newpipe.util.DependentPreferenceHelper
2627
import org.schabi.newpipe.util.NavigationHelper
2728

29+
/**
30+
* @param getPlayQueueStartingAt a builder for a queue containing all of the items in this list,
31+
* with the queue index set to the item passed as parameter; return `null` if no "start playing from
32+
* here" options should be shown in the long press menu
33+
*/
2834
@Composable
2935
fun ItemList(
3036
items: List<InfoItem>,
37+
getPlayQueueStartingAt: ((item: StreamInfoItem) -> PlayQueue)? = null,
3138
mode: ItemViewMode = determineItemViewMode(),
3239
listHeader: LazyListScope.() -> Unit = {}
3340
) {
@@ -72,7 +79,7 @@ fun ItemList(
7279
val item = items[it]
7380

7481
if (item is StreamInfoItem) {
75-
StreamListItem(item, showProgress, onClick)
82+
StreamListItem(item, showProgress, getPlayQueueStartingAt, onClick)
7683
} else if (item is PlaylistInfoItem) {
7784
PlaylistListItem(item, onClick)
7885
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@ import androidx.compose.ui.tooling.preview.Preview
2626
import androidx.compose.ui.tooling.preview.PreviewParameter
2727
import androidx.compose.ui.unit.dp
2828
import org.schabi.newpipe.extractor.stream.StreamInfoItem
29+
import org.schabi.newpipe.player.playqueue.PlayQueue
2930
import org.schabi.newpipe.ui.components.menu.LongPressAction
3031
import org.schabi.newpipe.ui.components.menu.LongPressMenu
3132
import org.schabi.newpipe.ui.components.menu.LongPressable
3233
import org.schabi.newpipe.ui.theme.AppTheme
3334

35+
/**
36+
* @param getPlayQueueStartingAt a builder for a queue containing all of the items in this list,
37+
* with the queue index set to the item passed as parameter; return `null` if no "start playing from
38+
* here" options should be shown in the long press menu
39+
*/
3440
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
3541
@Composable
3642
fun StreamListItem(
3743
stream: StreamInfoItem,
3844
showProgress: Boolean,
45+
getPlayQueueStartingAt: ((item: StreamInfoItem) -> PlayQueue)? = null,
3946
onClick: (StreamInfoItem) -> Unit = {}
4047
) {
4148
var showLongPressMenu by rememberSaveable { mutableStateOf(false) }
@@ -79,8 +86,10 @@ fun StreamListItem(
7986
if (showLongPressMenu) {
8087
LongPressMenu(
8188
longPressable = LongPressable.fromStreamInfoItem(stream),
82-
// TODO queueFromHere: allow playing the whole list starting from one stream
83-
longPressActions = LongPressAction.fromStreamInfoItem(stream, null),
89+
longPressActions = LongPressAction.fromStreamInfoItem(
90+
stream,
91+
getPlayQueueStartingAt?.let { { it(stream) } }
92+
),
8493
onDismissRequest = { showLongPressMenu = false }
8594
)
8695
}

app/src/main/java/org/schabi/newpipe/ui/components/video/RelatedItems.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fun RelatedItems(info: StreamInfo) {
4444

4545
ItemList(
4646
items = info.relatedItems,
47+
getPlayQueueStartingAt = null, // it does not make sense to play related items "from here"
4748
mode = ItemViewMode.LIST,
4849
listHeader = {
4950
item {

0 commit comments

Comments
 (0)