mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-08-04 21:13:49 +00:00
[#11930] Making CheckStyle happy
This commit is contained in:
parent
94d4c21cc7
commit
c6b87cd316
@ -399,27 +399,39 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
* @param shareMode Whether the playlist details should be included in the
|
* @param shareMode Whether the playlist details should be included in the
|
||||||
* shared content.
|
* shared content.
|
||||||
*/
|
*/
|
||||||
private void sharePlaylist(PlayListShareMode shareMode) {
|
private void sharePlaylist(final PlayListShareMode shareMode) {
|
||||||
final Context context = requireContext();
|
final Context context = requireContext();
|
||||||
|
|
||||||
disposables.add(playlistManager.getPlaylistStreams(playlistId)
|
disposables.add(playlistManager.getPlaylistStreams(playlistId)
|
||||||
.flatMapSingle(playlist -> Single.just(export( shareMode
|
.flatMapSingle(playlist -> Single.just(export(
|
||||||
, playlist.stream().map(PlaylistStreamEntry::getStreamEntity)
|
|
||||||
, context
|
shareMode,
|
||||||
)
|
playlist.stream().map(PlaylistStreamEntry::getStreamEntity),
|
||||||
))
|
context
|
||||||
|
)))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe( urlsText -> ShareUtils.shareText( context
|
.subscribe(
|
||||||
, name
|
urlsText -> {
|
||||||
, shareMode == JUST_URLS ? urlsText
|
|
||||||
: context.getString(R.string.share_playlist_content_details, name, urlsText))
|
final String content = shareMode == JUST_URLS
|
||||||
, throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable))
|
? urlsText
|
||||||
);
|
: context.getString(R.string.share_playlist_content_details,
|
||||||
|
name,
|
||||||
|
urlsText
|
||||||
|
);
|
||||||
|
|
||||||
|
ShareUtils.shareText(context, name, content);
|
||||||
|
},
|
||||||
|
throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String export(PlayListShareMode shareMode, Stream<StreamEntity> entityStream, Context context) {
|
static String export(final PlayListShareMode shareMode,
|
||||||
|
final Stream<StreamEntity> entityStream,
|
||||||
|
final Context context) {
|
||||||
|
|
||||||
return switch(shareMode) {
|
return switch (shareMode) {
|
||||||
|
|
||||||
case WITH_TITLES -> exportWithTitles(entityStream, context);
|
case WITH_TITLES -> exportWithTitles(entityStream, context);
|
||||||
case JUST_URLS -> exportJustUrls(entityStream);
|
case JUST_URLS -> exportJustUrls(entityStream);
|
||||||
@ -427,23 +439,27 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static String exportWithTitles(Stream<StreamEntity> entityStream, Context context) {
|
static String exportWithTitles(final Stream<StreamEntity> entityStream, final Context context) {
|
||||||
|
|
||||||
return entityStream
|
return entityStream
|
||||||
.map(entity -> context.getString(R.string.video_details_list_item, entity.getTitle(), entity.getUrl()))
|
.map(entity -> context.getString(R.string.video_details_list_item,
|
||||||
|
entity.getTitle(),
|
||||||
|
entity.getUrl()
|
||||||
|
)
|
||||||
|
)
|
||||||
.collect(Collectors.joining("\n"));
|
.collect(Collectors.joining("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static String exportJustUrls(Stream<StreamEntity> entityStream) {
|
static String exportJustUrls(final Stream<StreamEntity> entityStream) {
|
||||||
|
|
||||||
return entityStream
|
return entityStream
|
||||||
.map(StreamEntity::getUrl)
|
.map(StreamEntity::getUrl)
|
||||||
.collect(Collectors.joining("\n"));
|
.collect(Collectors.joining("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static String exportAsYoutubeTempPlaylist(Stream<StreamEntity> entityStream) {
|
static String exportAsYoutubeTempPlaylist(final Stream<StreamEntity> entityStream) {
|
||||||
|
|
||||||
String videoIDs = entityStream
|
final String videoIDs = entityStream
|
||||||
.map(entity -> getYouTubeId(entity.getUrl()))
|
.map(entity -> getYouTubeId(entity.getUrl()))
|
||||||
.collect(Collectors.joining(","));
|
.collect(Collectors.joining(","));
|
||||||
|
|
||||||
@ -451,15 +467,17 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the video id from a YouTube URL
|
* Gets the video id from a YouTube URL.
|
||||||
|
*
|
||||||
|
* @param url YouTube URL
|
||||||
|
* @return the video id
|
||||||
*/
|
*/
|
||||||
static String getYouTubeId(String url) {
|
static String getYouTubeId(final String url) {
|
||||||
|
|
||||||
HttpUrl httpUrl = HttpUrl.parse(url);
|
final HttpUrl httpUrl = HttpUrl.parse(url);
|
||||||
|
|
||||||
return httpUrl == null ? null
|
return httpUrl == null ? null
|
||||||
: httpUrl.queryParameter("v")
|
: httpUrl.queryParameter("v");
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeWatchedStreams(final boolean removePartiallyWatched) {
|
public void removeWatchedStreams(final boolean removePartiallyWatched) {
|
||||||
@ -924,7 +942,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) ->
|
.setPositiveButton(R.string.share_playlist_with_titles, (dialog, which) ->
|
||||||
sharePlaylist(WITH_TITLES)
|
sharePlaylist(WITH_TITLES)
|
||||||
)
|
)
|
||||||
.setNeutralButton("Share as YouTube temporary playlist", (dialog, which) -> // TODO R.string.share_playlist_as_YouTube_temporary_playlist
|
// TODO R.string.share_playlist_as_YouTube_temporary_playlist
|
||||||
|
.setNeutralButton("Share as YouTube temporary playlist", (dialog, which) ->
|
||||||
sharePlaylist(YOUTUBE_TEMP_PLAYLIST)
|
sharePlaylist(YOUTUBE_TEMP_PLAYLIST)
|
||||||
)
|
)
|
||||||
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) ->
|
.setNegativeButton(R.string.share_playlist_with_list, (dialog, which) ->
|
||||||
|
@ -2,7 +2,7 @@ package org.schabi.newpipe.local.playlist;
|
|||||||
|
|
||||||
public enum PlayListShareMode {
|
public enum PlayListShareMode {
|
||||||
|
|
||||||
JUST_URLS
|
JUST_URLS,
|
||||||
,WITH_TITLES
|
WITH_TITLES,
|
||||||
,YOUTUBE_TEMP_PLAYLIST
|
YOUTUBE_TEMP_PLAYLIST
|
||||||
}
|
}
|
||||||
|
@ -10,37 +10,36 @@ import org.junit.Test;
|
|||||||
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class LocalPlaylistFragmentTest {
|
public class LocalPlaylistFragmentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void export_asYouTubeTempPlaylist() {
|
public void exportAsYouTubeTempPlaylist() {
|
||||||
|
|
||||||
Stream<StreamEntity> entityStream = asStreamEntityStream(
|
final Stream<StreamEntity> entityStream = asStreamEntityStream(
|
||||||
|
|
||||||
"https://www.youtube.com/watch?v=1"
|
"https://www.youtube.com/watch?v=1",
|
||||||
,"https://www.youtube.com/watch?v=2"
|
"https://www.youtube.com/watch?v=2",
|
||||||
,"https://www.youtube.com/watch?v=3"
|
"https://www.youtube.com/watch?v=3"
|
||||||
);
|
);
|
||||||
|
|
||||||
String url = LocalPlaylistFragment.export(YOUTUBE_TEMP_PLAYLIST, entityStream, null);
|
final String url = LocalPlaylistFragment.export(YOUTUBE_TEMP_PLAYLIST, entityStream, null);
|
||||||
|
|
||||||
Assert.assertEquals("http://www.youtube.com/watch_videos?video_ids=1,2,3", url);
|
Assert.assertEquals("http://www.youtube.com/watch_videos?video_ids=1,2,3", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void export_justUrls() {
|
public void exportJustUrls() {
|
||||||
|
|
||||||
Stream<StreamEntity> entityStream = asStreamEntityStream(
|
final Stream<StreamEntity> entityStream = asStreamEntityStream(
|
||||||
|
|
||||||
"https://www.youtube.com/watch?v=1"
|
"https://www.youtube.com/watch?v=1",
|
||||||
,"https://www.youtube.com/watch?v=2"
|
"https://www.youtube.com/watch?v=2",
|
||||||
,"https://www.youtube.com/watch?v=3"
|
"https://www.youtube.com/watch?v=3"
|
||||||
);
|
);
|
||||||
|
|
||||||
String exported = LocalPlaylistFragment.export(JUST_URLS, entityStream, null);
|
final String exported = LocalPlaylistFragment.export(JUST_URLS, entityStream, null);
|
||||||
|
|
||||||
Assert.assertEquals("""
|
Assert.assertEquals("""
|
||||||
https://www.youtube.com/watch?v=1
|
https://www.youtube.com/watch?v=1
|
||||||
@ -49,30 +48,30 @@ public class LocalPlaylistFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static Stream<StreamEntity> asStreamEntityStream(String... urls) {
|
private static Stream<StreamEntity> asStreamEntityStream(final String... urls) {
|
||||||
|
|
||||||
return Stream.of(urls)
|
return Stream.of(urls)
|
||||||
.map(LocalPlaylistFragmentTest::newStreamEntity);
|
.map(LocalPlaylistFragmentTest::newStreamEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static StreamEntity newStreamEntity(String url) {
|
static StreamEntity newStreamEntity(final String url) {
|
||||||
|
|
||||||
return new StreamEntity(
|
return new StreamEntity(
|
||||||
|
|
||||||
0
|
0,
|
||||||
, 1
|
1,
|
||||||
, url
|
url,
|
||||||
, "Title"
|
"Title",
|
||||||
, StreamType.VIDEO_STREAM
|
StreamType.VIDEO_STREAM,
|
||||||
, 100
|
100,
|
||||||
, "Uploader"
|
"Uploader",
|
||||||
, null
|
null,
|
||||||
, null
|
null,
|
||||||
, null
|
null,
|
||||||
, null
|
null,
|
||||||
, null
|
null,
|
||||||
, null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user