Skip to content

Commit

Permalink
Merge pull request #6436 from Abanoub8/add_url_button
Browse files Browse the repository at this point in the history
Add copy url function to share button
  • Loading branch information
Stypox authored Jun 8, 2021
2 parents 63cff25 + bede758 commit 0b64382
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ private void initListeners() {
binding.moreOptionsButton.setOnClickListener(this);
binding.moreOptionsButton.setOnLongClickListener(this);
binding.share.setOnClickListener(this);
binding.share.setOnLongClickListener(this);
binding.fullScreenButton.setOnClickListener(this);
binding.screenRotationButton.setOnClickListener(this);
binding.playWithKodi.setOnClickListener(this);
Expand Down Expand Up @@ -2917,6 +2918,18 @@ private String getVideoUrl() {
: currentMetadata.getMetadata().getUrl();
}

@NonNull
private String getVideoUrlAtCurrentTime() {
final int timeSeconds = binding.playbackSeekBar.getProgress() / 1000;
String videoUrl = getVideoUrl();
if (!isLive() && timeSeconds >= 0 && currentMetadata != null
&& currentMetadata.getMetadata().getServiceId() == YouTube.getServiceId()) {
// Timestamp doesn't make sense in a live stream so drop it
videoUrl += ("&t=" + timeSeconds);
}
return videoUrl;
}

@NonNull
public String getVideoTitle() {
return currentMetadata == null
Expand Down Expand Up @@ -3580,7 +3593,7 @@ public void onClick(final View v) {
} else if (v.getId() == binding.moreOptionsButton.getId()) {
onMoreOptionsClicked();
} else if (v.getId() == binding.share.getId()) {
onShareClicked();
ShareUtils.shareText(context, getVideoTitle(), getVideoUrlAtCurrentTime());
} else if (v.getId() == binding.playWithKodi.getId()) {
onPlayWithKodiClicked();
} else if (v.getId() == binding.openInBrowser.getId()) {
Expand Down Expand Up @@ -3629,6 +3642,8 @@ public boolean onLongClick(final View v) {
fragmentListener.onMoreOptionsLongClicked();
hideControls(0, 0);
hideSystemUIIfNeeded();
} else if (v.getId() == binding.share.getId()) {
ShareUtils.copyToClipboard(context, getVideoUrlAtCurrentTime());
}
return true;
}
Expand Down Expand Up @@ -3700,19 +3715,6 @@ private void onMoreOptionsClicked() {
showControls(DEFAULT_CONTROLS_DURATION);
}

private void onShareClicked() {
// share video at the current time (youtube.com/watch?v=ID&t=SECONDS)
// Timestamp doesn't make sense in a live stream so drop it

final int ts = binding.playbackSeekBar.getProgress() / 1000;
String videoUrl = getVideoUrl();
if (!isLive() && ts >= 0 && currentMetadata != null
&& currentMetadata.getMetadata().getServiceId() == YouTube.getServiceId()) {
videoUrl += ("&t=" + ts);
}
ShareUtils.shareText(context, getVideoTitle(), videoUrl);
}

private void onPlayWithKodiClicked() {
if (currentMetadata != null) {
pause();
Expand Down

0 comments on commit 0b64382

Please sign in to comment.