mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-03 14:00:32 +00:00
Rename StreamSizeWrapper to StreamInfoWrapper
This commit is contained in:
parent
ac5f991c0c
commit
0db12e5561
@ -84,7 +84,7 @@ class StreamItemAdapterTest {
|
|||||||
@Test
|
@Test
|
||||||
fun subtitleStreams_noIcon() {
|
fun subtitleStreams_noIcon() {
|
||||||
val adapter = StreamItemAdapter<SubtitlesStream, Stream>(
|
val adapter = StreamItemAdapter<SubtitlesStream, Stream>(
|
||||||
StreamItemAdapter.StreamSizeWrapper(
|
StreamItemAdapter.StreamInfoWrapper(
|
||||||
(0 until 5).map {
|
(0 until 5).map {
|
||||||
SubtitlesStream.Builder()
|
SubtitlesStream.Builder()
|
||||||
.setContent("https://example.com", true)
|
.setContent("https://example.com", true)
|
||||||
@ -105,7 +105,7 @@ class StreamItemAdapterTest {
|
|||||||
@Test
|
@Test
|
||||||
fun audioStreams_noIcon() {
|
fun audioStreams_noIcon() {
|
||||||
val adapter = StreamItemAdapter<AudioStream, Stream>(
|
val adapter = StreamItemAdapter<AudioStream, Stream>(
|
||||||
StreamItemAdapter.StreamSizeWrapper(
|
StreamItemAdapter.StreamInfoWrapper(
|
||||||
(0 until 5).map {
|
(0 until 5).map {
|
||||||
AudioStream.Builder()
|
AudioStream.Builder()
|
||||||
.setId(Stream.ID_UNKNOWN)
|
.setId(Stream.ID_UNKNOWN)
|
||||||
@ -128,7 +128,7 @@ class StreamItemAdapterTest {
|
|||||||
* [videoOnly] vararg.
|
* [videoOnly] vararg.
|
||||||
*/
|
*/
|
||||||
private fun getVideoStreams(vararg videoOnly: Boolean) =
|
private fun getVideoStreams(vararg videoOnly: Boolean) =
|
||||||
StreamItemAdapter.StreamSizeWrapper(
|
StreamItemAdapter.StreamInfoWrapper(
|
||||||
videoOnly.map {
|
videoOnly.map {
|
||||||
VideoStream.Builder()
|
VideoStream.Builder()
|
||||||
.setId(Stream.ID_UNKNOWN)
|
.setId(Stream.ID_UNKNOWN)
|
||||||
@ -196,7 +196,7 @@ class StreamItemAdapterTest {
|
|||||||
streams.forEachIndexed { index, stream ->
|
streams.forEachIndexed { index, stream ->
|
||||||
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
|
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
|
||||||
SecondaryStreamHelper(
|
SecondaryStreamHelper(
|
||||||
StreamItemAdapter.StreamSizeWrapper(streams, context),
|
StreamItemAdapter.StreamInfoWrapper(streams, context),
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ import org.schabi.newpipe.util.PermissionHelper;
|
|||||||
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
||||||
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
|
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter;
|
import org.schabi.newpipe.util.StreamItemAdapter;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper;
|
||||||
import org.schabi.newpipe.util.AudioTrackAdapter;
|
import org.schabi.newpipe.util.AudioTrackAdapter;
|
||||||
import org.schabi.newpipe.util.AudioTrackAdapter.AudioTracksWrapper;
|
import org.schabi.newpipe.util.AudioTrackAdapter.AudioTracksWrapper;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
@ -97,9 +97,9 @@ public class DownloadDialog extends DialogFragment
|
|||||||
@State
|
@State
|
||||||
StreamInfo currentInfo;
|
StreamInfo currentInfo;
|
||||||
@State
|
@State
|
||||||
StreamSizeWrapper<VideoStream> wrappedVideoStreams;
|
StreamInfoWrapper<VideoStream> wrappedVideoStreams;
|
||||||
@State
|
@State
|
||||||
StreamSizeWrapper<SubtitlesStream> wrappedSubtitleStreams;
|
StreamInfoWrapper<SubtitlesStream> wrappedSubtitleStreams;
|
||||||
@State
|
@State
|
||||||
AudioTracksWrapper wrappedAudioTracks;
|
AudioTracksWrapper wrappedAudioTracks;
|
||||||
@State
|
@State
|
||||||
@ -187,8 +187,8 @@ public class DownloadDialog extends DialogFragment
|
|||||||
wrappedAudioTracks.size() > 1
|
wrappedAudioTracks.size() > 1
|
||||||
);
|
);
|
||||||
|
|
||||||
this.wrappedVideoStreams = new StreamSizeWrapper<>(videoStreams, context);
|
this.wrappedVideoStreams = new StreamInfoWrapper<>(videoStreams, context);
|
||||||
this.wrappedSubtitleStreams = new StreamSizeWrapper<>(
|
this.wrappedSubtitleStreams = new StreamInfoWrapper<>(
|
||||||
getStreamsOfSpecifiedDelivery(info.getSubtitles(), PROGRESSIVE_HTTP), context);
|
getStreamsOfSpecifiedDelivery(info.getSubtitles(), PROGRESSIVE_HTTP), context);
|
||||||
|
|
||||||
this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams);
|
this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams);
|
||||||
@ -258,10 +258,10 @@ public class DownloadDialog extends DialogFragment
|
|||||||
* Update the displayed video streams based on the selected audio track.
|
* Update the displayed video streams based on the selected audio track.
|
||||||
*/
|
*/
|
||||||
private void updateSecondaryStreams() {
|
private void updateSecondaryStreams() {
|
||||||
final StreamSizeWrapper<AudioStream> audioStreams = getWrappedAudioStreams();
|
final StreamInfoWrapper<AudioStream> audioStreams = getWrappedAudioStreams();
|
||||||
final var secondaryStreams = new SparseArrayCompat<SecondaryStreamHelper<AudioStream>>(4);
|
final var secondaryStreams = new SparseArrayCompat<SecondaryStreamHelper<AudioStream>>(4);
|
||||||
final List<VideoStream> videoStreams = wrappedVideoStreams.getStreamsList();
|
final List<VideoStream> videoStreams = wrappedVideoStreams.getStreamsList();
|
||||||
wrappedVideoStreams.resetSizes();
|
wrappedVideoStreams.resetInfo();
|
||||||
|
|
||||||
for (int i = 0; i < videoStreams.size(); i++) {
|
for (int i = 0; i < videoStreams.size(); i++) {
|
||||||
if (!videoStreams.get(i).isVideoOnly()) {
|
if (!videoStreams.get(i).isVideoOnly()) {
|
||||||
@ -396,7 +396,7 @@ public class DownloadDialog extends DialogFragment
|
|||||||
|
|
||||||
private void fetchStreamsSize() {
|
private void fetchStreamsSize() {
|
||||||
disposables.clear();
|
disposables.clear();
|
||||||
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(wrappedVideoStreams)
|
disposables.add(StreamInfoWrapper.fetchMoreInfoForWrapper(wrappedVideoStreams)
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
||||||
== R.id.video_button) {
|
== R.id.video_button) {
|
||||||
@ -406,7 +406,7 @@ public class DownloadDialog extends DialogFragment
|
|||||||
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
||||||
"Downloading video stream size",
|
"Downloading video stream size",
|
||||||
currentInfo.getServiceId()))));
|
currentInfo.getServiceId()))));
|
||||||
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(getWrappedAudioStreams())
|
disposables.add(StreamInfoWrapper.fetchMoreInfoForWrapper(getWrappedAudioStreams())
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
||||||
== R.id.audio_button) {
|
== R.id.audio_button) {
|
||||||
@ -416,7 +416,7 @@ public class DownloadDialog extends DialogFragment
|
|||||||
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
||||||
"Downloading audio stream size",
|
"Downloading audio stream size",
|
||||||
currentInfo.getServiceId()))));
|
currentInfo.getServiceId()))));
|
||||||
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(wrappedSubtitleStreams)
|
disposables.add(StreamInfoWrapper.fetchMoreInfoForWrapper(wrappedSubtitleStreams)
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
||||||
== R.id.subtitle_button) {
|
== R.id.subtitle_button) {
|
||||||
@ -724,9 +724,9 @@ public class DownloadDialog extends DialogFragment
|
|||||||
dialogBinding.subtitleButton.setEnabled(enabled);
|
dialogBinding.subtitleButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamSizeWrapper<AudioStream> getWrappedAudioStreams() {
|
private StreamInfoWrapper<AudioStream> getWrappedAudioStreams() {
|
||||||
if (selectedAudioTrackIndex < 0 || selectedAudioTrackIndex > wrappedAudioTracks.size()) {
|
if (selectedAudioTrackIndex < 0 || selectedAudioTrackIndex > wrappedAudioTracks.size()) {
|
||||||
return StreamSizeWrapper.empty();
|
return StreamInfoWrapper.empty();
|
||||||
}
|
}
|
||||||
return wrappedAudioTracks.getTracksList().get(selectedAudioTrackIndex);
|
return wrappedAudioTracks.getTracksList().get(selectedAudioTrackIndex);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -75,15 +75,15 @@ public class AudioTrackAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class AudioTracksWrapper implements Serializable {
|
public static class AudioTracksWrapper implements Serializable {
|
||||||
private final List<StreamSizeWrapper<AudioStream>> tracksList;
|
private final List<StreamInfoWrapper<AudioStream>> tracksList;
|
||||||
|
|
||||||
public AudioTracksWrapper(@NonNull final List<List<AudioStream>> groupedAudioStreams,
|
public AudioTracksWrapper(@NonNull final List<List<AudioStream>> groupedAudioStreams,
|
||||||
@Nullable final Context context) {
|
@Nullable final Context context) {
|
||||||
this.tracksList = groupedAudioStreams.stream().map(streams ->
|
this.tracksList = groupedAudioStreams.stream().map(streams ->
|
||||||
new StreamSizeWrapper<>(streams, context)).collect(Collectors.toList());
|
new StreamInfoWrapper<>(streams, context)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StreamSizeWrapper<AudioStream>> getTracksList() {
|
public List<StreamInfoWrapper<AudioStream>> getTracksList() {
|
||||||
return tracksList;
|
return tracksList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,15 +7,15 @@ import org.schabi.newpipe.extractor.MediaFormat;
|
|||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
import org.schabi.newpipe.extractor.stream.Stream;
|
import org.schabi.newpipe.extractor.stream.Stream;
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SecondaryStreamHelper<T extends Stream> {
|
public class SecondaryStreamHelper<T extends Stream> {
|
||||||
private final int position;
|
private final int position;
|
||||||
private final StreamSizeWrapper<T> streams;
|
private final StreamInfoWrapper<T> streams;
|
||||||
|
|
||||||
public SecondaryStreamHelper(@NonNull final StreamSizeWrapper<T> streams,
|
public SecondaryStreamHelper(@NonNull final StreamInfoWrapper<T> streams,
|
||||||
final T selectedStream) {
|
final T selectedStream) {
|
||||||
this.streams = streams;
|
this.streams = streams;
|
||||||
this.position = streams.getStreamsList().indexOf(selectedStream);
|
this.position = streams.getStreamsList().indexOf(selectedStream);
|
||||||
|
@ -41,7 +41,7 @@ import us.shandian.giga.util.Utility;
|
|||||||
*/
|
*/
|
||||||
public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseAdapter {
|
public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseAdapter {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final StreamSizeWrapper<T> streamsWrapper;
|
private final StreamInfoWrapper<T> streamsWrapper;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SparseArrayCompat<SecondaryStreamHelper<U>> secondaryStreams;
|
private final SparseArrayCompat<SecondaryStreamHelper<U>> secondaryStreams;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
private final boolean hasAnyVideoOnlyStreamWithNoSecondaryStream;
|
private final boolean hasAnyVideoOnlyStreamWithNoSecondaryStream;
|
||||||
|
|
||||||
public StreamItemAdapter(
|
public StreamItemAdapter(
|
||||||
@NonNull final StreamSizeWrapper<T> streamsWrapper,
|
@NonNull final StreamInfoWrapper<T> streamsWrapper,
|
||||||
@NonNull final SparseArrayCompat<SecondaryStreamHelper<U>> secondaryStreams
|
@NonNull final SparseArrayCompat<SecondaryStreamHelper<U>> secondaryStreams
|
||||||
) {
|
) {
|
||||||
this.streamsWrapper = streamsWrapper;
|
this.streamsWrapper = streamsWrapper;
|
||||||
@ -63,7 +63,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
checkHasAnyVideoOnlyStreamWithNoSecondaryStream();
|
checkHasAnyVideoOnlyStreamWithNoSecondaryStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamItemAdapter(final StreamSizeWrapper<T> streamsWrapper) {
|
public StreamItemAdapter(final StreamInfoWrapper<T> streamsWrapper) {
|
||||||
this(streamsWrapper, new SparseArrayCompat<>(0));
|
this(streamsWrapper, new SparseArrayCompat<>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
final TextView sizeView = convertView.findViewById(R.id.stream_size);
|
final TextView sizeView = convertView.findViewById(R.id.stream_size);
|
||||||
|
|
||||||
final T stream = getItem(position);
|
final T stream = getItem(position);
|
||||||
final MediaFormat mediaFormat = stream.getFormat();
|
final MediaFormat mediaFormat = streamsWrapper.getFormat(position);
|
||||||
|
|
||||||
int woSoundIconVisibility = View.GONE;
|
int woSoundIconVisibility = View.GONE;
|
||||||
String qualityString;
|
String qualityString;
|
||||||
@ -221,16 +221,16 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
*
|
*
|
||||||
* @param <T> the stream type's class extending {@link Stream}
|
* @param <T> the stream type's class extending {@link Stream}
|
||||||
*/
|
*/
|
||||||
public static class StreamSizeWrapper<T extends Stream> implements Serializable {
|
public static class StreamInfoWrapper<T extends Stream> implements Serializable {
|
||||||
private static final StreamSizeWrapper<Stream> EMPTY =
|
private static final StreamInfoWrapper<Stream> EMPTY =
|
||||||
new StreamSizeWrapper<>(Collections.emptyList(), null);
|
new StreamInfoWrapper<>(Collections.emptyList(), null);
|
||||||
private static final int SIZE_UNSET = -2;
|
private static final int SIZE_UNSET = -2;
|
||||||
|
|
||||||
private final List<T> streamsList;
|
private final List<T> streamsList;
|
||||||
private final long[] streamSizes;
|
private final long[] streamSizes;
|
||||||
private final String unknownSize;
|
private final String unknownSize;
|
||||||
|
|
||||||
public StreamSizeWrapper(@NonNull final List<T> streamList,
|
public StreamInfoWrapper(@NonNull final List<T> streamList,
|
||||||
@Nullable final Context context) {
|
@Nullable final Context context) {
|
||||||
this.streamsList = streamList;
|
this.streamsList = streamList;
|
||||||
this.streamSizes = new long[streamsList.size()];
|
this.streamSizes = new long[streamsList.size()];
|
||||||
@ -249,7 +249,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static <X extends Stream> Single<Boolean> fetchSizeForWrapper(
|
public static <X extends Stream> Single<Boolean> fetchSizeForWrapper(
|
||||||
final StreamSizeWrapper<X> streamsWrapper) {
|
final StreamInfoWrapper<X> streamsWrapper) {
|
||||||
final Callable<Boolean> fetchAndSet = () -> {
|
final Callable<Boolean> fetchAndSet = () -> {
|
||||||
boolean hasChanged = false;
|
boolean hasChanged = false;
|
||||||
for (final X stream : streamsWrapper.getStreamsList()) {
|
for (final X stream : streamsWrapper.getStreamsList()) {
|
||||||
@ -275,9 +275,9 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
Arrays.fill(streamSizes, SIZE_UNSET);
|
Arrays.fill(streamSizes, SIZE_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <X extends Stream> StreamSizeWrapper<X> empty() {
|
public static <X extends Stream> StreamInfoWrapper<X> empty() {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (StreamSizeWrapper<X>) EMPTY;
|
return (StreamInfoWrapper<X>) EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getStreamsList() {
|
public List<T> getStreamsList() {
|
||||||
|
Loading…
Reference in New Issue
Block a user