Skip to content

Commit a898d75

Browse files
committed
Implement "play from here" for channels
1 parent 72c8668 commit a898d75

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.fragments.list.channel;
22

3+
import static org.schabi.newpipe.ui.components.menu.LongPressMenuKt.openLongPressMenuInActivity;
4+
35
import android.os.Bundle;
46
import android.util.Log;
57
import android.view.LayoutInflater;
@@ -26,12 +28,15 @@
2628
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
2729
import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue;
2830
import org.schabi.newpipe.player.playqueue.PlayQueue;
31+
import org.schabi.newpipe.ui.components.menu.LongPressAction;
32+
import org.schabi.newpipe.ui.components.menu.LongPressable;
2933
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
3034
import org.schabi.newpipe.util.ChannelTabHelper;
3135
import org.schabi.newpipe.util.ExtractorHelper;
3236
import org.schabi.newpipe.util.PlayButtonHelper;
3337

3438
import java.util.List;
39+
import java.util.function.Function;
3540
import java.util.function.Supplier;
3641
import java.util.stream.Collectors;
3742

@@ -165,13 +170,30 @@ public void handleResult(@NonNull final ChannelTabInfo result) {
165170
}
166171

167172
@Override
168-
public PlayQueue getPlayQueue() {
173+
protected void showInfoItemDialog(final StreamInfoItem item) {
174+
openLongPressMenuInActivity(
175+
requireActivity(),
176+
LongPressable.fromStreamInfoItem(item),
177+
LongPressAction.fromStreamInfoItem(item, () -> getPlayQueueStartingAt(item))
178+
);
179+
}
180+
181+
private PlayQueue getPlayQueueStartingAt(final StreamInfoItem infoItem) {
182+
return getPlayQueue(streamItems -> Math.max(streamItems.indexOf(infoItem), 0));
183+
}
184+
185+
public PlayQueue getPlayQueue(final Function<List<StreamInfoItem>, Integer> index) {
169186
final List<StreamInfoItem> streamItems = infoListAdapter.getItemsList().stream()
170187
.filter(StreamInfoItem.class::isInstance)
171188
.map(StreamInfoItem.class::cast)
172189
.collect(Collectors.toList());
173190

174191
return new ChannelTabPlayQueue(currentInfo.getServiceId(), tabHandler,
175-
currentInfo.getNextPage(), streamItems, 0);
192+
currentInfo.getNextPage(), streamItems, index.apply(streamItems));
193+
}
194+
195+
@Override
196+
public PlayQueue getPlayQueue() {
197+
return getPlayQueue(streamItems -> 0);
176198
}
177199
}

0 commit comments

Comments
 (0)