Skip to content

Commit 09ba278

Browse files
committed
Implement "play from here" for feed fragment
1 parent c2a5f51 commit 09ba278

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import org.schabi.newpipe.ktx.slideUp
7373
import org.schabi.newpipe.local.feed.item.StreamItem
7474
import org.schabi.newpipe.local.feed.service.FeedLoadService
7575
import org.schabi.newpipe.local.subscription.SubscriptionManager
76+
import org.schabi.newpipe.player.playqueue.SinglePlayQueue
7677
import org.schabi.newpipe.ui.components.menu.LongPressAction
7778
import org.schabi.newpipe.ui.components.menu.LongPressable
7879
import org.schabi.newpipe.ui.components.menu.openLongPressMenuInActivity
@@ -384,7 +385,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
384385
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
385386
override fun onItemClick(item: Item<*>, view: View) {
386387
if (item is StreamItem && !isRefreshing) {
387-
val stream = item.streamWithState.stream
388+
val stream = item.stream
388389
NavigationHelper.openVideoDetailFragment(
389390
requireContext(),
390391
fm,
@@ -401,9 +402,31 @@ class FeedFragment : BaseStateFragment<FeedState>() {
401402
if (item is StreamItem && !isRefreshing) {
402403
openLongPressMenuInActivity(
403404
requireActivity(),
404-
LongPressable.fromStreamEntity(item.streamWithState.stream),
405-
// TODO queueFromHere: allow playing the whole feed starting from one stream
406-
LongPressAction.fromStreamEntity(item.streamWithState.stream, null),
405+
LongPressable.fromStreamEntity(item.stream),
406+
LongPressAction.fromStreamEntity(
407+
item = item.stream,
408+
queueFromHere = {
409+
val items = (viewModel.stateLiveData.value as? FeedState.LoadedState)
410+
?.items
411+
412+
if (items != null) {
413+
val index = items.indexOf(item)
414+
if (index >= 0) {
415+
return@fromStreamEntity SinglePlayQueue(
416+
items.map { it.stream.toStreamInfoItem() },
417+
index
418+
)
419+
}
420+
}
421+
422+
// when long-pressing on an item the state should be LoadedState and the
423+
// item list should contain the long-pressed item, so the following
424+
// statement should be unreachable, but let's return a SinglePlayQueue
425+
// just in case
426+
Log.w(TAG, "Could not get full list of items on long press")
427+
return@fromStreamEntity SinglePlayQueue(item.stream.toStreamInfoItem())
428+
},
429+
),
407430
)
408431
return true
409432
}
@@ -575,7 +598,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
575598
}
576599
if (doCheck) {
577600
// If the uploadDate is null or true we should highlight the item
578-
if (item.streamWithState.stream.uploadDate?.isAfter(updateTime) != false) {
601+
if (item.stream.uploadDate?.isAfter(updateTime) != false) {
579602
highlightCount++
580603

581604
typeface = Typeface.DEFAULT_BOLD

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data class StreamItem(
3030
const val UPDATE_RELATIVE_TIME = 1
3131
}
3232

33-
private val stream: StreamEntity = streamWithState.stream
33+
val stream: StreamEntity = streamWithState.stream
3434
private val stateProgressTime: Long? = streamWithState.stateProgressMillis
3535

3636
/**

0 commit comments

Comments
 (0)