Skip to content

Commit 72c8668

Browse files
committed
Implement "play from here" for feed fragment
1 parent bef134c commit 72c8668

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

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
@@ -71,6 +71,7 @@ import org.schabi.newpipe.ktx.slideUp
7171
import org.schabi.newpipe.local.feed.item.StreamItem
7272
import org.schabi.newpipe.local.feed.service.FeedLoadService
7373
import org.schabi.newpipe.local.subscription.SubscriptionManager
74+
import org.schabi.newpipe.player.playqueue.SinglePlayQueue
7475
import org.schabi.newpipe.ui.components.menu.LongPressAction
7576
import org.schabi.newpipe.ui.components.menu.LongPressable
7677
import org.schabi.newpipe.ui.components.menu.openLongPressMenuInActivity
@@ -382,7 +383,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
382383
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
383384
override fun onItemClick(item: Item<*>, view: View) {
384385
if (item is StreamItem && !isRefreshing) {
385-
val stream = item.streamWithState.stream
386+
val stream = item.stream
386387
NavigationHelper.openVideoDetailFragment(
387388
requireContext(), fm,
388389
stream.serviceId, stream.url, stream.title, null, false
@@ -394,9 +395,31 @@ class FeedFragment : BaseStateFragment<FeedState>() {
394395
if (item is StreamItem && !isRefreshing) {
395396
openLongPressMenuInActivity(
396397
requireActivity(),
397-
LongPressable.fromStreamEntity(item.streamWithState.stream),
398-
// TODO queueFromHere: allow playing the whole feed starting from one stream
399-
LongPressAction.fromStreamEntity(item.streamWithState.stream, null),
398+
LongPressable.fromStreamEntity(item.stream),
399+
LongPressAction.fromStreamEntity(
400+
item = item.stream,
401+
queueFromHere = {
402+
val items = (viewModel.stateLiveData.value as? FeedState.LoadedState)
403+
?.items
404+
405+
if (items != null) {
406+
val index = items.indexOf(item)
407+
if (index >= 0) {
408+
return@fromStreamEntity SinglePlayQueue(
409+
items.map { it.stream.toStreamInfoItem() },
410+
index
411+
)
412+
}
413+
}
414+
415+
// when long-pressing on an item the state should be LoadedState and the
416+
// item list should contain the long-pressed item, so the following
417+
// statement should be unreachable, but let's return a SinglePlayQueue
418+
// just in case
419+
Log.w(TAG, "Could not get full list of items on long press")
420+
return@fromStreamEntity SinglePlayQueue(item.stream.toStreamInfoItem())
421+
},
422+
),
400423
)
401424
return true
402425
}
@@ -566,7 +589,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
566589
}
567590
if (doCheck) {
568591
// If the uploadDate is null or true we should highlight the item
569-
if (item.streamWithState.stream.uploadDate?.isAfter(updateTime) != false) {
592+
if (item.stream.uploadDate?.isAfter(updateTime) != false) {
570593
highlightCount++
571594

572595
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)