Skip to content

Commit

Permalink
TobiGr - review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
snaik20 committed Sep 20, 2023
1 parent b5274a7 commit 64f2416
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ public void onComplete() {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.menu_item_share_playlist) {
if (sharedPreferences.getBoolean(requireContext().getString(
R.string.share_playlist_with_details_can_show_dialog_key), true)) {
if (!sharedPreferences.getBoolean(requireContext().getString(
R.string.remember_local_playlist_sharing_option_key), false)) {
createShareConfirmationDialog();
} else {
sharePlaylist();
Expand Down Expand Up @@ -388,14 +388,19 @@ public boolean onOptionsItemSelected(final MenuItem item) {
* Share the playlist as a newline-separated list of stream URLs and video names.
*/
private void sharePlaylist() {
final Context context = getContext();
if (context == null) {
return;
}

final boolean shouldSharePlaylistDetails = sharedPreferences.getBoolean(
requireContext().getString(R.string.share_playlist_with_details_key), false);
context.getString(R.string.share_playlist_with_details_key), false);
disposables.add(playlistManager.getPlaylistStreams(playlistId)
.flatMapSingle(playlist -> Single.just(playlist.stream()
.map(PlaylistStreamEntry::getStreamEntity)
.map(streamEntity -> {
if (shouldSharePlaylistDetails) {
return String.format("- %s: %s",
return context.getString(R.string.video_details_list_item,
streamEntity.getTitle(), streamEntity.getUrl());
} else {
return streamEntity.getUrl();
Expand All @@ -404,8 +409,9 @@ private void sharePlaylist() {
.collect(Collectors.joining("\n"))))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(urlsText -> ShareUtils.shareText(
requireContext(), name, shouldSharePlaylistDetails
? String.format("%s\n%s", name, urlsText) : urlsText),
context, name, shouldSharePlaylistDetails
? context.getString(R.string.share_playlist_content_details,
name, urlsText) : urlsText),
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)));
}

Expand Down Expand Up @@ -877,26 +883,26 @@ private void createShareConfirmationDialog() {
.setCancelable(true)
.setView(dialogBinding.getRoot())
.setPositiveButton(R.string.share_playlist_with_details, (dialog, which) -> {
sharedPreferences.edit()
.putBoolean(requireContext().getString(
R.string.share_playlist_with_details_can_show_dialog_key),
!dialogBinding.rememberChoiceCheckBox.isChecked())
.putBoolean(requireContext().getString(
R.string.share_playlist_with_details_key), true)
.commit();
sharePlaylist();
savePreferencesAndSharePlaylist(
dialogBinding.rememberChoiceCheckBox.isChecked(), true);
})
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) -> {
sharedPreferences.edit()
.putBoolean(requireContext().getString(
R.string.share_playlist_with_details_can_show_dialog_key),
!dialogBinding.rememberChoiceCheckBox.isChecked())
.putBoolean(requireContext().getString(
R.string.share_playlist_with_details_key), false)
.commit();
sharePlaylist();
savePreferencesAndSharePlaylist(
dialogBinding.rememberChoiceCheckBox.isChecked(), false);
})
.show();
}

private void savePreferencesAndSharePlaylist(final boolean rememberPlaylistSharingOption,
final boolean sharePlaylistWithDetails) {
sharedPreferences.edit()
.putBoolean(requireContext().getString(
R.string.remember_local_playlist_sharing_option_key),
rememberPlaylistSharingOption)
.putBoolean(requireContext().getString(
R.string.share_playlist_with_details_key), sharePlaylistWithDetails)
.apply();
sharePlaylist();
}
}

2 changes: 1 addition & 1 deletion app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<string name="clear_queue_confirmation_key">clear_queue_confirmation_key</string>
<string name="ignore_hardware_media_buttons_key">ignore_hardware_media_buttons_key</string>
<string name="share_playlist_with_details_key">share_playlist_with_details_key</string>
<string name="share_playlist_with_details_can_show_dialog_key">share_playlist_with_details_can_show_dialog_key</string>
<string name="remember_local_playlist_sharing_option_key">remember_local_playlist_sharing_option_key</string>

<string name="popup_saved_width_key">popup_saved_width</string>
<string name="popup_saved_x_key">popup_saved_x</string>
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,11 @@
<string name="show_channel_tabs">Channel tabs</string>
<string name="show_channel_tabs_summary">What tabs are shown on the channel pages</string>
<string name="share_playlist">Share Playlist</string>
<string name="share_playlist_with_details_message">Share playlist with details such as playlist name and video titles Or a simply share a list of video links</string>
<string name="share_playlist_with_details_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_details">Share with details</string>
<string name="share_playlist_with_list">Share list</string>
<string name="share_playlist_with_list">Share URL list</string>
<string name="remember_my_choice">Remember my choice</string>
<string name="share_playlist_with_details_settings_item">Share playlist with details such as playlist name and video titles</string>
</resources>
<string name="video_details_list_item">- %s: %s</string>
<string name="share_playlist_content_details">%s\n%s</string>
</resources>

0 comments on commit 64f2416

Please sign in to comment.