@@ -399,67 +399,85 @@ public boolean onOptionsItemSelected(final MenuItem item) {
399
399
* @param shareMode Whether the playlist details should be included in the
400
400
* shared content.
401
401
*/
402
- private void sharePlaylist (PlayListShareMode shareMode ) {
402
+ private void sharePlaylist (final PlayListShareMode shareMode ) {
403
403
final Context context = requireContext ();
404
404
405
405
disposables .add (playlistManager .getPlaylistStreams (playlistId )
406
- .flatMapSingle (playlist -> Single .just (export ( shareMode
407
- , playlist .stream ().map (PlaylistStreamEntry ::getStreamEntity )
408
- , context
409
- )
410
- ))
406
+ .flatMapSingle (playlist -> Single .just (export (
407
+
408
+ shareMode ,
409
+ playlist .stream ().map (PlaylistStreamEntry ::getStreamEntity ),
410
+ context
411
+ )))
411
412
.observeOn (AndroidSchedulers .mainThread ())
412
- .subscribe ( urlsText -> ShareUtils .shareText ( context
413
- , name
414
- , shareMode == JUST_URLS ? urlsText
415
- : context .getString (R .string .share_playlist_content_details , name , urlsText ))
416
- , throwable -> showUiErrorSnackbar (this , "Sharing playlist" , throwable ))
417
- );
413
+ .subscribe (
414
+ urlsText -> {
415
+
416
+ final String content = shareMode == JUST_URLS
417
+ ? urlsText
418
+ : context .getString (R .string .share_playlist_content_details ,
419
+ name ,
420
+ urlsText
421
+ );
422
+
423
+ ShareUtils .shareText (context , name , content );
424
+ },
425
+ throwable -> showUiErrorSnackbar (this , "Sharing playlist" , throwable )
426
+ )
427
+ );
418
428
}
419
429
420
- static String export (PlayListShareMode shareMode , Stream <StreamEntity > entityStream , Context context ) {
430
+ static String export (final PlayListShareMode shareMode ,
431
+ final Stream <StreamEntity > entityStream ,
432
+ final Context context ) {
421
433
422
- return switch (shareMode ) {
434
+ return switch (shareMode ) {
423
435
424
436
case WITH_TITLES -> exportWithTitles (entityStream , context );
425
437
case JUST_URLS -> exportJustUrls (entityStream );
426
438
case YOUTUBE_TEMP_PLAYLIST -> exportAsYoutubeTempPlaylist (entityStream );
427
439
};
428
440
}
429
441
430
- static String exportWithTitles (Stream <StreamEntity > entityStream , Context context ) {
442
+ static String exportWithTitles (final Stream <StreamEntity > entityStream , final Context context ) {
431
443
432
444
return entityStream
433
- .map (entity -> context .getString (R .string .video_details_list_item , entity .getTitle (), entity .getUrl ()))
445
+ .map (entity -> context .getString (R .string .video_details_list_item ,
446
+ entity .getTitle (),
447
+ entity .getUrl ()
448
+ )
449
+ )
434
450
.collect (Collectors .joining ("\n " ));
435
451
}
436
452
437
- static String exportJustUrls (Stream <StreamEntity > entityStream ) {
453
+ static String exportJustUrls (final Stream <StreamEntity > entityStream ) {
438
454
439
455
return entityStream
440
456
.map (StreamEntity ::getUrl )
441
457
.collect (Collectors .joining ("\n " ));
442
458
}
443
459
444
- static String exportAsYoutubeTempPlaylist (Stream <StreamEntity > entityStream ) {
460
+ static String exportAsYoutubeTempPlaylist (final Stream <StreamEntity > entityStream ) {
445
461
446
- String videoIDs = entityStream
462
+ final String videoIDs = entityStream
447
463
.map (entity -> getYouTubeId (entity .getUrl ()))
448
464
.collect (Collectors .joining ("," ));
449
465
450
466
return "http://www.youtube.com/watch_videos?video_ids=" + videoIDs ;
451
467
}
452
468
453
469
/**
454
- * Gets the video id from a YouTube URL
470
+ * Gets the video id from a YouTube URL.
471
+ *
472
+ * @param url YouTube URL
473
+ * @return the video id
455
474
*/
456
- static String getYouTubeId (String url ) {
475
+ static String getYouTubeId (final String url ) {
457
476
458
- HttpUrl httpUrl = HttpUrl .parse (url );
477
+ final HttpUrl httpUrl = HttpUrl .parse (url );
459
478
460
479
return httpUrl == null ? null
461
- : httpUrl .queryParameter ("v" )
462
- ;
480
+ : httpUrl .queryParameter ("v" );
463
481
}
464
482
465
483
public void removeWatchedStreams (final boolean removePartiallyWatched ) {
@@ -924,7 +942,8 @@ private void createShareConfirmationDialog() {
924
942
.setPositiveButton (R .string .share_playlist_with_titles , (dialog , which ) ->
925
943
sharePlaylist (WITH_TITLES )
926
944
)
927
- .setNeutralButton ("Share as YouTube temporary playlist" , (dialog , which ) -> // TODO R.string.share_playlist_as_YouTube_temporary_playlist
945
+ // TODO R.string.share_playlist_as_YouTube_temporary_playlist
946
+ .setNeutralButton ("Share as YouTube temporary playlist" , (dialog , which ) ->
928
947
sharePlaylist (YOUTUBE_TEMP_PLAYLIST )
929
948
)
930
949
.setNegativeButton (R .string .share_playlist_with_list , (dialog , which ) ->
0 commit comments