File tree Expand file tree Collapse file tree
app/src/main/java/org/schabi/newpipe/player Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -477,22 +477,23 @@ public void handleIntent(@NonNull final Intent intent) {
477477 }
478478
479479 private void initUIsForCurrentPlayerType () {
480- if ((UIs .getOpt (MainPlayerUi .class ). isPresent () && playerType == PlayerType .MAIN )
481- || (UIs .getOpt (PopupPlayerUi .class ). isPresent ()
480+ if ((UIs .get (MainPlayerUi .class ) != null && playerType == PlayerType .MAIN )
481+ || (UIs .get (PopupPlayerUi .class ) != null
482482 && playerType == PlayerType .POPUP )) {
483483 // correct UI already in place
484484 return ;
485485 }
486486
487487 // try to reuse binding if possible
488- final PlayerBinding binding = UIs .getOpt (VideoPlayerUi .class ).map (VideoPlayerUi ::getBinding )
489- .orElseGet (() -> {
490- if (playerType == PlayerType .AUDIO ) {
491- return null ;
492- } else {
493- return PlayerBinding .inflate (LayoutInflater .from (context ));
494- }
495- });
488+ @ Nullable final VideoPlayerUi ui = UIs .get (VideoPlayerUi .class );
489+ final PlayerBinding binding ;
490+ if (ui != null ) {
491+ binding = ui .getBinding ();
492+ } else if (playerType == PlayerType .AUDIO ) {
493+ binding = null ;
494+ } else {
495+ binding = PlayerBinding .inflate (LayoutInflater .from (context ));
496+ }
496497
497498 switch (playerType ) {
498499 case MAIN :
Original file line number Diff line number Diff line change @@ -124,8 +124,10 @@ public void handleMediaButtonIntent(final Intent intent) {
124124 MediaButtonReceiver .handleIntent (mediaSession , intent );
125125 }
126126
127- public Optional <MediaSessionCompat .Token > getSessionToken () {
128- return Optional .ofNullable (mediaSession ).map (MediaSessionCompat ::getSessionToken );
127+
128+ @ NonNull
129+ public MediaSessionCompat .Token getSessionToken () {
130+ return mediaSession .getSessionToken ();
129131 }
130132
131133
@@ -138,7 +140,10 @@ private ForwardingPlayer getForwardingPlayer() {
138140 public void play () {
139141 player .play ();
140142 // hide the player controls even if the play command came from the media session
141- player .UIs ().getOpt (VideoPlayerUi .class ).ifPresent (ui -> ui .hideControls (0 , 0 ));
143+ final VideoPlayerUi ui = player .UIs ().get (VideoPlayerUi .class );
144+ if (ui != null ) {
145+ ui .hideControls (0 , 0 );
146+ }
142147 }
143148
144149 @ Override
Original file line number Diff line number Diff line change @@ -101,10 +101,10 @@ private synchronized NotificationCompat.Builder createNotification() {
101101 final int [] compactSlots = initializeNotificationSlots ();
102102 mediaStyle .setShowActionsInCompactView (compactSlots );
103103 }
104- player .UIs ()
105- . getOpt ( MediaSessionPlayerUi . class )
106- . flatMap ( MediaSessionPlayerUi :: getSessionToken )
107- . ifPresent ( mediaStyle :: setMediaSession );
104+ @ Nullable final MediaSessionPlayerUi ui = player .UIs (). get ( MediaSessionPlayerUi . class );
105+ if ( ui != null ) {
106+ mediaStyle . setMediaSession ( ui . getSessionToken ());
107+ }
108108
109109 // setup notification builder
110110 builder .setStyle (mediaStyle )
Original file line number Diff line number Diff line change 11package org.schabi.newpipe.player.ui
22
33import org.schabi.newpipe.util.GuardedByMutex
4- import java.util.Optional
54
65/* *
76 * Creates a [PlayerUiList] starting with the provided player uis. The provided player uis
@@ -99,17 +98,6 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) {
9998 return @runWithLockSync null
10099 }
101100
102- /* *
103- * @param playerUiType the class of the player UI to return;
104- * the [Class.isInstance] method will be used, so even subclasses could be returned
105- * @param T the class type parameter
106- * @return the first player UI of the required type found in the list, or an empty
107- * [Optional] otherwise
108- </T> */
109- @Deprecated(" use get" , ReplaceWith (" get(playerUiType)" ))
110- fun <T : PlayerUi > getOpt (playerUiType : Class <T >): Optional <T > =
111- Optional .ofNullable(get(playerUiType))
112-
113101 /* *
114102 * Calls the provided consumer on all player UIs in the list, in order of addition.
115103 * @param consumer the consumer to call with player UIs
You can’t perform that action at this time.
0 commit comments