mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-09-01 18:37:56 +00:00
PlayerUIList: remove remaining uses of getOpt
mediaSession is now `@NonNull`, so the getter is as well.
This commit is contained in:
@@ -477,22 +477,23 @@ public final class Player implements PlaybackListener, Listener {
|
||||
}
|
||||
|
||||
private void initUIsForCurrentPlayerType() {
|
||||
if ((UIs.getOpt(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
|
||||
|| (UIs.getOpt(PopupPlayerUi.class).isPresent()
|
||||
if ((UIs.get(MainPlayerUi.class) != null && playerType == PlayerType.MAIN)
|
||||
|| (UIs.get(PopupPlayerUi.class) != null
|
||||
&& playerType == PlayerType.POPUP)) {
|
||||
// correct UI already in place
|
||||
return;
|
||||
}
|
||||
|
||||
// try to reuse binding if possible
|
||||
final PlayerBinding binding = UIs.getOpt(VideoPlayerUi.class).map(VideoPlayerUi::getBinding)
|
||||
.orElseGet(() -> {
|
||||
if (playerType == PlayerType.AUDIO) {
|
||||
return null;
|
||||
} else {
|
||||
return PlayerBinding.inflate(LayoutInflater.from(context));
|
||||
}
|
||||
});
|
||||
@Nullable final VideoPlayerUi ui = UIs.get(VideoPlayerUi.class);
|
||||
final PlayerBinding binding;
|
||||
if (ui != null) {
|
||||
binding = ui.getBinding();
|
||||
} else if (playerType == PlayerType.AUDIO) {
|
||||
binding = null;
|
||||
} else {
|
||||
binding = PlayerBinding.inflate(LayoutInflater.from(context));
|
||||
}
|
||||
|
||||
switch (playerType) {
|
||||
case MAIN:
|
||||
|
@@ -124,8 +124,10 @@ public class MediaSessionPlayerUi extends PlayerUi
|
||||
MediaButtonReceiver.handleIntent(mediaSession, intent);
|
||||
}
|
||||
|
||||
public Optional<MediaSessionCompat.Token> getSessionToken() {
|
||||
return Optional.ofNullable(mediaSession).map(MediaSessionCompat::getSessionToken);
|
||||
|
||||
@NonNull
|
||||
public MediaSessionCompat.Token getSessionToken() {
|
||||
return mediaSession.getSessionToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +140,10 @@ public class MediaSessionPlayerUi extends PlayerUi
|
||||
public void play() {
|
||||
player.play();
|
||||
// hide the player controls even if the play command came from the media session
|
||||
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
|
||||
final VideoPlayerUi ui = player.UIs().get(VideoPlayerUi.class);
|
||||
if (ui != null) {
|
||||
ui.hideControls(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -101,10 +101,10 @@ public final class NotificationUtil {
|
||||
final int[] compactSlots = initializeNotificationSlots();
|
||||
mediaStyle.setShowActionsInCompactView(compactSlots);
|
||||
}
|
||||
player.UIs()
|
||||
.getOpt(MediaSessionPlayerUi.class)
|
||||
.flatMap(MediaSessionPlayerUi::getSessionToken)
|
||||
.ifPresent(mediaStyle::setMediaSession);
|
||||
@Nullable final MediaSessionPlayerUi ui = player.UIs().get(MediaSessionPlayerUi.class);
|
||||
if (ui != null) {
|
||||
mediaStyle.setMediaSession(ui.getSessionToken());
|
||||
}
|
||||
|
||||
// setup notification builder
|
||||
builder.setStyle(mediaStyle)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package org.schabi.newpipe.player.ui
|
||||
|
||||
import org.schabi.newpipe.util.GuardedByMutex
|
||||
import java.util.Optional
|
||||
|
||||
/**
|
||||
* Creates a [PlayerUiList] starting with the provided player uis. The provided player uis
|
||||
@@ -99,17 +98,6 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) {
|
||||
return@runWithLockSync null
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUiType the class of the player UI to return;
|
||||
* the [Class.isInstance] method will be used, so even subclasses could be returned
|
||||
* @param T the class type parameter
|
||||
* @return the first player UI of the required type found in the list, or an empty
|
||||
* [Optional] otherwise
|
||||
</T> */
|
||||
@Deprecated("use get", ReplaceWith("get(playerUiType)"))
|
||||
fun <T : PlayerUi> getOpt(playerUiType: Class<T>): Optional<T> =
|
||||
Optional.ofNullable(get(playerUiType))
|
||||
|
||||
/**
|
||||
* Calls the provided consumer on all player UIs in the list, in order of addition.
|
||||
* @param consumer the consumer to call with player UIs
|
||||
|
Reference in New Issue
Block a user