From 83357ca67e2ff3a7b835aba1721bde572e7d2f9e Mon Sep 17 00:00:00 2001 From: Daniel M Date: Mon, 24 Oct 2022 14:14:41 +1100 Subject: [PATCH] Added sharing a link with timestamp from a chapter into the long click for each chapter --- .../newpipe/info_list/StreamSegmentAdapter.kt | 1 + .../newpipe/info_list/StreamSegmentItem.kt | 1 + .../newpipe/player/ui/MainPlayerUi.java | 26 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentAdapter.kt b/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentAdapter.kt index 9fb4bfbb3..869bf6f48 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentAdapter.kt +++ b/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentAdapter.kt @@ -61,5 +61,6 @@ class StreamSegmentAdapter( interface StreamSegmentListener { fun onItemClick(item: StreamSegmentItem, seconds: Int) + fun onItemLongClick(item: StreamSegmentItem, seconds: Int) } } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentItem.kt b/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentItem.kt index f233c7627..5fc8aa684 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentItem.kt +++ b/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentItem.kt @@ -41,6 +41,7 @@ class StreamSegmentItem( viewHolder.root.findViewById(R.id.textViewStartSeconds).text = Localization.getDurationString(item.startTimeSeconds.toLong()) viewHolder.root.setOnClickListener { onClick.onItemClick(this, item.startTimeSeconds) } + viewHolder.root.setOnLongClickListener { onClick.onItemLongClick(this, item.startTimeSeconds); true } viewHolder.root.isSelected = isSelected } diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java index 81dc954d1..4f00bcf12 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java @@ -52,6 +52,7 @@ import org.schabi.newpipe.extractor.stream.StreamSegment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.info_list.StreamSegmentAdapter; +import org.schabi.newpipe.info_list.StreamSegmentItem; import org.schabi.newpipe.ktx.AnimationType; import org.schabi.newpipe.local.dialog.PlaylistDialog; 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.NavigationHelper; import org.schabi.newpipe.util.external_communication.KoreUtils; +import org.schabi.newpipe.util.external_communication.ShareUtils; import java.util.List; import java.util.Objects; @@ -644,7 +646,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh private void buildSegments() { binding.itemsList.setAdapter(segmentAdapter); binding.itemsList.setClickable(true); - binding.itemsList.setLongClickable(false); + binding.itemsList.setLongClickable(true); binding.itemsList.clearOnScrollListeners(); if (itemTouchHelper != null) { @@ -696,10 +698,24 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh } private StreamSegmentAdapter.StreamSegmentListener getStreamSegmentListener() { - return (item, seconds) -> { - segmentAdapter.selectSegment(item); - player.seekTo(seconds * 1000L); - player.triggerProgressUpdate(); + return new StreamSegmentAdapter.StreamSegmentListener() { + @Override + public void onItemClick(@NonNull final StreamSegmentItem item, final int seconds) { + 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()); + } + } }; }