From 64f24160e909f4efba283fcd071c977bce8f607a Mon Sep 17 00:00:00 2001 From: Siddhesh Naik Date: Thu, 21 Sep 2023 00:19:23 +0530 Subject: [PATCH] TobiGr - review comments --- .../local/playlist/LocalPlaylistFragment.java | 50 +++++++++++-------- app/src/main/res/values/settings_keys.xml | 2 +- app/src/main/res/values/strings.xml | 8 +-- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index c1cea305b08..5a4eab6e831 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -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(); @@ -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(); @@ -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))); } @@ -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(); + } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 11e9fa9f9f3..005bf2b5459 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -25,7 +25,7 @@ clear_queue_confirmation_key ignore_hardware_media_buttons_key share_playlist_with_details_key - share_playlist_with_details_can_show_dialog_key + remember_local_playlist_sharing_option_key popup_saved_width popup_saved_x diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f491004f37c..ab9d0e1e929 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -812,9 +812,11 @@ Channel tabs What tabs are shown on the channel pages Share Playlist - Share playlist with details such as playlist name and video titles Or a simply share a list of video links + Share playlist with details such as playlist name and video titles or as a simple list of video URLs Share with details - Share list + Share URL list Remember my choice Share playlist with details such as playlist name and video titles - \ No newline at end of file + - %s: %s + %s\n%s +