|
2 | 2 |
|
3 | 3 | import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar; |
4 | 4 | import static org.schabi.newpipe.ktx.ViewUtils.animate; |
| 5 | +import static org.schabi.newpipe.local.playlist.ExportPlaylistKt.export; |
| 6 | +import static org.schabi.newpipe.local.playlist.PlayListShareMode.JUST_URLS; |
| 7 | +import static org.schabi.newpipe.local.playlist.PlayListShareMode.WITH_TITLES; |
| 8 | +import static org.schabi.newpipe.local.playlist.PlayListShareMode.YOUTUBE_TEMP_PLAYLIST; |
5 | 9 | import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout; |
6 | 10 |
|
| 11 | + |
7 | 12 | import android.content.Context; |
8 | 13 | import android.os.Bundle; |
9 | 14 | import android.os.Parcelable; |
|
27 | 32 | import androidx.viewbinding.ViewBinding; |
28 | 33 |
|
29 | 34 | import com.evernote.android.state.State; |
30 | | - |
31 | 35 | import org.reactivestreams.Subscriber; |
32 | 36 | import org.reactivestreams.Subscription; |
33 | 37 | import org.schabi.newpipe.NewPipeDatabase; |
@@ -385,34 +389,41 @@ public boolean onOptionsItemSelected(final MenuItem item) { |
385 | 389 | } |
386 | 390 |
|
387 | 391 | /** |
388 | | - * Shares the playlist as a list of stream URLs if {@code shouldSharePlaylistDetails} is |
389 | | - * set to {@code false}. Shares the playlist name along with a list of video titles and URLs |
390 | | - * if {@code shouldSharePlaylistDetails} is set to {@code true}. |
| 392 | + * Shares the playlist in one of 3 ways, depending on the value of {@code shareMode}: |
| 393 | + * <ul> |
| 394 | + * <li>{@code JUST_URLS}: shares the URLs only.</li> |
| 395 | + * <li>{@code WITH_TITLES}: each entry in the list is accompanied by its title.</li> |
| 396 | + * <li>{@code YOUTUBE_TEMP_PLAYLIST}: shares as a YouTube temporary playlist.</li> |
| 397 | + * </ul> |
391 | 398 | * |
392 | | - * @param shouldSharePlaylistDetails Whether the playlist details should be included in the |
393 | | - * shared content. |
| 399 | + * @param shareMode The way the playlist should be shared. |
394 | 400 | */ |
395 | | - private void sharePlaylist(final boolean shouldSharePlaylistDetails) { |
| 401 | + private void sharePlaylist(final PlayListShareMode shareMode) { |
396 | 402 | final Context context = requireContext(); |
397 | 403 |
|
398 | 404 | disposables.add(playlistManager.getPlaylistStreams(playlistId) |
399 | | - .flatMapSingle(playlist -> Single.just(playlist.stream() |
400 | | - .map(PlaylistStreamEntry::getStreamEntity) |
401 | | - .map(streamEntity -> { |
402 | | - if (shouldSharePlaylistDetails) { |
403 | | - return context.getString(R.string.video_details_list_item, |
404 | | - streamEntity.getTitle(), streamEntity.getUrl()); |
405 | | - } else { |
406 | | - return streamEntity.getUrl(); |
407 | | - } |
408 | | - }) |
409 | | - .collect(Collectors.joining("\n")))) |
410 | | - .observeOn(AndroidSchedulers.mainThread()) |
411 | | - .subscribe(urlsText -> ShareUtils.shareText( |
412 | | - context, name, shouldSharePlaylistDetails |
413 | | - ? context.getString(R.string.share_playlist_content_details, |
414 | | - name, urlsText) : urlsText), |
415 | | - throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable))); |
| 405 | + .flatMapSingle(playlist -> Single.just(export( |
| 406 | + |
| 407 | + shareMode, |
| 408 | + playlist, |
| 409 | + context |
| 410 | + ))) |
| 411 | + .observeOn(AndroidSchedulers.mainThread()) |
| 412 | + .subscribe( |
| 413 | + urlsText -> { |
| 414 | + |
| 415 | + final String content = shareMode == WITH_TITLES |
| 416 | + ? context.getString(R.string.share_playlist_content_details, |
| 417 | + name, |
| 418 | + urlsText |
| 419 | + ) |
| 420 | + : urlsText; |
| 421 | + |
| 422 | + ShareUtils.shareText(context, name, content); |
| 423 | + }, |
| 424 | + throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable) |
| 425 | + ) |
| 426 | + ); |
416 | 427 | } |
417 | 428 |
|
418 | 429 | public void removeWatchedStreams(final boolean removePartiallyWatched) { |
@@ -872,13 +883,15 @@ private PlayQueue getPlayQueue(final int index) { |
872 | 883 | private void createShareConfirmationDialog() { |
873 | 884 | new AlertDialog.Builder(requireContext()) |
874 | 885 | .setTitle(R.string.share_playlist) |
875 | | - .setMessage(R.string.share_playlist_with_titles_message) |
876 | 886 | .setCancelable(true) |
877 | 887 | .setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) -> |
878 | | - sharePlaylist(/* shouldSharePlaylistDetails= */ true) |
| 888 | + sharePlaylist(WITH_TITLES) |
| 889 | + ) |
| 890 | + .setNeutralButton(R.string.share_playlist_as_youtube_temporary_playlist, |
| 891 | + (dialog, which) -> sharePlaylist(YOUTUBE_TEMP_PLAYLIST) |
879 | 892 | ) |
880 | 893 | .setNegativeButton(R.string.share_playlist_with_list, (dialog, which) -> |
881 | | - sharePlaylist(/* shouldSharePlaylistDetails= */ false) |
| 894 | + sharePlaylist(JUST_URLS) |
882 | 895 | ) |
883 | 896 | .show(); |
884 | 897 | } |
|
0 commit comments