|
51 | 51 | import org.schabi.newpipe.util.Localization; |
52 | 52 | import org.schabi.newpipe.util.NavigationHelper; |
53 | 53 | import org.schabi.newpipe.util.OnClickGesture; |
54 | | -import org.schabi.newpipe.util.external_communication.ShareUtils; |
55 | 54 | import org.schabi.newpipe.util.PlayButtonHelper; |
| 55 | +import org.schabi.newpipe.util.external_communication.ShareUtils; |
56 | 56 |
|
57 | 57 | import java.util.ArrayList; |
58 | 58 | import java.util.Collections; |
@@ -346,7 +346,7 @@ public void onComplete() { |
346 | 346 | @Override |
347 | 347 | public boolean onOptionsItemSelected(final MenuItem item) { |
348 | 348 | if (item.getItemId() == R.id.menu_item_share_playlist) { |
349 | | - sharePlaylist(); |
| 349 | + createShareConfirmationDialog(); |
350 | 350 | } else if (item.getItemId() == R.id.menu_item_rename_playlist) { |
351 | 351 | createRenameDialog(); |
352 | 352 | } else if (item.getItemId() == R.id.menu_item_remove_watched) { |
@@ -374,16 +374,33 @@ public boolean onOptionsItemSelected(final MenuItem item) { |
374 | 374 | } |
375 | 375 |
|
376 | 376 | /** |
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. |
378 | 383 | */ |
379 | | - public void sharePlaylist() { |
| 384 | + private void sharePlaylist(final boolean shouldSharePlaylistDetails) { |
| 385 | + final Context context = requireContext(); |
| 386 | + |
380 | 387 | disposables.add(playlistManager.getPlaylistStreams(playlistId) |
381 | 388 | .flatMapSingle(playlist -> Single.just(playlist.stream() |
382 | 389 | .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 | + }) |
384 | 398 | .collect(Collectors.joining("\n")))) |
385 | 399 | .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), |
387 | 404 | throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable))); |
388 | 405 | } |
389 | 406 |
|
@@ -841,5 +858,24 @@ private PlayQueue getPlayQueue(final int index) { |
841 | 858 | } |
842 | 859 | return new SinglePlayQueue(streamInfoItems, index); |
843 | 860 | } |
| 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 | + } |
844 | 880 | } |
845 | 881 |
|
0 commit comments