Added sharing a link with timestamp from a chapter into the long click for each chapter

This commit is contained in:
Daniel M 2022-10-24 14:14:41 +11:00
parent 2a98cca801
commit 83357ca67e
3 changed files with 23 additions and 5 deletions

View File

@ -61,5 +61,6 @@ class StreamSegmentAdapter(
interface StreamSegmentListener { interface StreamSegmentListener {
fun onItemClick(item: StreamSegmentItem, seconds: Int) fun onItemClick(item: StreamSegmentItem, seconds: Int)
fun onItemLongClick(item: StreamSegmentItem, seconds: Int)
} }
} }

View File

@ -41,6 +41,7 @@ class StreamSegmentItem(
viewHolder.root.findViewById<TextView>(R.id.textViewStartSeconds).text = viewHolder.root.findViewById<TextView>(R.id.textViewStartSeconds).text =
Localization.getDurationString(item.startTimeSeconds.toLong()) Localization.getDurationString(item.startTimeSeconds.toLong())
viewHolder.root.setOnClickListener { onClick.onItemClick(this, item.startTimeSeconds) } viewHolder.root.setOnClickListener { onClick.onItemClick(this, item.startTimeSeconds) }
viewHolder.root.setOnLongClickListener { onClick.onItemLongClick(this, item.startTimeSeconds); true }
viewHolder.root.isSelected = isSelected viewHolder.root.isSelected = isSelected
} }

View File

@ -52,6 +52,7 @@ import org.schabi.newpipe.extractor.stream.StreamSegment;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.info_list.StreamSegmentAdapter; import org.schabi.newpipe.info_list.StreamSegmentAdapter;
import org.schabi.newpipe.info_list.StreamSegmentItem;
import org.schabi.newpipe.ktx.AnimationType; import org.schabi.newpipe.ktx.AnimationType;
import org.schabi.newpipe.local.dialog.PlaylistDialog; import org.schabi.newpipe.local.dialog.PlaylistDialog;
import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.Player;
@ -69,6 +70,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.external_communication.KoreUtils; import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -644,7 +646,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
private void buildSegments() { private void buildSegments() {
binding.itemsList.setAdapter(segmentAdapter); binding.itemsList.setAdapter(segmentAdapter);
binding.itemsList.setClickable(true); binding.itemsList.setClickable(true);
binding.itemsList.setLongClickable(false); binding.itemsList.setLongClickable(true);
binding.itemsList.clearOnScrollListeners(); binding.itemsList.clearOnScrollListeners();
if (itemTouchHelper != null) { if (itemTouchHelper != null) {
@ -696,10 +698,24 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
} }
private StreamSegmentAdapter.StreamSegmentListener getStreamSegmentListener() { private StreamSegmentAdapter.StreamSegmentListener getStreamSegmentListener() {
return (item, seconds) -> { return new StreamSegmentAdapter.StreamSegmentListener() {
segmentAdapter.selectSegment(item); @Override
player.seekTo(seconds * 1000L); public void onItemClick(@NonNull final StreamSegmentItem item, final int seconds) {
player.triggerProgressUpdate(); segmentAdapter.selectSegment(item);
player.seekTo(seconds * 1000L);
player.triggerProgressUpdate();
}
@Override
public void onItemLongClick(@NonNull final StreamSegmentItem item, final int seconds) {
final PlayQueueItem currentItem = player.getCurrentItem();
if (currentItem != null) {
String videoUrl = player.getVideoUrl();
videoUrl += ("&t=" + seconds);
ShareUtils.shareText(context, currentItem.getTitle(),
videoUrl, currentItem.getThumbnailUrl());
}
}
}; };
} }