11package org .schabi .newpipe .local .playlist ;
22
3+ import static org .schabi .newpipe .error .ErrorUtil .showUiErrorSnackbar ;
34import static org .schabi .newpipe .ktx .ViewUtils .animate ;
45import static org .schabi .newpipe .util .ThemeHelper .shouldUseGridLayout ;
56
5051import org .schabi .newpipe .util .NavigationHelper ;
5152import org .schabi .newpipe .util .OnClickGesture ;
5253import org .schabi .newpipe .info_list .dialog .StreamDialogDefaultEntry ;
54+ import org .schabi .newpipe .util .external_communication .ShareUtils ;
5355
5456import java .util .ArrayList ;
5557import java .util .Collections ;
5658import java .util .Iterator ;
5759import java .util .List ;
5860import java .util .concurrent .TimeUnit ;
5961import java .util .concurrent .atomic .AtomicBoolean ;
62+ import java .util .stream .Collectors ;
6063
6164import icepick .State ;
6265import io .reactivex .rxjava3 .android .schedulers .AndroidSchedulers ;
6366import io .reactivex .rxjava3 .core .Flowable ;
67+ import io .reactivex .rxjava3 .core .Single ;
6468import io .reactivex .rxjava3 .disposables .CompositeDisposable ;
6569import io .reactivex .rxjava3 .disposables .Disposable ;
6670import io .reactivex .rxjava3 .schedulers .Schedulers ;
@@ -345,7 +349,11 @@ public void onComplete() {
345349
346350 @ Override
347351 public boolean onOptionsItemSelected (final MenuItem item ) {
348- if (item .getItemId () == R .id .menu_item_remove_watched ) {
352+ if (item .getItemId () == R .id .menu_item_share_playlist ) {
353+ sharePlaylist ();
354+ } else if (item .getItemId () == R .id .menu_item_rename_playlist ) {
355+ createRenameDialog ();
356+ } else if (item .getItemId () == R .id .menu_item_remove_watched ) {
349357 if (!isRemovingWatched ) {
350358 new AlertDialog .Builder (requireContext ())
351359 .setMessage (R .string .remove_watched_popup_warning )
@@ -360,14 +368,26 @@ public boolean onOptionsItemSelected(final MenuItem item) {
360368 .create ()
361369 .show ();
362370 }
363- } else if (item .getItemId () == R .id .menu_item_rename_playlist ) {
364- createRenameDialog ();
365371 } else {
366372 return super .onOptionsItemSelected (item );
367373 }
368374 return true ;
369375 }
370376
377+ /**
378+ * Share the playlist as a newline-separated list of stream URLs.
379+ */
380+ public void sharePlaylist () {
381+ disposables .add (playlistManager .getPlaylistStreams (playlistId )
382+ .flatMapSingle (playlist -> Single .just (playlist .stream ()
383+ .map (PlaylistStreamEntry ::getStreamEntity )
384+ .map (StreamEntity ::getUrl )
385+ .collect (Collectors .joining ("\n " ))))
386+ .observeOn (AndroidSchedulers .mainThread ())
387+ .subscribe (urlsText -> ShareUtils .shareText (requireContext (), name , urlsText ),
388+ throwable -> showUiErrorSnackbar (this , "Sharing playlist" , throwable )));
389+ }
390+
371391 public void removeWatchedStreams (final boolean removePartiallyWatched ) {
372392 if (isRemovingWatched ) {
373393 return ;
0 commit comments