99import android .content .Intent ;
1010import android .net .Uri ;
1111import android .os .Build ;
12- import android .os .Parcelable ;
1312import android .util .Log ;
1413import android .widget .Toast ;
1514
7069import org .schabi .newpipe .util .external_communication .ShareUtils ;
7170
7271import java .util .List ;
72+ import java .util .Optional ;
7373
7474public final class NavigationHelper {
7575 public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag" ;
@@ -89,31 +89,22 @@ public static <T> Intent getPlayerIntent(@NonNull final Context context,
8989 @ NonNull final Class <T > targetClazz ,
9090 @ Nullable final PlayQueue playQueue ,
9191 @ NonNull final PlayerIntentType playerIntentType ) {
92- final Intent intent = new Intent (context , targetClazz );
93-
94- if (playQueue != null ) {
95- final String cacheKey = SerializedCache .getInstance ().put (playQueue , PlayQueue .class );
96- if (cacheKey != null ) {
97- intent .putExtra (Player .PLAY_QUEUE_KEY , cacheKey );
98- }
99- }
100- intent .putExtra (Player .PLAYER_TYPE , PlayerType .MAIN .valueForIntent ());
101- intent .putExtra (PlayerService .SHOULD_START_FOREGROUND_EXTRA , true );
102- intent .putExtra (Player .PLAYER_INTENT_TYPE , (Parcelable ) playerIntentType );
103-
104- return intent ;
92+ final String cacheKey = Optional .ofNullable (playQueue )
93+ .map (queue -> SerializedCache .getInstance ().put (queue , PlayQueue .class ))
94+ .orElse (null );
95+ return new Intent (context , targetClazz )
96+ .putExtra (Player .PLAY_QUEUE_KEY , cacheKey )
97+ .putExtra (Player .PLAYER_TYPE , PlayerType .MAIN )
98+ .putExtra (PlayerService .SHOULD_START_FOREGROUND_EXTRA , true )
99+ .putExtra (Player .PLAYER_INTENT_TYPE , playerIntentType );
105100 }
106101
107102 @ NonNull
108103 public static Intent getPlayerTimestampIntent (@ NonNull final Context context ,
109- @ NonNull final TimestampChangeData
110- timestampChangeData ) {
111- final Intent intent = new Intent (context , PlayerService .class );
112-
113- intent .putExtra (Player .PLAYER_INTENT_TYPE , (Parcelable ) PlayerIntentType .TimestampChange );
114- intent .putExtra (Player .PLAYER_INTENT_DATA , timestampChangeData );
115-
116- return intent ;
104+ @ NonNull final TimestampChangeData data ) {
105+ return new Intent (context , PlayerService .class )
106+ .putExtra (Player .PLAYER_INTENT_TYPE , PlayerIntentType .TimestampChange )
107+ .putExtra (Player .PLAYER_INTENT_DATA , data );
117108 }
118109
119110 @ NonNull
@@ -156,9 +147,9 @@ public static void playOnPopupPlayer(final Context context,
156147
157148 Toast .makeText (context , R .string .popup_playing_toast , Toast .LENGTH_SHORT ).show ();
158149
159- final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
160- PlayerIntentType .AllOthers );
161- intent .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP . valueForIntent () )
150+ final var intent = getPlayerIntent (context , PlayerService .class , queue ,
151+ PlayerIntentType .AllOthers )
152+ .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP )
162153 .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
163154 ContextCompat .startForegroundService (context , intent );
164155 }
@@ -170,9 +161,9 @@ public static void playOnBackgroundPlayer(final Context context,
170161 .show ();
171162
172163 final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
173- PlayerIntentType .AllOthers );
174- intent .putExtra (Player .PLAYER_TYPE , PlayerType .AUDIO . valueForIntent ());
175- intent .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
164+ PlayerIntentType .AllOthers )
165+ .putExtra (Player .PLAYER_TYPE , PlayerType .AUDIO )
166+ .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
176167 ContextCompat .startForegroundService (context , intent );
177168 }
178169
@@ -195,9 +186,8 @@ public static void enqueueOnPlayer(final Context context,
195186 // by long pressing the video detail fragment, playlist or channel controls
196187 final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
197188 PlayerIntentType .Enqueue )
198- .putExtra (Player .RESUME_PLAYBACK , false );
199-
200- intent .putExtra (Player .PLAYER_TYPE , playerType .valueForIntent ());
189+ .putExtra (Player .RESUME_PLAYBACK , false )
190+ .putExtra (Player .PLAYER_TYPE , playerType );
201191 ContextCompat .startForegroundService (context , intent );
202192 }
203193
@@ -219,9 +209,8 @@ public static void enqueueNextOnPlayer(final Context context, final PlayQueue qu
219209 playerType = PlayerType .AUDIO ;
220210 }
221211 Toast .makeText (context , R .string .enqueued_next , Toast .LENGTH_SHORT ).show ();
222- final Intent intent = getPlayerEnqueueNextIntent (context , PlayerService .class , queue );
223-
224- intent .putExtra (Player .PLAYER_TYPE , playerType .valueForIntent ());
212+ final Intent intent = getPlayerEnqueueNextIntent (context , PlayerService .class , queue )
213+ .putExtra (Player .PLAYER_TYPE , playerType );
225214 ContextCompat .startForegroundService (context , intent );
226215 }
227216
0 commit comments