From 83357ca67e2ff3a7b835aba1721bde572e7d2f9e Mon Sep 17 00:00:00 2001 From: Daniel M Date: Mon, 24 Oct 2022 14:14:41 +1100 Subject: [PATCH 1/2] 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()); + } + } }; } From 7f3da04fee98479f2fea17e5afebbeee73146358 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Sun, 30 Oct 2022 13:48:03 +1100 Subject: [PATCH 2/2] Added an "isYouTube" check to start of long click handler --- .../java/org/schabi/newpipe/player/ui/MainPlayerUi.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 4f00bcf12..248104738 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.player.ui; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static org.schabi.newpipe.MainActivity.DEBUG; import static org.schabi.newpipe.QueueItemMenuUtil.openPopupMenu; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.ktx.ViewUtils.animate; import static org.schabi.newpipe.player.Player.STATE_COMPLETED; import static org.schabi.newpipe.player.Player.STATE_PAUSED; @@ -61,6 +62,7 @@ import org.schabi.newpipe.player.gesture.BasePlayerGestureListener; import org.schabi.newpipe.player.gesture.MainPlayerGestureListener; import org.schabi.newpipe.player.helper.PlaybackParameterDialog; import org.schabi.newpipe.player.helper.PlayerHelper; +import org.schabi.newpipe.player.mediaitem.MediaItemTag; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueueAdapter; import org.schabi.newpipe.player.playqueue.PlayQueueItem; @@ -708,6 +710,12 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh @Override public void onItemLongClick(@NonNull final StreamSegmentItem item, final int seconds) { + @Nullable final MediaItemTag currentMetadata = player.getCurrentMetadata(); + if (currentMetadata == null + || currentMetadata.getServiceId() != YouTube.getServiceId()) { + return; + } + final PlayQueueItem currentItem = player.getCurrentItem(); if (currentItem != null) { String videoUrl = player.getVideoUrl();