|
1 | 1 | package org.schabi.newpipe.fragments.list.playlist; |
2 | 2 |
|
3 | | -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; |
4 | 3 | import static org.schabi.newpipe.ktx.ViewUtils.animate; |
5 | 4 | import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling; |
6 | 5 |
|
7 | | -import android.app.Activity; |
8 | 6 | import android.content.Context; |
9 | 7 | import android.content.res.ColorStateList; |
10 | 8 | import android.os.Bundle; |
|
41 | 39 | import org.schabi.newpipe.extractor.playlist.PlaylistInfo; |
42 | 40 | import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; |
43 | 41 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
44 | | -import org.schabi.newpipe.extractor.stream.StreamType; |
45 | 42 | import org.schabi.newpipe.fragments.list.BaseListInfoFragment; |
46 | | -import org.schabi.newpipe.info_list.InfoItemDialog; |
| 43 | +import org.schabi.newpipe.info_list.dialog.InfoItemDialog; |
47 | 44 | import org.schabi.newpipe.local.playlist.RemotePlaylistManager; |
48 | 45 | import org.schabi.newpipe.player.MainPlayer.PlayerType; |
49 | | -import org.schabi.newpipe.player.helper.PlayerHolder; |
50 | 46 | import org.schabi.newpipe.player.playqueue.PlayQueue; |
51 | 47 | import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; |
52 | 48 | import org.schabi.newpipe.util.ExtractorHelper; |
53 | 49 | import org.schabi.newpipe.util.Localization; |
54 | 50 | import org.schabi.newpipe.util.NavigationHelper; |
55 | 51 | import org.schabi.newpipe.util.PicassoHelper; |
56 | | -import org.schabi.newpipe.util.StreamDialogEntry; |
57 | | -import org.schabi.newpipe.util.external_communication.KoreUtils; |
| 52 | +import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry; |
58 | 53 | import org.schabi.newpipe.util.external_communication.ShareUtils; |
59 | 54 |
|
60 | 55 | import java.util.ArrayList; |
61 | | -import java.util.Arrays; |
62 | 56 | import java.util.List; |
63 | 57 | import java.util.concurrent.atomic.AtomicBoolean; |
64 | 58 | import java.util.function.Supplier; |
@@ -145,60 +139,22 @@ private PlayQueue getPlayQueueStartingAt(final StreamInfoItem infoItem) { |
145 | 139 | } |
146 | 140 |
|
147 | 141 | @Override |
148 | | - protected void showStreamDialog(final StreamInfoItem item) { |
| 142 | + protected void showInfoItemDialog(final StreamInfoItem item) { |
149 | 143 | final Context context = getContext(); |
150 | | - final Activity activity = getActivity(); |
151 | | - if (context == null || context.getResources() == null || activity == null) { |
152 | | - return; |
153 | | - } |
154 | | - |
155 | | - final ArrayList<StreamDialogEntry> entries = new ArrayList<>(); |
156 | | - |
157 | | - if (PlayerHolder.getInstance().isPlayQueueReady()) { |
158 | | - entries.add(StreamDialogEntry.enqueue); |
159 | | - |
160 | | - if (PlayerHolder.getInstance().getQueueSize() > 1) { |
161 | | - entries.add(StreamDialogEntry.enqueue_next); |
162 | | - } |
163 | | - } |
164 | | - |
165 | | - if (item.getStreamType() == StreamType.AUDIO_STREAM) { |
166 | | - entries.addAll(Arrays.asList( |
167 | | - StreamDialogEntry.start_here_on_background, |
168 | | - StreamDialogEntry.append_playlist, |
169 | | - StreamDialogEntry.share |
170 | | - )); |
171 | | - } else { |
172 | | - entries.addAll(Arrays.asList( |
173 | | - StreamDialogEntry.start_here_on_background, |
174 | | - StreamDialogEntry.start_here_on_popup, |
175 | | - StreamDialogEntry.append_playlist, |
176 | | - StreamDialogEntry.share |
177 | | - )); |
| 144 | + try { |
| 145 | + final InfoItemDialog.Builder dialogBuilder = |
| 146 | + new InfoItemDialog.Builder(getActivity(), context, this, item); |
| 147 | + |
| 148 | + dialogBuilder |
| 149 | + .setAction( |
| 150 | + StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, |
| 151 | + (f, infoItem) -> NavigationHelper.playOnBackgroundPlayer( |
| 152 | + context, getPlayQueueStartingAt(infoItem), true)) |
| 153 | + .create() |
| 154 | + .show(); |
| 155 | + } catch (final IllegalArgumentException e) { |
| 156 | + InfoItemDialog.Builder.reportErrorDuringInitialization(e, item); |
178 | 157 | } |
179 | | - entries.add(StreamDialogEntry.open_in_browser); |
180 | | - if (KoreUtils.shouldShowPlayWithKodi(context, item.getServiceId())) { |
181 | | - entries.add(StreamDialogEntry.play_with_kodi); |
182 | | - } |
183 | | - |
184 | | - // show "mark as watched" only when watch history is enabled |
185 | | - if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) { |
186 | | - entries.add( |
187 | | - StreamDialogEntry.mark_as_watched |
188 | | - ); |
189 | | - } |
190 | | - if (!isNullOrEmpty(item.getUploaderUrl())) { |
191 | | - entries.add(StreamDialogEntry.show_channel_details); |
192 | | - } |
193 | | - |
194 | | - StreamDialogEntry.setEnabledEntries(entries); |
195 | | - |
196 | | - StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItem) -> |
197 | | - NavigationHelper.playOnBackgroundPlayer(context, |
198 | | - getPlayQueueStartingAt(infoItem), true)); |
199 | | - |
200 | | - new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), |
201 | | - (dialog, which) -> StreamDialogEntry.clickOn(which, this, item)).show(); |
202 | 158 | } |
203 | 159 |
|
204 | 160 | @Override |
|
0 commit comments