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>
This commit is contained in:
parent
9c86afe40d
commit
e80b6b3057
2 changed files with 49 additions and 7 deletions
|
@ -51,8 +51,8 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
|
||||||
import org.schabi.newpipe.util.PlayButtonHelper;
|
import org.schabi.newpipe.util.PlayButtonHelper;
|
||||||
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -346,7 +346,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
if (item.getItemId() == R.id.menu_item_share_playlist) {
|
if (item.getItemId() == R.id.menu_item_share_playlist) {
|
||||||
sharePlaylist();
|
createShareConfirmationDialog();
|
||||||
} else if (item.getItemId() == R.id.menu_item_rename_playlist) {
|
} else if (item.getItemId() == R.id.menu_item_rename_playlist) {
|
||||||
createRenameDialog();
|
createRenameDialog();
|
||||||
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
|
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
|
||||||
|
@ -374,16 +374,33 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share the playlist as a newline-separated list of stream URLs.
|
* Shares the playlist as a list of stream URLs if {@code shouldSharePlaylistDetails} is
|
||||||
|
* set to {@code false}. Shares the playlist name along with a list of video titles and URLs
|
||||||
|
* if {@code shouldSharePlaylistDetails} is set to {@code true}.
|
||||||
|
*
|
||||||
|
* @param shouldSharePlaylistDetails Whether the playlist details should be included in the
|
||||||
|
* shared content.
|
||||||
*/
|
*/
|
||||||
public void sharePlaylist() {
|
private void sharePlaylist(final boolean shouldSharePlaylistDetails) {
|
||||||
|
final Context context = requireContext();
|
||||||
|
|
||||||
disposables.add(playlistManager.getPlaylistStreams(playlistId)
|
disposables.add(playlistManager.getPlaylistStreams(playlistId)
|
||||||
.flatMapSingle(playlist -> Single.just(playlist.stream()
|
.flatMapSingle(playlist -> Single.just(playlist.stream()
|
||||||
.map(PlaylistStreamEntry::getStreamEntity)
|
.map(PlaylistStreamEntry::getStreamEntity)
|
||||||
.map(StreamEntity::getUrl)
|
.map(streamEntity -> {
|
||||||
|
if (shouldSharePlaylistDetails) {
|
||||||
|
return context.getString(R.string.video_details_list_item,
|
||||||
|
streamEntity.getTitle(), streamEntity.getUrl());
|
||||||
|
} else {
|
||||||
|
return streamEntity.getUrl();
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(Collectors.joining("\n"))))
|
.collect(Collectors.joining("\n"))))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(urlsText -> ShareUtils.shareText(requireContext(), name, urlsText),
|
.subscribe(urlsText -> ShareUtils.shareText(
|
||||||
|
context, name, shouldSharePlaylistDetails
|
||||||
|
? context.getString(R.string.share_playlist_content_details,
|
||||||
|
name, urlsText) : urlsText),
|
||||||
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)));
|
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -841,5 +858,24 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
}
|
}
|
||||||
return new SinglePlayQueue(streamInfoItems, index);
|
return new SinglePlayQueue(streamInfoItems, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a dialog to confirm whether the user wants to share the playlist
|
||||||
|
* with the playlist details or just the list of stream URLs.
|
||||||
|
* After the user has made a choice, the playlist is shared.
|
||||||
|
*/
|
||||||
|
private void createShareConfirmationDialog() {
|
||||||
|
new AlertDialog.Builder(requireContext())
|
||||||
|
.setTitle(R.string.share_playlist)
|
||||||
|
.setMessage(R.string.share_playlist_with_titles_message)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) ->
|
||||||
|
sharePlaylist(/* shouldSharePlaylistDetails= */ true)
|
||||||
|
)
|
||||||
|
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) ->
|
||||||
|
sharePlaylist(/* shouldSharePlaylistDetails= */ false)
|
||||||
|
)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -832,4 +832,10 @@
|
||||||
<string name="image_quality_medium">Medium quality</string>
|
<string name="image_quality_medium">Medium quality</string>
|
||||||
<string name="image_quality_high">High quality</string>
|
<string name="image_quality_high">High quality</string>
|
||||||
<string name="question_mark">\?</string>
|
<string name="question_mark">\?</string>
|
||||||
|
<string name="share_playlist">Share Playlist</string>
|
||||||
|
<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>
|
||||||
|
<string name="share_playlist_with_titles">Share with Titles</string>
|
||||||
|
<string name="share_playlist_with_list">Share URL list</string>
|
||||||
|
<string name="video_details_list_item">- %s: %s</string>
|
||||||
|
<string name="share_playlist_content_details">%s\n%s</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue