5858import org .schabi .newpipe .local .subscription .SubscriptionsImportFragment ;
5959import org .schabi .newpipe .player .PlayQueueActivity ;
6060import org .schabi .newpipe .player .Player ;
61+ import org .schabi .newpipe .player .PlayerIntentType ;
6162import org .schabi .newpipe .player .PlayerService ;
6263import org .schabi .newpipe .player .PlayerType ;
64+ import org .schabi .newpipe .player .TimestampChangeData ;
6365import org .schabi .newpipe .player .helper .PlayerHelper ;
6466import org .schabi .newpipe .player .helper .PlayerHolder ;
6567import org .schabi .newpipe .player .playqueue .PlayQueue ;
6971import org .schabi .newpipe .util .external_communication .ShareUtils ;
7072
7173import java .util .List ;
74+ import java .util .Optional ;
7275
7376public final class NavigationHelper {
7477 public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag" ;
@@ -87,54 +90,32 @@ private NavigationHelper() {
8790 public static <T > Intent getPlayerIntent (@ NonNull final Context context ,
8891 @ NonNull final Class <T > targetClazz ,
8992 @ Nullable final PlayQueue playQueue ,
90- final boolean resumePlayback ) {
91- final Intent intent = new Intent (context , targetClazz );
92-
93- if (playQueue != null ) {
94- final String cacheKey = SerializedCache .getInstance ().put (playQueue , PlayQueue .class );
95- if (cacheKey != null ) {
96- intent .putExtra (Player .PLAY_QUEUE_KEY , cacheKey );
97- }
98- }
99- intent .putExtra (Player .PLAYER_TYPE , PlayerType .MAIN .valueForIntent ());
100- intent .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
101- intent .putExtra (PlayerService .SHOULD_START_FOREGROUND_EXTRA , true );
102-
103- return intent ;
104- }
105-
106- @ NonNull
107- public static <T > Intent getPlayerIntent (@ NonNull final Context context ,
108- @ NonNull final Class <T > targetClazz ,
109- @ Nullable final PlayQueue playQueue ,
110- final boolean resumePlayback ,
111- final boolean playWhenReady ) {
112- return getPlayerIntent (context , targetClazz , playQueue , resumePlayback )
113- .putExtra (Player .PLAY_WHEN_READY , playWhenReady );
93+ @ NonNull final PlayerIntentType playerIntentType ) {
94+ final String cacheKey = Optional .ofNullable (playQueue )
95+ .map (queue -> SerializedCache .getInstance ().put (queue , PlayQueue .class ))
96+ .orElse (null );
97+ return new Intent (context , targetClazz )
98+ .putExtra (Player .PLAY_QUEUE_KEY , cacheKey )
99+ .putExtra (Player .PLAYER_TYPE , PlayerType .MAIN )
100+ .putExtra (PlayerService .SHOULD_START_FOREGROUND_EXTRA , true )
101+ .putExtra (Player .PLAYER_INTENT_TYPE , playerIntentType );
114102 }
115103
116104 @ NonNull
117- public static <T > Intent getPlayerEnqueueIntent (@ NonNull final Context context ,
118- @ NonNull final Class <T > targetClazz ,
119- @ Nullable final PlayQueue playQueue ) {
120- // when enqueueing `resumePlayback` is always `false` since:
121- // - if there is a video already playing, the value of `resumePlayback` just doesn't make
122- // any difference.
123- // - if there is nothing already playing, it is useful for the enqueue action to have a
124- // slightly different behaviour than the normal play action: the latter resumes playback,
125- // the former doesn't. (note that enqueue can be triggered when nothing is playing only
126- // by long pressing the video detail fragment, playlist or channel controls
127- return getPlayerIntent (context , targetClazz , playQueue , false )
128- .putExtra (Player .ENQUEUE , true );
105+ public static Intent getPlayerTimestampIntent (@ NonNull final Context context ,
106+ @ NonNull final TimestampChangeData data ) {
107+ return new Intent (context , PlayerService .class )
108+ .putExtra (Player .PLAYER_INTENT_TYPE , PlayerIntentType .TimestampChange )
109+ .putExtra (Player .PLAYER_INTENT_DATA , data );
129110 }
130111
131112 @ NonNull
132113 public static <T > Intent getPlayerEnqueueNextIntent (@ NonNull final Context context ,
133114 @ NonNull final Class <T > targetClazz ,
134115 @ Nullable final PlayQueue playQueue ) {
135- // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
136- return getPlayerIntent ( context , targetClazz , playQueue , false )
137- .putExtra (Player .ENQUEUE_NEXT , true );
116+ return getPlayerIntent ( context , targetClazz , playQueue , PlayerIntentType . EnqueueNext )
117+ // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
118+ .putExtra (Player .RESUME_PLAYBACK , false );
138119 }
139120
140121 /* PLAY */
@@ -168,8 +149,10 @@ public static void playOnPopupPlayer(final Context context,
168149
169150 Toast .makeText (context , R .string .popup_playing_toast , Toast .LENGTH_SHORT ).show ();
170151
171- final Intent intent = getPlayerIntent (context , PlayerService .class , queue , resumePlayback );
172- intent .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP .valueForIntent ());
152+ final var intent = getPlayerIntent (context , PlayerService .class , queue ,
153+ PlayerIntentType .AllOthers )
154+ .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP )
155+ .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
173156 ContextCompat .startForegroundService (context , intent );
174157 }
175158
@@ -179,8 +162,10 @@ public static void playOnBackgroundPlayer(final Context context,
179162 Toast .makeText (context , R .string .background_player_playing_toast , Toast .LENGTH_SHORT )
180163 .show ();
181164
182- final Intent intent = getPlayerIntent (context , PlayerService .class , queue , resumePlayback );
183- intent .putExtra (Player .PLAYER_TYPE , PlayerType .AUDIO .valueForIntent ());
165+ final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
166+ PlayerIntentType .AllOthers )
167+ .putExtra (Player .PLAYER_TYPE , PlayerType .AUDIO )
168+ .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
184169 ContextCompat .startForegroundService (context , intent );
185170 }
186171
@@ -193,9 +178,18 @@ public static void enqueueOnPlayer(final Context context,
193178 }
194179
195180 Toast .makeText (context , R .string .enqueued , Toast .LENGTH_SHORT ).show ();
196- final Intent intent = getPlayerEnqueueIntent (context , PlayerService .class , queue );
197181
198- intent .putExtra (Player .PLAYER_TYPE , playerType .valueForIntent ());
182+ // when enqueueing `resumePlayback` is always `false` since:
183+ // - if there is a video already playing, the value of `resumePlayback` just doesn't make
184+ // any difference.
185+ // - if there is nothing already playing, it is useful for the enqueue action to have a
186+ // slightly different behaviour than the normal play action: the latter resumes playback,
187+ // the former doesn't. (note that enqueue can be triggered when nothing is playing only
188+ // by long pressing the video detail fragment, playlist or channel controls
189+ final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
190+ PlayerIntentType .Enqueue )
191+ .putExtra (Player .RESUME_PLAYBACK , false )
192+ .putExtra (Player .PLAYER_TYPE , playerType );
199193 ContextCompat .startForegroundService (context , intent );
200194 }
201195
@@ -217,9 +211,8 @@ public static void enqueueNextOnPlayer(final Context context, final PlayQueue qu
217211 playerType = PlayerType .AUDIO ;
218212 }
219213 Toast .makeText (context , R .string .enqueued_next , Toast .LENGTH_SHORT ).show ();
220- final Intent intent = getPlayerEnqueueNextIntent (context , PlayerService .class , queue );
221-
222- intent .putExtra (Player .PLAYER_TYPE , playerType .valueForIntent ());
214+ final Intent intent = getPlayerEnqueueNextIntent (context , PlayerService .class , queue )
215+ .putExtra (Player .PLAYER_TYPE , playerType );
223216 ContextCompat .startForegroundService (context , intent );
224217 }
225218
0 commit comments