99
1010import androidx .annotation .NonNull ;
1111import androidx .annotation .StringRes ;
12+ import androidx .fragment .app .FragmentManager ;
1213
1314import org .schabi .newpipe .R ;
1415import org .schabi .newpipe .database .stream .model .StreamEntity ;
4445 * </p>
4546 */
4647public enum StreamDialogDefaultEntry {
47- SHOW_CHANNEL_DETAILS (R .string .show_channel_details , (fragment , item ) -> {
48- final var activity = fragment .requireActivity ();
49- fetchUploaderUrlIfSparse (activity , item .getServiceId (), item .getUrl (),
50- item .getUploaderUrl (), url -> openChannelFragment (activity , item , url ));
51- }),
48+ SHOW_CHANNEL_DETAILS (R .string .show_channel_details , (fragmentActivity , item ) ->
49+ fetchUploaderUrlIfSparse (fragmentActivity , item .getServiceId (), item .getUrl (),
50+ item .getUploaderUrl (), url -> openChannelFragment (fragmentActivity , item , url ))
51+ ),
5252
5353 /**
5454 * Enqueues the stream automatically to the current PlayerType.
5555 */
56- ENQUEUE (R .string .enqueue_stream , (fragment , item ) ->
57- fetchItemInfoIfSparse (fragment . requireContext () , item , singlePlayQueue ->
58- NavigationHelper .enqueueOnPlayer (fragment . getContext () , singlePlayQueue ))
56+ ENQUEUE (R .string .enqueue_stream , (fragmentActivity , item ) ->
57+ fetchItemInfoIfSparse (fragmentActivity , item , singlePlayQueue ->
58+ NavigationHelper .enqueueOnPlayer (fragmentActivity , singlePlayQueue ))
5959 ),
6060
6161 /**
6262 * Enqueues the stream automatically to the current PlayerType
6363 * after the currently playing stream.
6464 */
65- ENQUEUE_NEXT (R .string .enqueue_next_stream , (fragment , item ) ->
66- fetchItemInfoIfSparse (fragment . requireContext () , item , singlePlayQueue ->
67- NavigationHelper .enqueueNextOnPlayer (fragment . getContext () , singlePlayQueue ))
65+ ENQUEUE_NEXT (R .string .enqueue_next_stream , (fragmentActivity , item ) ->
66+ fetchItemInfoIfSparse (fragmentActivity , item , singlePlayQueue ->
67+ NavigationHelper .enqueueNextOnPlayer (fragmentActivity , singlePlayQueue ))
6868 ),
6969
70- START_HERE_ON_BACKGROUND (R .string .start_here_on_background , (fragment , item ) ->
71- fetchItemInfoIfSparse (fragment . requireContext () , item , singlePlayQueue ->
70+ START_HERE_ON_BACKGROUND (R .string .start_here_on_background , (fragmentActivity , item ) ->
71+ fetchItemInfoIfSparse (fragmentActivity , item , singlePlayQueue ->
7272 NavigationHelper .playOnBackgroundPlayer (
73- fragment . getContext () , singlePlayQueue , true ))),
73+ fragmentActivity , singlePlayQueue , true ))),
7474
75- START_HERE_ON_POPUP (R .string .start_here_on_popup , (fragment , item ) ->
76- fetchItemInfoIfSparse (fragment . requireContext () , item , singlePlayQueue ->
77- NavigationHelper .playOnPopupPlayer (fragment . getContext () , singlePlayQueue , true ))),
75+ START_HERE_ON_POPUP (R .string .start_here_on_popup , (fragmentActivity , item ) ->
76+ fetchItemInfoIfSparse (fragmentActivity , item , singlePlayQueue ->
77+ NavigationHelper .playOnPopupPlayer (fragmentActivity , singlePlayQueue , true ))),
7878
79- SET_AS_PLAYLIST_THUMBNAIL (R .string .set_as_playlist_thumbnail , (fragment , item ) -> {
79+ SET_AS_PLAYLIST_THUMBNAIL (R .string .set_as_playlist_thumbnail , (fragmentActivity , item ) -> {
8080 throw new UnsupportedOperationException ("This needs to be implemented manually "
8181 + "by using InfoItemDialog.Builder.setAction()" );
8282 }),
8383
84- DELETE (R .string .delete , (fragment , item ) -> {
84+ DELETE (R .string .delete , (fragmentActivity , item ) -> {
8585 throw new UnsupportedOperationException ("This needs to be implemented manually "
8686 + "by using InfoItemDialog.Builder.setAction()" );
8787 }),
@@ -90,62 +90,63 @@ public enum StreamDialogDefaultEntry {
9090 * Opens a {@link PlaylistDialog} to either append the stream to a playlist
9191 * or create a new playlist if there are no local playlists.
9292 */
93- APPEND_PLAYLIST (R .string .add_to_playlist , (fragment , item ) ->
93+ APPEND_PLAYLIST (R .string .add_to_playlist , (fragmentActivity , item ) ->
9494 PlaylistDialog .createCorrespondingDialog (
95- fragment . getContext () ,
95+ fragmentActivity ,
9696 List .of (new StreamEntity (item )),
9797 dialog -> dialog .show (
98- fragment . getParentFragmentManager (),
98+ fragmentActivity . getSupportFragmentManager (),
9999 "StreamDialogEntry@"
100100 + (dialog instanceof PlaylistAppendDialog ? "append" : "create" )
101101 + "_playlist"
102102 )
103103 )
104104 ),
105105
106- PLAY_WITH_KODI (R .string .play_with_kodi_title , (fragment , item ) ->
107- KoreUtils .playWithKore (fragment . requireContext () , Uri .parse (item .getUrl ()))),
106+ PLAY_WITH_KODI (R .string .play_with_kodi_title , (fragmentActivity , item ) ->
107+ KoreUtils .playWithKore (fragmentActivity , Uri .parse (item .getUrl ()))),
108108
109- SHARE (R .string .share , (fragment , item ) ->
110- ShareUtils .shareText (fragment . requireContext () , item .getName (), item .getUrl (),
109+ SHARE (R .string .share , (fragmentActivity , item ) ->
110+ ShareUtils .shareText (fragmentActivity , item .getName (), item .getUrl (),
111111 item .getThumbnails ())),
112112
113113 /**
114114 * Opens a {@link DownloadDialog} after fetching some stream info.
115- * If the user quits the current fragment , it will not open a DownloadDialog.
115+ * If the user quits the current fragmentActivity , it will not open a DownloadDialog.
116116 */
117- DOWNLOAD (R .string .download , (fragment , item ) ->
118- fetchStreamInfoAndSaveToDatabase (fragment . requireContext () , item .getServiceId (),
117+ DOWNLOAD (R .string .download , (fragmentActivity , item ) ->
118+ fetchStreamInfoAndSaveToDatabase (fragmentActivity , item .getServiceId (),
119119 item .getUrl (), info -> {
120- // Ensure the fragment is attached and its state hasn't been saved to avoid
120+ // Ensure the fragment in the activity is attached
121+ // and its state hasn't been saved to avoid
121122 // showing dialog during lifecycle changes or when the activity is paused,
122123 // e.g. by selecting the download option and opening a different fragment.
123- if (fragment .isAdded () && !fragment .isStateSaved ()) {
124+ final FragmentManager fm = fragmentActivity .getSupportFragmentManager ();
125+ if (!fm .isStateSaved ()) {
124126 final DownloadDialog downloadDialog =
125- new DownloadDialog (fragment .requireContext (), info );
126- downloadDialog .show (fragment .getChildFragmentManager (),
127- "downloadDialog" );
127+ new DownloadDialog (fragmentActivity , info );
128+ downloadDialog .show (fm , "downloadDialog" );
128129 }
129130 })
130131 ),
131132
132- OPEN_IN_BROWSER (R .string .open_in_browser , (fragment , item ) ->
133- ShareUtils .openUrlInBrowser (fragment . requireContext () , item .getUrl ())),
133+ OPEN_IN_BROWSER (R .string .open_in_browser , (fragmentActivity , item ) ->
134+ ShareUtils .openUrlInBrowser (fragmentActivity , item .getUrl ())),
134135
135136
136- MARK_AS_WATCHED (R .string .mark_as_watched , (fragment , item ) ->
137- new HistoryRecordManager (fragment . getContext () )
137+ MARK_AS_WATCHED (R .string .mark_as_watched , (fragmentActivity , item ) ->
138+ new HistoryRecordManager (fragmentActivity )
138139 .markAsWatched (item )
139- .doOnError (error -> {
140+ .doOnError (error ->
140141 ErrorUtil .showSnackbar (
141- fragment . requireContext () ,
142+ fragmentActivity ,
142143 new ErrorInfo (
143144 error ,
144145 UserAction .OPEN_INFO_ITEM_DIALOG ,
145146 "Got an error when trying to mark as watched"
146147 )
147- );
148- } )
148+ )
149+ )
149150 .onErrorComplete ()
150151 .observeOn (AndroidSchedulers .mainThread ())
151152 .subscribe ()
0 commit comments