Skip to content

Commit 813f551

Browse files
authored
Merge branch 'TeamNewPipe:dev' into feature-7870
2 parents 270a541 + 8441aff commit 813f551

6 files changed

Lines changed: 53 additions & 30 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The [checkStyle](https://github.com/checkstyle/checkstyle) plugin verifies that
6868
- Go to `File -> Settings -> Plugins`, search for `checkstyle` and install `CheckStyle-IDEA`.
6969
- Go to `File -> Settings -> Tools -> Checkstyle`.
7070
- Add NewPipe's configuration file by clicking the `+` in the right toolbar of the "Configuration File" list.
71-
- Under the "Use a local Checkstyle file" bullet, click on `Browse` and pick the file named `checkstyle.xml` in the project's root folder.
71+
- Under the "Use a local Checkstyle file" bullet, click on `Browse` and, enter `checkstyle` folder under the project's root path and pick the file named `checkstyle.xml`.
7272
- Enable "Store relative to project location" so that moving the directory around does not create issues.
7373
- Insert a description in the top bar, then click `Next` and then `Finish`.
7474
- Activate the configuration file you just added by enabling the checkbox on the left.

app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
3333

3434
private final CompositeDisposable playlistDisposables = new CompositeDisposable();
3535

36-
public PlaylistAppendDialog(final List<StreamEntity> streamEntities) {
37-
super(streamEntities);
36+
/**
37+
* Create a new instance of {@link PlaylistAppendDialog}.
38+
*
39+
* @param streamEntities a list of {@link StreamEntity} to be added to playlists
40+
* @return a new instance of {@link PlaylistAppendDialog}
41+
*/
42+
public static PlaylistAppendDialog newInstance(final List<StreamEntity> streamEntities) {
43+
final PlaylistAppendDialog dialog = new PlaylistAppendDialog();
44+
dialog.setStreamEntities(streamEntities);
45+
return dialog;
3846
}
3947

4048
/*//////////////////////////////////////////////////////////////////////////
@@ -103,13 +111,14 @@ public void onDestroyView() {
103111
// Helper
104112
//////////////////////////////////////////////////////////////////////////*/
105113

114+
/** Display create playlist dialog. */
106115
public void openCreatePlaylistDialog() {
107116
if (getStreamEntities() == null || !isAdded()) {
108117
return;
109118
}
110119

111120
final PlaylistCreationDialog playlistCreationDialog =
112-
new PlaylistCreationDialog(getStreamEntities());
121+
PlaylistCreationDialog.newInstance(getStreamEntities());
113122
// Move the dismissListener to the new dialog.
114123
playlistCreationDialog.setOnDismissListener(this.getOnDismissListener());
115124
this.setOnDismissListener(null);

app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistCreationDialog.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@
2121
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
2222

2323
public final class PlaylistCreationDialog extends PlaylistDialog {
24-
public PlaylistCreationDialog(final List<StreamEntity> streamEntities) {
25-
super(streamEntities);
24+
25+
/**
26+
* Create a new instance of {@link PlaylistCreationDialog}.
27+
*
28+
* @param streamEntities a list of {@link StreamEntity} to be added to playlists
29+
* @return a new instance of {@link PlaylistCreationDialog}
30+
*/
31+
public static PlaylistCreationDialog newInstance(final List<StreamEntity> streamEntities) {
32+
final PlaylistCreationDialog dialog = new PlaylistCreationDialog();
33+
dialog.setStreamEntities(streamEntities);
34+
return dialog;
2635
}
2736

2837
/*//////////////////////////////////////////////////////////////////////////

app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
3131

3232
private org.schabi.newpipe.util.SavedState savedState;
3333

34-
public PlaylistDialog(final List<StreamEntity> streamEntities) {
35-
this.streamEntities = streamEntities;
36-
}
37-
3834
/*//////////////////////////////////////////////////////////////////////////
3935
// LifeCycle
4036
//////////////////////////////////////////////////////////////////////////*/
@@ -120,6 +116,10 @@ public void setOnDismissListener(
120116
this.onDismissListener = onDismissListener;
121117
}
122118

119+
protected void setStreamEntities(final List<StreamEntity> streamEntities) {
120+
this.streamEntities = streamEntities;
121+
}
122+
123123
/*//////////////////////////////////////////////////////////////////////////
124124
// Dialog creation
125125
//////////////////////////////////////////////////////////////////////////*/
@@ -143,8 +143,8 @@ public static Disposable createCorrespondingDialog(
143143
.observeOn(AndroidSchedulers.mainThread())
144144
.subscribe(hasPlaylists ->
145145
onExec.accept(hasPlaylists
146-
? new PlaylistAppendDialog(streamEntities)
147-
: new PlaylistCreationDialog(streamEntities))
146+
? PlaylistAppendDialog.newInstance(streamEntities)
147+
: PlaylistCreationDialog.newInstance(streamEntities))
148148
);
149149
}
150150
}

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import androidx.appcompat.view.ContextThemeWrapper;
117117
import androidx.appcompat.widget.AppCompatImageButton;
118118
import androidx.appcompat.widget.PopupMenu;
119+
import androidx.collection.ArraySet;
119120
import androidx.core.content.ContextCompat;
120121
import androidx.core.graphics.Insets;
121122
import androidx.core.view.GestureDetectorCompat;
@@ -4217,21 +4218,21 @@ private void useVideoSource(final boolean videoEnabled) {
42174218
// in livestreams) so we will be not able to execute the block below.
42184219
// Reload the play queue manager in this case, which is the behavior when we don't know the
42194220
// index of the video renderer or playQueueManagerReloadingNeeded returns true.
4220-
if (!getCurrentStreamInfo().isPresent()) {
4221+
final Optional<StreamInfo> optCurrentStreamInfo = getCurrentStreamInfo();
4222+
if (!optCurrentStreamInfo.isPresent()) {
42214223
reloadPlayQueueManager();
42224224
setRecovery();
42234225
return;
42244226
}
42254227

4226-
final int videoRenderIndex = getVideoRendererIndex();
4227-
final StreamInfo info = getCurrentStreamInfo().get();
4228+
final StreamInfo info = optCurrentStreamInfo.get();
42284229

42294230
// In the case we don't know the source type, fallback to the one with video with audio or
42304231
// audio-only source.
42314232
final SourceType sourceType = videoResolver.getStreamSourceType().orElse(
42324233
SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
42334234

4234-
if (playQueueManagerReloadingNeeded(sourceType, info, videoRenderIndex)) {
4235+
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
42354236
reloadPlayQueueManager();
42364237
} else {
42374238
final StreamType streamType = info.getStreamType();
@@ -4242,19 +4243,22 @@ private void useVideoSource(final boolean videoEnabled) {
42424243
return;
42434244
}
42444245

4245-
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
4246-
trackSelector.getCurrentMappedTrackInfo()).getTrackGroups(videoRenderIndex);
4246+
final DefaultTrackSelector.ParametersBuilder parametersBuilder =
4247+
trackSelector.buildUponParameters();
4248+
42474249
if (videoEnabled) {
4248-
// Clearing the null selection override enable again the video stream (and its
4249-
// fetching).
4250-
trackSelector.setParameters(trackSelector.buildUponParameters()
4251-
.clearSelectionOverride(videoRenderIndex, videoTrackGroupArray));
4250+
// Enable again the video track and the subtitles, if there is one selected
4251+
parametersBuilder.setDisabledTrackTypes(Collections.emptySet());
42524252
} else {
4253-
// Using setRendererDisabled still fetch the video stream in background, contrary
4254-
// to setSelectionOverride with a null override.
4255-
trackSelector.setParameters(trackSelector.buildUponParameters()
4256-
.setSelectionOverride(videoRenderIndex, videoTrackGroupArray, null));
4253+
// Disable the video track and the ability to select subtitles
4254+
// Use an ArraySet because we can't use Set.of() on all supported APIs by the app
4255+
final ArraySet<Integer> disabledTracks = new ArraySet<>();
4256+
disabledTracks.add(C.TRACK_TYPE_TEXT);
4257+
disabledTracks.add(C.TRACK_TYPE_VIDEO);
4258+
parametersBuilder.setDisabledTrackTypes(disabledTracks);
42574259
}
4260+
4261+
trackSelector.setParameters(parametersBuilder);
42584262
}
42594263

42604264
setRecovery();

app/src/main/java/org/schabi/newpipe/util/SparseItemUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static void fetchItemInfoIfSparse(@NonNull final Context context,
5454
// if the duration is >= 0 (provided that the item is not a livestream) and there is an
5555
// uploader url, probably all info is already there, so there is no need to fetch it
5656
callback.accept(new SinglePlayQueue(item));
57+
return;
5758
}
5859

5960
// either the duration or the uploader url are not available, so fetch more info
@@ -80,12 +81,12 @@ public static void fetchUploaderUrlIfSparse(@NonNull final Context context,
8081
@NonNull final String url,
8182
@Nullable final String uploaderUrl,
8283
@NonNull final Consumer<String> callback) {
83-
if (isNullOrEmpty(uploaderUrl)) {
84-
fetchStreamInfoAndSaveToDatabase(context, serviceId, url,
85-
streamInfo -> callback.accept(streamInfo.getUploaderUrl()));
86-
} else {
84+
if (!isNullOrEmpty(uploaderUrl)) {
8785
callback.accept(uploaderUrl);
86+
return;
8887
}
88+
fetchStreamInfoAndSaveToDatabase(context, serviceId, url,
89+
streamInfo -> callback.accept(streamInfo.getUploaderUrl()));
8990
}
9091

9192
/**

0 commit comments

Comments
 (0)