Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Removed the setting item to update the playlist sharing preference.
- Removed the option to save user's playlist sharing preference.

Video demo:
- https://github.com/TeamNewPipe/NewPipe/assets/87667048/5ac5ab6f-163d-4407-bd67-a078a8b55bbb

PR Commit Message
Add playlist name and video name in playlist sharing content

- 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

Screenshots:
| Before | After |
| --- | --- |
| <img src="https://github.com/TeamNewPipe/NewPipe/assets/87667048/fa7b27b2-91d6-491d-8f93-a8b447263de6" width=320> | <img src="https://github.com/TeamNewPipe/NewPipe/assets/87667048/e7ddde18-1d3a-4ccb-8c35-f5bf14e48bec" width=320> |

Video demo:
- https://github.com/TeamNewPipe/NewPipe/assets/87667048/5ac5ab6f-163d-4407-bd67-a078a8b55bbb
  • Loading branch information
snaik20 authored and TobiGr committed Sep 26, 2023
1 parent 118ed48 commit 9b48adb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.InputType;
Expand All @@ -23,7 +22,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
Expand All @@ -38,7 +36,6 @@
import org.schabi.newpipe.database.playlist.model.PlaylistEntity;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.databinding.DialogEditTextBinding;
import org.schabi.newpipe.databinding.DialogSharePlaylistBinding;
import org.schabi.newpipe.databinding.LocalPlaylistHeaderBinding;
import org.schabi.newpipe.databinding.PlaylistControlBinding;
import org.schabi.newpipe.error.ErrorInfo;
Expand All @@ -54,8 +51,8 @@
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
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.external_communication.ShareUtils;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -102,8 +99,6 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
/* Flag to prevent simultaneous rewrites of the playlist */
private boolean isRewritingPlaylist = false;

private SharedPreferences sharedPreferences;

public static LocalPlaylistFragment getInstance(final long playlistId, final String name) {
final LocalPlaylistFragment instance = new LocalPlaylistFragment();
instance.setInitialData(playlistId, name);
Expand All @@ -124,7 +119,6 @@ public void onCreate(final Bundle savedInstanceState) {

isLoadingComplete = new AtomicBoolean();
isModified = new AtomicBoolean();
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
}

@Override
Expand Down Expand Up @@ -352,12 +346,7 @@ 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.remember_local_playlist_sharing_option_key), false)) {
createShareConfirmationDialog();
} else {
sharePlaylist();
}
createShareConfirmationDialog();
} else if (item.getItemId() == R.id.menu_item_rename_playlist) {
createRenameDialog();
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
Expand Down Expand Up @@ -385,16 +374,19 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}

/**
* Share the playlist as a newline-separated list of stream URLs and video names.
* 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.
*/
private void sharePlaylist() {
private void sharePlaylist(final boolean shouldSharePlaylistDetails) {
final Context context = getContext();
if (context == null) {
return;
}

final boolean shouldSharePlaylistDetails = sharedPreferences.getBoolean(
context.getString(R.string.share_playlist_with_details_key), false);
disposables.add(playlistManager.getPlaylistStreams(playlistId)
.flatMapSingle(playlist -> Single.just(playlist.stream()
.map(PlaylistStreamEntry::getStreamEntity)
Expand Down Expand Up @@ -875,34 +867,17 @@ private void createShareConfirmationDialog() {
return;
}

final DialogSharePlaylistBinding dialogBinding = DialogSharePlaylistBinding
.inflate(getLayoutInflater());

new AlertDialog.Builder(getContext())
.setTitle(R.string.share_playlist)
.setMessage(R.string.share_playlist_with_details_message)
.setCancelable(true)
.setView(dialogBinding.getRoot())
.setPositiveButton(R.string.share_playlist_with_details, (dialog, which) -> {
savePreferencesAndSharePlaylist(
dialogBinding.rememberChoiceCheckBox.isChecked(), true);
sharePlaylist(/* shouldSharePlaylistDetails= */ true);
})
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) -> {
savePreferencesAndSharePlaylist(
dialogBinding.rememberChoiceCheckBox.isChecked(), false);
sharePlaylist(/* shouldSharePlaylistDetails= */ 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();
}
}

28 changes: 0 additions & 28 deletions app/src/main/res/layout/dialog_share_playlist.xml

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<string name="screen_brightness_timestamp_key">screen_brightness_timestamp_key</string>
<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="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
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,6 @@
<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 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>
<string name="video_details_list_item">- %s: %s</string>
<string name="share_playlist_content_details">%s\n%s</string>
</resources>
8 changes: 0 additions & 8 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,5 @@
android:title="@string/ignore_hardware_media_buttons_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/share_playlist_with_details_key"
android:summary="@string/share_playlist_with_details_settings_item"
android:title="@string/share_playlist"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 9b48adb

Please sign in to comment.