Skip to content

Commit

Permalink
Add playlist name and video name to playlist sharing content (#10427)
Browse files Browse the repository at this point in the history
- Currently, only a list of videos separated by newline are added in
  the share content.
- This makes it difficult to identify a specific video in a list of
  Urls.
- Used string resources for the sharing content formats.
- Added a confirmation dialog for users to choose between sharing
  playlist formats.
- Added Playlist name as the header and corresponding video name for
  each video url in following format.

Playlist
- Music1: https://media-url1
- Music2: https://media-url2
- Music3: https://media-url3


Co-authored-by: TobiGr <tobigr@users.noreply.github.com>
  • Loading branch information
snaik20 and TobiGr authored Sep 26, 2023
1 parent 9c86afe commit e80b6b3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import org.schabi.newpipe.util.PlayButtonHelper;
import org.schabi.newpipe.util.external_communication.ShareUtils;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -346,7 +346,7 @@ public void onComplete() {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.menu_item_share_playlist) {
sharePlaylist();
createShareConfirmationDialog();
} else if (item.getItemId() == R.id.menu_item_rename_playlist) {
createRenameDialog();
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
Expand Down Expand Up @@ -374,16 +374,33 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}

/**
* Share the playlist as a newline-separated list of stream URLs.
* Shares the playlist as a list of stream URLs if {@code shouldSharePlaylistDetails} is
* set to {@code false}. Shares the playlist name along with a list of video titles and URLs
* if {@code shouldSharePlaylistDetails} is set to {@code true}.
*
* @param shouldSharePlaylistDetails Whether the playlist details should be included in the
* shared content.
*/
public void sharePlaylist() {
private void sharePlaylist(final boolean shouldSharePlaylistDetails) {
final Context context = requireContext();

disposables.add(playlistManager.getPlaylistStreams(playlistId)
.flatMapSingle(playlist -> Single.just(playlist.stream()
.map(PlaylistStreamEntry::getStreamEntity)
.map(StreamEntity::getUrl)
.map(streamEntity -> {
if (shouldSharePlaylistDetails) {
return context.getString(R.string.video_details_list_item,
streamEntity.getTitle(), streamEntity.getUrl());
} else {
return streamEntity.getUrl();
}
})
.collect(Collectors.joining("\n"))))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(urlsText -> ShareUtils.shareText(requireContext(), name, urlsText),
.subscribe(urlsText -> ShareUtils.shareText(
context, name, shouldSharePlaylistDetails
? context.getString(R.string.share_playlist_content_details,
name, urlsText) : urlsText),
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)));
}

Expand Down Expand Up @@ -841,5 +858,24 @@ private PlayQueue getPlayQueue(final int index) {
}
return new SinglePlayQueue(streamInfoItems, index);
}

/**
* Creates a dialog to confirm whether the user wants to share the playlist
* with the playlist details or just the list of stream URLs.
* After the user has made a choice, the playlist is shared.
*/
private void createShareConfirmationDialog() {
new AlertDialog.Builder(requireContext())
.setTitle(R.string.share_playlist)
.setMessage(R.string.share_playlist_with_titles_message)
.setCancelable(true)
.setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) ->
sharePlaylist(/* shouldSharePlaylistDetails= */ true)
)
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) ->
sharePlaylist(/* shouldSharePlaylistDetails= */ false)
)
.show();
}
}

8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,10 @@
<string name="image_quality_medium">Medium quality</string>
<string name="image_quality_high">High quality</string>
<string name="question_mark">\?</string>
</resources>
<string name="share_playlist">Share Playlist</string>
<string name="share_playlist_with_titles_message">Share playlist with details such as playlist name and video titles or as a simple list of video URLs</string>
<string name="share_playlist_with_titles">Share with Titles</string>
<string name="share_playlist_with_list">Share URL list</string>
<string name="video_details_list_item">- %s: %s</string>
<string name="share_playlist_content_details">%s\n%s</string>
</resources>

0 comments on commit e80b6b3

Please sign in to comment.