|
1 | 1 | package org.schabi.newpipe.info_list.holder; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
4 | | -import android.net.Uri; |
5 | 4 | import android.os.Bundle; |
6 | 5 | import android.view.View; |
7 | 6 | import android.view.ViewGroup; |
8 | 7 | import android.widget.ImageView; |
9 | 8 | import android.widget.TextView; |
10 | 9 |
|
| 10 | +import androidx.annotation.NonNull; |
11 | 11 | import androidx.appcompat.app.AppCompatActivity; |
12 | 12 | import androidx.core.content.ContextCompat; |
13 | 13 | import androidx.core.view.AccessibilityDelegateCompat; |
|
17 | 17 | import androidx.preference.PreferenceManager; |
18 | 18 |
|
19 | 19 | import org.schabi.newpipe.R; |
20 | | -import org.schabi.newpipe.database.stream.model.StreamEntity; |
21 | 20 | import org.schabi.newpipe.database.stream.model.StreamStateEntity; |
22 | | -import org.schabi.newpipe.download.DownloadDialog; |
23 | | -import org.schabi.newpipe.error.ErrorInfo; |
24 | | -import org.schabi.newpipe.error.ErrorUtil; |
25 | | -import org.schabi.newpipe.error.UserAction; |
26 | 21 | import org.schabi.newpipe.extractor.InfoItem; |
27 | 22 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
28 | 23 | import org.schabi.newpipe.info_list.InfoItemBuilder; |
| 24 | +import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry; |
29 | 25 | import org.schabi.newpipe.ktx.ViewUtils; |
30 | | -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; |
31 | | -import org.schabi.newpipe.local.dialog.PlaylistDialog; |
32 | 26 | import org.schabi.newpipe.local.history.HistoryRecordManager; |
33 | 27 | import org.schabi.newpipe.player.helper.PlayerHolder; |
34 | 28 | import org.schabi.newpipe.util.DependentPreferenceHelper; |
35 | 29 | import org.schabi.newpipe.util.Localization; |
36 | | -import org.schabi.newpipe.util.NavigationHelper; |
37 | | -import org.schabi.newpipe.util.SparseItemUtil; |
38 | 30 | import org.schabi.newpipe.util.StreamTypeUtil; |
39 | 31 | import org.schabi.newpipe.util.external_communication.KoreUtils; |
40 | | -import org.schabi.newpipe.util.external_communication.ShareUtils; |
41 | 32 | import org.schabi.newpipe.util.image.CoilHelper; |
42 | 33 | import org.schabi.newpipe.views.AnimatedProgressBar; |
43 | 34 |
|
44 | | -import java.util.List; |
45 | 35 | import java.util.concurrent.TimeUnit; |
46 | 36 |
|
47 | | -import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; |
48 | | - |
49 | 37 | public class StreamMiniInfoItemHolder extends InfoItemHolder { |
50 | 38 | public final ImageView itemThumbnailView; |
51 | 39 | public final TextView itemVideoTitleView; |
@@ -178,8 +166,9 @@ private void enableLongClick(final StreamInfoItem item) { |
178 | 166 | private void updateAccessibilityActions(final StreamInfoItem item) { |
179 | 167 | ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() { |
180 | 168 | @Override |
181 | | - public void onInitializeAccessibilityNodeInfo(final View host, |
182 | | - final AccessibilityNodeInfoCompat info) { |
| 169 | + public void onInitializeAccessibilityNodeInfo( |
| 170 | + @NonNull final View host, |
| 171 | + @NonNull final AccessibilityNodeInfoCompat info) { |
183 | 172 | super.onInitializeAccessibilityNodeInfo(host, info); |
184 | 173 |
|
185 | 174 | final Context context = itemBuilder.getContext(); |
@@ -256,99 +245,54 @@ public void onInitializeAccessibilityNodeInfo(final View host, |
256 | 245 | } |
257 | 246 |
|
258 | 247 | @Override |
259 | | - public boolean performAccessibilityAction(final View host, final int action, |
| 248 | + public boolean performAccessibilityAction(@NonNull final View host, final int action, |
260 | 249 | final Bundle args) { |
261 | 250 | final Context context = itemBuilder.getContext(); |
| 251 | + final FragmentActivity fActivity = ((FragmentActivity) context); |
| 252 | + |
262 | 253 | if (context == null) { |
263 | 254 | return super.performAccessibilityAction(host, action, args); |
264 | 255 | } |
265 | 256 |
|
266 | 257 | if (action == R.id.accessibility_action_show_options) { |
| 258 | + // display stream dialog |
267 | 259 | if (itemBuilder.getOnStreamSelectedListener() != null) { |
268 | 260 | itemBuilder.getOnStreamSelectedListener().held(item); |
269 | 261 | } |
270 | 262 | return true; |
271 | 263 | } else if (action == R.id.accessibility_action_enqueue) { |
272 | | - SparseItemUtil.fetchItemInfoIfSparse(context, item, |
273 | | - singlePlayQueue -> NavigationHelper.enqueueOnPlayer( |
274 | | - context, singlePlayQueue)); |
| 264 | + StreamDialogDefaultEntry.ENQUEUE.action.onClick(fActivity, item); |
275 | 265 | return true; |
276 | 266 | } else if (action == R.id.accessibility_action_enqueue_next) { |
277 | | - SparseItemUtil.fetchItemInfoIfSparse(context, item, |
278 | | - singlePlayQueue -> NavigationHelper.enqueueNextOnPlayer( |
279 | | - context, singlePlayQueue)); |
| 267 | + StreamDialogDefaultEntry.ENQUEUE_NEXT.action.onClick(fActivity, item); |
280 | 268 | return true; |
281 | 269 | } else if (action == R.id.accessibility_action_background) { |
282 | | - SparseItemUtil.fetchItemInfoIfSparse(context, item, singlePlayQueue -> |
283 | | - NavigationHelper.playOnBackgroundPlayer( |
284 | | - context, singlePlayQueue, true)); |
| 270 | + StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND.action.onClick( |
| 271 | + fActivity, item); |
285 | 272 | return true; |
286 | 273 | } else if (action == R.id.accessibility_action_popup) { |
287 | | - SparseItemUtil.fetchItemInfoIfSparse(context, item, singlePlayQueue -> |
288 | | - NavigationHelper.playOnPopupPlayer( |
289 | | - context, singlePlayQueue, true)); |
| 274 | + StreamDialogDefaultEntry.START_HERE_ON_POPUP.action.onClick(fActivity, item); |
290 | 275 | return true; |
291 | 276 | } else if (action == R.id.accessibility_action_download) { |
292 | | - SparseItemUtil.fetchStreamInfoAndSaveToDatabase(context, |
293 | | - item.getServiceId(), |
294 | | - item.getUrl(), info -> { |
295 | | - final FragmentActivity activity = (FragmentActivity) context; |
296 | | - if (!activity.isFinishing() && !activity.isDestroyed()) { |
297 | | - final DownloadDialog downloadDialog = |
298 | | - new DownloadDialog(context, info); |
299 | | - downloadDialog.show(activity.getSupportFragmentManager(), |
300 | | - "downloadDialog"); |
301 | | - } |
302 | | - }); |
| 277 | + StreamDialogDefaultEntry.DOWNLOAD.action.onClick(fActivity, item); |
303 | 278 | return true; |
304 | 279 | } else if (action == R.id.accessibility_action_playlist) { |
305 | | - final FragmentActivity activity = (FragmentActivity) context; |
306 | | - PlaylistDialog.createCorrespondingDialog( |
307 | | - context, |
308 | | - List.of(new StreamEntity(item)), |
309 | | - dialog -> dialog.show( |
310 | | - activity.getSupportFragmentManager(), |
311 | | - "StreamDialogEntry@" |
312 | | - + (dialog instanceof PlaylistAppendDialog |
313 | | - ? "append" : "create") |
314 | | - + "_playlist" |
315 | | - ) |
316 | | - ); |
| 280 | + StreamDialogDefaultEntry.APPEND_PLAYLIST.action.onClick(fActivity, item); |
317 | 281 | return true; |
318 | 282 | } else if (action == R.id.accessibility_action_share) { |
319 | | - ShareUtils.shareText(context, item.getName(), |
320 | | - item.getUrl(), item.getThumbnails()); |
| 283 | + StreamDialogDefaultEntry.SHARE.action.onClick(fActivity, item); |
321 | 284 | return true; |
322 | 285 | } else if (action == R.id.accessibility_action_browser) { |
323 | | - ShareUtils.openUrlInBrowser(context, item.getUrl()); |
| 286 | + StreamDialogDefaultEntry.OPEN_IN_BROWSER.action.onClick(fActivity, item); |
324 | 287 | return true; |
325 | 288 | } else if (action == R.id.accessibility_action_kodi) { |
326 | | - KoreUtils.playWithKore(context, Uri.parse(item.getUrl())); |
| 289 | + StreamDialogDefaultEntry.PLAY_WITH_KODI.action.onClick(fActivity, item); |
327 | 290 | return true; |
328 | 291 | } else if (action == R.id.accessibility_action_mark_watched) { |
329 | | - new HistoryRecordManager(context) |
330 | | - .markAsWatched(item) |
331 | | - .doOnError(error -> { |
332 | | - ErrorUtil.showSnackbar( |
333 | | - context, |
334 | | - new ErrorInfo( |
335 | | - error, |
336 | | - UserAction.OPEN_INFO_ITEM_DIALOG, |
337 | | - "Got an error when trying to mark as watched" |
338 | | - ) |
339 | | - ); |
340 | | - }) |
341 | | - .onErrorComplete() |
342 | | - .observeOn(AndroidSchedulers.mainThread()) |
343 | | - .subscribe(); |
| 292 | + StreamDialogDefaultEntry.MARK_AS_WATCHED.action.onClick(fActivity, item); |
344 | 293 | return true; |
345 | 294 | } else if (action == R.id.accessibility_action_channel_details) { |
346 | | - SparseItemUtil.fetchUploaderUrlIfSparse((AppCompatActivity) context, |
347 | | - item.getServiceId(), item.getUrl(), |
348 | | - item.getUploaderUrl(), |
349 | | - url -> NavigationHelper.openChannelFragment( |
350 | | - ((AppCompatActivity) context).getSupportFragmentManager(), |
351 | | - item.getServiceId(), url, item.getUploaderName())); |
| 295 | + StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS.action.onClick(fActivity, item); |
352 | 296 | return true; |
353 | 297 | } |
354 | 298 |
|
|
0 commit comments