Skip to content

Commit b7a4456

Browse files
authored
Merge pull request TeamNewPipe#8170 from Stypox/player-refactor
Refactor player and extract UI components
2 parents 33e2076 + 0e8cc72 commit b7a4456

45 files changed

Lines changed: 5013 additions & 4099 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</receiver>
4545

4646
<service
47-
android:name=".player.MainPlayer"
47+
android:name=".player.PlayerService"
4848
android:exported="false"
4949
android:foregroundServiceType="mediaPlayback">
5050
<intent-filter>

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import org.schabi.newpipe.extractor.stream.StreamInfo;
6161
import org.schabi.newpipe.ktx.ExceptionUtils;
6262
import org.schabi.newpipe.local.dialog.PlaylistDialog;
63-
import org.schabi.newpipe.player.MainPlayer;
63+
import org.schabi.newpipe.player.PlayerType;
6464
import org.schabi.newpipe.player.helper.PlayerHelper;
6565
import org.schabi.newpipe.player.helper.PlayerHolder;
6666
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
@@ -630,8 +630,8 @@ private boolean canHandleChoiceLikeShowInfo(final String selectedChoiceKey) {
630630
}
631631

632632
// ...the player is not running or in normal Video-mode/type
633-
final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
634-
return playerType == null || playerType == MainPlayer.PlayerType.VIDEO;
633+
final PlayerType playerType = PlayerHolder.getInstance().getType();
634+
return playerType == null || playerType == PlayerType.MAIN;
635635
}
636636

637637
private void openAddToPlaylistDialog() {

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 98 additions & 79 deletions
Large diffs are not rendered by default.

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.schabi.newpipe.ktx.AnimationType;
4444
import org.schabi.newpipe.local.subscription.SubscriptionManager;
4545
import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
46-
import org.schabi.newpipe.player.MainPlayer.PlayerType;
46+
import org.schabi.newpipe.player.PlayerType;
4747
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
4848
import org.schabi.newpipe.player.playqueue.PlayQueue;
4949
import org.schabi.newpipe.util.ExtractorHelper;

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry;
4444
import org.schabi.newpipe.local.dialog.PlaylistDialog;
4545
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
46-
import org.schabi.newpipe.player.MainPlayer.PlayerType;
46+
import org.schabi.newpipe.player.PlayerType;
4747
import org.schabi.newpipe.player.playqueue.PlayQueue;
4848
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
4949
import org.schabi.newpipe.util.ExtractorHelper;

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
import androidx.annotation.NonNull;
1010
import androidx.annotation.Nullable;
1111
import androidx.fragment.app.DialogFragment;
12+
import androidx.fragment.app.FragmentManager;
1213

1314
import org.schabi.newpipe.NewPipeDatabase;
1415
import org.schabi.newpipe.database.stream.model.StreamEntity;
1516
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
17+
import org.schabi.newpipe.player.Player;
1618
import org.schabi.newpipe.util.StateSaver;
1719

1820
import java.util.List;
21+
import java.util.Objects;
1922
import java.util.Queue;
2023
import java.util.function.Consumer;
24+
import java.util.stream.Collectors;
25+
import java.util.stream.Stream;
2126

2227
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
2328
import io.reactivex.rxjava3.disposables.Disposable;
@@ -131,13 +136,13 @@ protected void setStreamEntities(final List<StreamEntity> streamEntities) {
131136
* @param context context used for accessing the database
132137
* @param streamEntities used for crating the dialog
133138
* @param onExec execution that should occur after a dialog got created, e.g. showing it
134-
* @return Disposable
139+
* @return the disposable that was created
135140
*/
136141
public static Disposable createCorrespondingDialog(
137142
final Context context,
138143
final List<StreamEntity> streamEntities,
139-
final Consumer<PlaylistDialog> onExec
140-
) {
144+
final Consumer<PlaylistDialog> onExec) {
145+
141146
return new LocalPlaylistManager(NewPipeDatabase.getInstance(context))
142147
.hasPlaylists()
143148
.observeOn(AndroidSchedulers.mainThread())
@@ -147,4 +152,30 @@ public static Disposable createCorrespondingDialog(
147152
: PlaylistCreationDialog.newInstance(streamEntities))
148153
);
149154
}
155+
156+
/**
157+
* Creates a {@link PlaylistAppendDialog} when playlists exists,
158+
* otherwise a {@link PlaylistCreationDialog}. If the player's play queue is null or empty, no
159+
* dialog will be created.
160+
*
161+
* @param player the player from which to extract the context and the play queue
162+
* @param fragmentManager the fragment manager to use to show the dialog
163+
* @return the disposable that was created
164+
*/
165+
public static Disposable showForPlayQueue(
166+
final Player player,
167+
@NonNull final FragmentManager fragmentManager) {
168+
169+
final List<StreamEntity> streamEntities = Stream.of(player.getPlayQueue())
170+
.filter(Objects::nonNull)
171+
.flatMap(playQueue -> playQueue.getStreams().stream())
172+
.map(StreamEntity::new)
173+
.collect(Collectors.toList());
174+
if (streamEntities.isEmpty()) {
175+
return Disposable.empty();
176+
}
177+
178+
return PlaylistDialog.createCorrespondingDialog(player.getContext(), streamEntities,
179+
dialog -> dialog.show(fragmentManager, "PlaylistDialog"));
180+
}
150181
}

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.schabi.newpipe.info_list.dialog.InfoItemDialog;
4545
import org.schabi.newpipe.local.BaseLocalListFragment;
4646
import org.schabi.newpipe.local.history.HistoryRecordManager;
47-
import org.schabi.newpipe.player.MainPlayer.PlayerType;
47+
import org.schabi.newpipe.player.PlayerType;
4848
import org.schabi.newpipe.player.playqueue.PlayQueue;
4949
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
5050
import org.schabi.newpipe.util.Localization;

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

Lines changed: 0 additions & 259 deletions
This file was deleted.

0 commit comments

Comments
 (0)