From 6421d3017eb0a139ee1b45be6b92189ac81453b7 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Wed, 13 Mar 2019 07:01:03 +0530 Subject: [PATCH 1/3] seek on clicking timestamp links in comments --- .../holder/CommentsMiniInfoItemHolder.java | 2 +- .../org/schabi/newpipe/player/BasePlayer.java | 12 ++++++++++++ .../player/playqueue/SinglePlayQueue.java | 5 +++++ .../util/CommentTextOnTouchListener.java | 17 ++++++++++------- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index 9be272198..b8362f947 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -45,7 +45,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { if(hours != null) timestamp += (Integer.parseInt(hours.replace(":", ""))*3600); if(minutes != null) timestamp += (Integer.parseInt(minutes.replace(":", ""))*60); if(seconds != null) timestamp += (Integer.parseInt(seconds)); - return streamUrl + url.replace(match.group(0), "&t=" + String.valueOf(timestamp)); + return streamUrl + url.replace(match.group(0), "#timestamp=" + String.valueOf(timestamp)); } }; diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 4d5f29148..22c69fdd4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -269,6 +269,18 @@ public abstract class BasePlayer implements final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE, getPlaybackSkipSilence()); + // seek to timestamp if stream is already playing + if (simpleExoPlayer != null + && queue.size() == 1 + && playQueue != null + && playQueue.getItem() != null + && queue.getItem().getUrl().equals(playQueue.getItem().getUrl()) + && queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET + ) { + simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition()); + return; + } + // Good to go... initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, /*playOnInit=*/true); diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java index 5993481e2..40d1a11e7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java @@ -16,6 +16,11 @@ public final class SinglePlayQueue extends PlayQueue { super(0, Collections.singletonList(new PlayQueueItem(info))); } + public SinglePlayQueue(final StreamInfo info, final long startPosition) { + super(0, Collections.singletonList(new PlayQueueItem(info))); + getItem().setRecoveryPosition(startPosition); + } + public SinglePlayQueue(final List items, final int index) { super(index, playQueueItemsOf(items)); } diff --git a/app/src/main/java/org/schabi/newpipe/util/CommentTextOnTouchListener.java b/app/src/main/java/org/schabi/newpipe/util/CommentTextOnTouchListener.java index 570b5f8b2..e1ecc662d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/CommentTextOnTouchListener.java +++ b/app/src/main/java/org/schabi/newpipe/util/CommentTextOnTouchListener.java @@ -31,7 +31,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener { public static final CommentTextOnTouchListener INSTANCE = new CommentTextOnTouchListener(); - private static final Pattern timestampPattern = Pattern.compile(".*&t=(\\d+)"); + private static final Pattern timestampPattern = Pattern.compile("(.*)#timestamp=(\\d+)"); @Override public boolean onTouch(View v, MotionEvent event) { @@ -86,6 +86,12 @@ public class CommentTextOnTouchListener implements View.OnTouchListener { private boolean handleUrl(Context context, URLSpan urlSpan) { String url = urlSpan.getURL(); + int seconds = -1; + Matcher matcher = timestampPattern.matcher(url); + if(matcher.matches()){ + url = matcher.group(1); + seconds = Integer.parseInt(matcher.group(2)); + } StreamingService service; StreamingService.LinkType linkType; try { @@ -97,9 +103,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener { if(linkType == StreamingService.LinkType.NONE){ return false; } - Matcher matcher = timestampPattern.matcher(url); - if(linkType == StreamingService.LinkType.STREAM && matcher.matches()){ - int seconds = Integer.parseInt(matcher.group(1)); + if(linkType == StreamingService.LinkType.STREAM && seconds != -1){ return playOnPopup(context, url, service, seconds); }else{ NavigationHelper.openRouterActivity(context, url); @@ -119,9 +123,8 @@ public class CommentTextOnTouchListener implements View.OnTouchListener { single.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(info -> { - PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info); - ((StreamInfo) info).setStartPosition(seconds); - NavigationHelper.enqueueOnPopupPlayer(context, playQueue, true); + PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info, seconds*1000); + NavigationHelper.playOnPopupPlayer(context, playQueue); }); return true; } From a026143a840b9ac57534357a2074a50175be388a Mon Sep 17 00:00:00 2001 From: yausername <13ritvik@gmail.com> Date: Fri, 22 Mar 2019 04:57:33 +0530 Subject: [PATCH 2/3] linkify optimizations --- .../holder/CommentsMiniInfoItemHolder.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index b8362f947..78eb06ea4 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -91,15 +91,14 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { streamUrl = item.getUrl(); - itemContentView.setMaxLines(commentDefaultLines); + itemContentView.setLines(commentDefaultLines); commentText = item.getCommentText(); itemContentView.setText(commentText); - linkify(); itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE); - if(itemContentView.getLineCount() == 0){ + if (itemContentView.getLineCount() == 0) { itemContentView.post(() -> ellipsize()); - }else{ + } else { ellipsize(); } @@ -119,15 +118,17 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { private void ellipsize() { if (itemContentView.getLineCount() > commentDefaultLines){ int endOfLastLine = itemContentView.getLayout().getLineEnd(commentDefaultLines - 1); - String newVal = itemContentView.getText().subSequence(0, endOfLastLine - 3) + "..."; + int end = itemContentView.getText().toString().lastIndexOf(' ', endOfLastLine -3); + if(end == -1) end = Math.max(endOfLastLine -3, 0); + String newVal = itemContentView.getText().subSequence(0, end) + "..."; itemContentView.setText(newVal); - linkify(); } + linkify(); } private void toggleEllipsize() { if (itemContentView.getText().toString().equals(commentText)) { - ellipsize(); + if (itemContentView.getLineCount() > commentDefaultLines) ellipsize(); } else { expand(); } From 07f8dcb3ca1af4840d31754edb5331ecc652c24d Mon Sep 17 00:00:00 2001 From: yausername <13ritvik@gmail.com> Date: Fri, 22 Mar 2019 05:56:56 +0530 Subject: [PATCH 3/3] use ellipsis character --- .../info_list/holder/CommentsMiniInfoItemHolder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index 78eb06ea4..b726a40c6 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -118,9 +118,9 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { private void ellipsize() { if (itemContentView.getLineCount() > commentDefaultLines){ int endOfLastLine = itemContentView.getLayout().getLineEnd(commentDefaultLines - 1); - int end = itemContentView.getText().toString().lastIndexOf(' ', endOfLastLine -3); - if(end == -1) end = Math.max(endOfLastLine -3, 0); - String newVal = itemContentView.getText().subSequence(0, end) + "..."; + int end = itemContentView.getText().toString().lastIndexOf(' ', endOfLastLine -2); + if(end == -1) end = Math.max(endOfLastLine -2, 0); + String newVal = itemContentView.getText().subSequence(0, end) + " …"; itemContentView.setText(newVal); } linkify();