Implement getPlayQueueStartingAt for Compose ItemList too

This commit is contained in:
Stypox 2026-02-09 10:39:17 +01:00
parent f65094b5fd
commit d561444836
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 20 additions and 3 deletions

View File

@ -19,15 +19,22 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.info_list.ItemViewMode
import org.schabi.newpipe.ktx.findFragmentActivity
import org.schabi.newpipe.player.playqueue.PlayQueue
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
import org.schabi.newpipe.util.DependentPreferenceHelper
import org.schabi.newpipe.util.NavigationHelper
/**
* @param getPlayQueueStartingAt a builder for a queue containing all of the items in this list,
* with the queue index set to the item passed as parameter; return `null` if no "start playing from
* here" options should be shown in the long press menu
*/
@Composable
fun ItemList(
items: List<InfoItem>,
getPlayQueueStartingAt: ((item: StreamInfoItem) -> PlayQueue)? = null,
mode: ItemViewMode = determineItemViewMode(),
listHeader: LazyListScope.() -> Unit = {}
) {
@ -72,7 +79,7 @@ fun ItemList(
val item = items[it]
if (item is StreamInfoItem) {
StreamListItem(item, showProgress, onClick)
StreamListItem(item, showProgress, getPlayQueueStartingAt, onClick)
} else if (item is PlaylistInfoItem) {
PlaylistListItem(item, onClick)
}

View File

@ -26,16 +26,23 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.player.playqueue.PlayQueue
import org.schabi.newpipe.ui.components.menu.LongPressAction
import org.schabi.newpipe.ui.components.menu.LongPressMenu
import org.schabi.newpipe.ui.components.menu.LongPressable
import org.schabi.newpipe.ui.theme.AppTheme
/**
* @param getPlayQueueStartingAt a builder for a queue containing all of the items in this list,
* with the queue index set to the item passed as parameter; return `null` if no "start playing from
* here" options should be shown in the long press menu
*/
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun StreamListItem(
stream: StreamInfoItem,
showProgress: Boolean,
getPlayQueueStartingAt: ((item: StreamInfoItem) -> PlayQueue)? = null,
onClick: (StreamInfoItem) -> Unit = {}
) {
var showLongPressMenu by rememberSaveable { mutableStateOf(false) }
@ -79,8 +86,10 @@ fun StreamListItem(
if (showLongPressMenu) {
LongPressMenu(
longPressable = LongPressable.fromStreamInfoItem(stream),
// TODO queueFromHere: allow playing the whole list starting from one stream
longPressActions = LongPressAction.fromStreamInfoItem(stream, null),
longPressActions = LongPressAction.fromStreamInfoItem(
stream,
getPlayQueueStartingAt?.let { { it(stream) } }
),
onDismissRequest = { showLongPressMenu = false }
)
}

View File

@ -44,6 +44,7 @@ fun RelatedItems(info: StreamInfo) {
ItemList(
items = info.relatedItems,
getPlayQueueStartingAt = null, // it does not make sense to play related items "from here"
mode = ItemViewMode.LIST,
listHeader = {
item {