Skip to content

Commit e80b6b3

Browse files
Add playlist name and video name to playlist sharing content (#10427)
- 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>
1 parent 9c86afe commit e80b6b3

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
import org.schabi.newpipe.util.Localization;
5252
import org.schabi.newpipe.util.NavigationHelper;
5353
import org.schabi.newpipe.util.OnClickGesture;
54-
import org.schabi.newpipe.util.external_communication.ShareUtils;
5554
import org.schabi.newpipe.util.PlayButtonHelper;
55+
import org.schabi.newpipe.util.external_communication.ShareUtils;
5656

5757
import java.util.ArrayList;
5858
import java.util.Collections;
@@ -346,7 +346,7 @@ public void onComplete() {
346346
@Override
347347
public boolean onOptionsItemSelected(final MenuItem item) {
348348
if (item.getItemId() == R.id.menu_item_share_playlist) {
349-
sharePlaylist();
349+
createShareConfirmationDialog();
350350
} else if (item.getItemId() == R.id.menu_item_rename_playlist) {
351351
createRenameDialog();
352352
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
@@ -374,16 +374,33 @@ public boolean onOptionsItemSelected(final MenuItem item) {
374374
}
375375

376376
/**
377-
* Share the playlist as a newline-separated list of stream URLs.
377+
* Shares the playlist as a list of stream URLs if {@code shouldSharePlaylistDetails} is
378+
* set to {@code false}. Shares the playlist name along with a list of video titles and URLs
379+
* if {@code shouldSharePlaylistDetails} is set to {@code true}.
380+
*
381+
* @param shouldSharePlaylistDetails Whether the playlist details should be included in the
382+
* shared content.
378383
*/
379-
public void sharePlaylist() {
384+
private void sharePlaylist(final boolean shouldSharePlaylistDetails) {
385+
final Context context = requireContext();
386+
380387
disposables.add(playlistManager.getPlaylistStreams(playlistId)
381388
.flatMapSingle(playlist -> Single.just(playlist.stream()
382389
.map(PlaylistStreamEntry::getStreamEntity)
383-
.map(StreamEntity::getUrl)
390+
.map(streamEntity -> {
391+
if (shouldSharePlaylistDetails) {
392+
return context.getString(R.string.video_details_list_item,
393+
streamEntity.getTitle(), streamEntity.getUrl());
394+
} else {
395+
return streamEntity.getUrl();
396+
}
397+
})
384398
.collect(Collectors.joining("\n"))))
385399
.observeOn(AndroidSchedulers.mainThread())
386-
.subscribe(urlsText -> ShareUtils.shareText(requireContext(), name, urlsText),
400+
.subscribe(urlsText -> ShareUtils.shareText(
401+
context, name, shouldSharePlaylistDetails
402+
? context.getString(R.string.share_playlist_content_details,
403+
name, urlsText) : urlsText),
387404
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)));
388405
}
389406

@@ -841,5 +858,24 @@ private PlayQueue getPlayQueue(final int index) {
841858
}
842859
return new SinglePlayQueue(streamInfoItems, index);
843860
}
861+
862+
/**
863+
* Creates a dialog to confirm whether the user wants to share the playlist
864+
* with the playlist details or just the list of stream URLs.
865+
* After the user has made a choice, the playlist is shared.
866+
*/
867+
private void createShareConfirmationDialog() {
868+
new AlertDialog.Builder(requireContext())
869+
.setTitle(R.string.share_playlist)
870+
.setMessage(R.string.share_playlist_with_titles_message)
871+
.setCancelable(true)
872+
.setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) ->
873+
sharePlaylist(/* shouldSharePlaylistDetails= */ true)
874+
)
875+
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) ->
876+
sharePlaylist(/* shouldSharePlaylistDetails= */ false)
877+
)
878+
.show();
879+
}
844880
}
845881

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,4 +832,10 @@
832832
<string name="image_quality_medium">Medium quality</string>
833833
<string name="image_quality_high">High quality</string>
834834
<string name="question_mark">\?</string>
835-
</resources>
835+
<string name="share_playlist">Share Playlist</string>
836+
<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>
837+
<string name="share_playlist_with_titles">Share with Titles</string>
838+
<string name="share_playlist_with_list">Share URL list</string>
839+
<string name="video_details_list_item">- %s: %s</string>
840+
<string name="share_playlist_content_details">%s\n%s</string>
841+
</resources>

0 commit comments

Comments
 (0)