2019-07-25 00:44:12 +02:00
|
|
|
package org.schabi.newpipe.util;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2020-12-30 03:17:36 +01:00
|
|
|
import android.net.Uri;
|
2021-09-01 01:55:56 +02:00
|
|
|
import android.util.Log;
|
2021-08-14 03:07:27 +02:00
|
|
|
import android.widget.Toast;
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2021-08-13 11:35:25 +02:00
|
|
|
import org.schabi.newpipe.NewPipeDatabase;
|
2019-07-25 00:44:12 +02:00
|
|
|
import org.schabi.newpipe.R;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
2020-09-29 00:32:24 +02:00
|
|
|
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
2021-07-27 04:51:41 +02:00
|
|
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
2019-07-25 00:44:12 +02:00
|
|
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
2021-03-26 13:28:11 +01:00
|
|
|
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
|
|
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
import java.util.Collections;
|
2020-10-06 17:22:12 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-07-27 04:51:41 +02:00
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
2021-09-01 01:55:56 +02:00
|
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
2021-08-13 11:35:25 +02:00
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
2021-07-27 04:51:41 +02:00
|
|
|
|
2021-08-13 11:35:25 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
public enum StreamDialogEntry {
|
2019-07-25 00:53:13 +02:00
|
|
|
//////////////////////////////////////
|
|
|
|
// enum values with DEFAULT actions //
|
|
|
|
//////////////////////////////////////
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2021-08-13 11:35:25 +02:00
|
|
|
show_channel_details(R.string.show_channel_details, (fragment, item) -> {
|
|
|
|
if (isNullOrEmpty(item.getUploaderUrl())) {
|
|
|
|
final int serviceId = item.getServiceId();
|
|
|
|
final String url = item.getUrl();
|
2021-08-21 03:30:40 +02:00
|
|
|
Toast.makeText(fragment.getContext(), R.string.loading_channel_details,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
2021-08-14 03:07:27 +02:00
|
|
|
ExtractorHelper.getStreamInfo(serviceId, url, false)
|
2021-08-13 11:35:25 +02:00
|
|
|
.subscribeOn(Schedulers.io())
|
2021-08-14 03:07:27 +02:00
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe(result -> {
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
NewPipeDatabase.getInstance(fragment.requireContext()).streamDAO()
|
2021-08-14 03:07:27 +02:00
|
|
|
.setUploaderUrl(serviceId, url, result.getUploaderUrl())
|
|
|
|
.subscribeOn(Schedulers.io()).subscribe();
|
2021-08-14 11:32:38 +02:00
|
|
|
openChannelFragment(fragment, item, result.getUploaderUrl());
|
2021-08-24 15:17:08 +02:00
|
|
|
}, throwable -> Toast.makeText(
|
|
|
|
// TODO: Open the Error Activity
|
2021-08-14 03:07:27 +02:00
|
|
|
fragment.getContext(),
|
2021-08-14 09:38:57 +02:00
|
|
|
R.string.error_show_channel_details,
|
2021-08-14 03:07:27 +02:00
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
).show());
|
2021-08-13 11:35:25 +02:00
|
|
|
} else {
|
2021-08-14 11:32:38 +02:00
|
|
|
openChannelFragment(fragment, item, item.getUploaderUrl());
|
2021-08-13 11:35:25 +02:00
|
|
|
}
|
|
|
|
}),
|
2021-03-28 18:32:40 +02:00
|
|
|
|
2020-10-06 13:33:44 +02:00
|
|
|
/**
|
|
|
|
* Enqueues the stream automatically to the current PlayerType.<br>
|
|
|
|
* <br>
|
|
|
|
* Info: Add this entry within showStreamDialog.
|
|
|
|
*/
|
2020-10-06 17:22:12 +02:00
|
|
|
enqueue(R.string.enqueue_stream, (fragment, item) -> {
|
2021-10-28 02:11:53 +02:00
|
|
|
fetchItemInfoIfSparse(fragment, item,
|
2021-09-01 01:55:56 +02:00
|
|
|
fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem)
|
|
|
|
);
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> {
|
2021-10-28 02:11:53 +02:00
|
|
|
fetchItemInfoIfSparse(fragment, item,
|
2021-09-01 01:55:56 +02:00
|
|
|
fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem)
|
|
|
|
);
|
2020-10-06 17:22:12 +02:00
|
|
|
}),
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
|
2020-03-31 19:20:15 +02:00
|
|
|
NavigationHelper.playOnBackgroundPlayer(fragment.getContext(),
|
|
|
|
new SinglePlayQueue(item), true)),
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
start_here_on_popup(R.string.start_here_on_popup, (fragment, item) ->
|
2020-03-31 19:20:15 +02:00
|
|
|
NavigationHelper.playOnPopupPlayer(fragment.getContext(),
|
|
|
|
new SinglePlayQueue(item), true)),
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> {
|
|
|
|
}), // has to be set manually
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
delete(R.string.delete, (fragment, item) -> {
|
|
|
|
}), // has to be set manually
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
append_playlist(R.string.append_playlist, (fragment, item) -> {
|
2021-06-16 04:08:25 +02:00
|
|
|
final PlaylistAppendDialog d = PlaylistAppendDialog
|
|
|
|
.fromStreamInfoItems(Collections.singletonList(item));
|
|
|
|
|
|
|
|
PlaylistAppendDialog.onPlaylistFound(fragment.getContext(),
|
|
|
|
() -> d.show(fragment.getParentFragmentManager(), "StreamDialogEntry@append_playlist"),
|
|
|
|
() -> PlaylistCreationDialog.newInstance(d)
|
|
|
|
.show(fragment.getParentFragmentManager(), "StreamDialogEntry@create_playlist")
|
|
|
|
);
|
2020-03-31 19:20:15 +02:00
|
|
|
}),
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2020-12-30 23:40:21 +01:00
|
|
|
play_with_kodi(R.string.play_with_kodi_title, (fragment, item) -> {
|
2020-12-30 03:17:36 +01:00
|
|
|
final Uri videoUrl = Uri.parse(item.getUrl());
|
|
|
|
try {
|
2021-06-05 01:16:48 +02:00
|
|
|
NavigationHelper.playWithKore(fragment.requireContext(), videoUrl);
|
2020-12-30 03:17:36 +01:00
|
|
|
} catch (final Exception e) {
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
KoreUtils.showInstallKoreDialog(fragment.requireActivity());
|
2020-12-30 03:17:36 +01:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2019-07-25 00:44:12 +02:00
|
|
|
share(R.string.share, (fragment, item) ->
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
|
2021-03-20 16:35:14 +01:00
|
|
|
item.getThumbnailUrl())),
|
2021-05-13 12:49:34 +02:00
|
|
|
|
|
|
|
open_in_browser(R.string.open_in_browser, (fragment, item) ->
|
Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings
* changed line length for checkstyle pass
* cleaned comments, moved strings
* Update app/src/main/res/values/strings.xml
to make long press entry more descriptive
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
* Update app/src/main/res/values/strings.xml
Co-authored-by: Stypox <stypox@pm.me>
* replace redundant nextOnVideoPlayer methods
Co-authored-by: Stypox <stypox@pm.me>
* add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods
add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with
add section comments
* removed deprecated methods
removed redundant methods
* removed deprecated methods
removed redundant methods
* replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods
* now works with playlists
* renamed dialog entry
* checking for >1 items in the queue using the PlayerHolder
* making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio)
* corrected strings
* improve getQueueSize in PlayerHolder
* long press to enqueue only if queue isnt empty
* add Whitespace
Co-authored-by: Stypox <stypox@pm.me>
* clarify comments / add spaces
* PlayerType as parameter of the enqueueOnPlayer method
add Helper method
* using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere
/ passing checkstyle
* assimilated the enqueue*OnPlayer methods
* removed redundant comment, variable
* simplify code line
Co-authored-by: Stypox <stypox@pm.me>
* move if
* replace workaround for isPlayerOpen()
Co-authored-by: Stypox <stypox@pm.me>
* replaced workarounds (getType), corrected static access with getInstance
* remove unused imports
* changed method call to original, new method doesnt exist yet.
* Use getter method instead of property access syntax.
* improve conditional for play next entry
Co-authored-by: Stypox <stypox@pm.me>
* show play next btn in feed fragment
Co-authored-by: Stypox <stypox@pm.me>
* add play next to local playlist and statistics fragment
Co-authored-by: Stypox <stypox@pm.me>
* formating
Co-authored-by: Stypox <stypox@pm.me>
* correcting logic
Co-authored-by: Stypox <stypox@pm.me>
* remove 2 year old unused string, formating
Co-authored-by: Stypox <stypox@pm.me>
* correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play.
* remove player open checks from button long press enqueue actions
* improve log msg
* Rename next to enqueue_next
* Refactor kotlin
Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
2021-09-18 11:22:49 +02:00
|
|
|
ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),
|
2021-07-27 04:51:41 +02:00
|
|
|
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2021-07-27 21:26:51 +02:00
|
|
|
mark_as_watched(R.string.mark_as_watched, (fragment, item) -> {
|
2021-07-27 04:51:41 +02:00
|
|
|
new HistoryRecordManager(fragment.getContext())
|
2021-07-27 21:26:51 +02:00
|
|
|
.markAsWatched(item)
|
2021-07-27 04:51:41 +02:00
|
|
|
.onErrorComplete()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe();
|
|
|
|
});
|
2019-07-25 00:44:12 +02:00
|
|
|
|
|
|
|
///////////////
|
|
|
|
// variables //
|
|
|
|
///////////////
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static StreamDialogEntry[] enabledEntries;
|
2019-07-25 00:44:12 +02:00
|
|
|
private final int resource;
|
2019-07-25 01:07:51 +02:00
|
|
|
private final StreamDialogEntryAction defaultAction;
|
2019-07-25 00:53:13 +02:00
|
|
|
private StreamDialogEntryAction customAction;
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
StreamDialogEntry(final int resource, final StreamDialogEntryAction defaultAction) {
|
2019-07-25 00:44:12 +02:00
|
|
|
this.resource = resource;
|
2019-07-25 01:07:51 +02:00
|
|
|
this.defaultAction = defaultAction;
|
2019-07-25 00:53:13 +02:00
|
|
|
this.customAction = null;
|
2019-07-25 00:44:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// non-static methods to initialize and edit entries //
|
|
|
|
///////////////////////////////////////////////////////
|
2019-07-25 00:44:12 +02:00
|
|
|
|
2020-10-06 17:22:12 +02:00
|
|
|
public static void setEnabledEntries(final List<StreamDialogEntry> entries) {
|
2020-10-06 14:38:48 +02:00
|
|
|
setEnabledEntries(entries.toArray(new StreamDialogEntry[0]));
|
|
|
|
}
|
|
|
|
|
2019-07-25 00:53:13 +02:00
|
|
|
/**
|
2020-03-31 19:20:15 +02:00
|
|
|
* To be called before using {@link #setCustomAction(StreamDialogEntryAction)}.
|
|
|
|
*
|
|
|
|
* @param entries the entries to be enabled
|
2019-07-25 00:53:13 +02:00
|
|
|
*/
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void setEnabledEntries(final StreamDialogEntry... entries) {
|
2019-07-25 00:53:13 +02:00
|
|
|
// cleanup from last time StreamDialogEntry was used
|
2020-08-16 10:24:58 +02:00
|
|
|
for (final StreamDialogEntry streamDialogEntry : values()) {
|
2019-07-25 00:53:13 +02:00
|
|
|
streamDialogEntry.customAction = null;
|
|
|
|
}
|
|
|
|
|
2019-07-25 00:44:12 +02:00
|
|
|
enabledEntries = entries;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static String[] getCommands(final Context context) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final String[] commands = new String[enabledEntries.length];
|
2019-07-25 00:44:12 +02:00
|
|
|
for (int i = 0; i != enabledEntries.length; ++i) {
|
|
|
|
commands[i] = context.getResources().getString(enabledEntries[i].resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return commands;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
// static methods that act on enabled entries //
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public static void clickOn(final int which, final Fragment fragment,
|
|
|
|
final StreamInfoItem infoItem) {
|
2019-07-25 00:53:13 +02:00
|
|
|
if (enabledEntries[which].customAction == null) {
|
2019-07-25 01:07:51 +02:00
|
|
|
enabledEntries[which].defaultAction.onClick(fragment, infoItem);
|
2019-07-25 00:53:13 +02:00
|
|
|
} else {
|
|
|
|
enabledEntries[which].customAction.onClick(fragment, infoItem);
|
|
|
|
}
|
2019-07-25 00:44:12 +02:00
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Can be used after {@link #setEnabledEntries(StreamDialogEntry...)} has been called.
|
|
|
|
*
|
|
|
|
* @param action the action to be set
|
|
|
|
*/
|
|
|
|
public void setCustomAction(final StreamDialogEntryAction action) {
|
|
|
|
this.customAction = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface StreamDialogEntryAction {
|
|
|
|
void onClick(Fragment fragment, StreamInfoItem infoItem);
|
|
|
|
}
|
2021-08-14 11:32:38 +02:00
|
|
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
// private method to open channel fragment //
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
|
|
|
|
private static void openChannelFragment(final Fragment fragment,
|
|
|
|
final StreamInfoItem item,
|
|
|
|
final String uploaderUrl) {
|
|
|
|
// For some reason `getParentFragmentManager()` doesn't work, but this does.
|
|
|
|
NavigationHelper.openChannelFragment(
|
|
|
|
fragment.requireActivity().getSupportFragmentManager(),
|
|
|
|
item.getServiceId(), uploaderUrl, item.getUploaderName());
|
|
|
|
}
|
2021-09-01 01:55:56 +02:00
|
|
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
// helper functions //
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
|
|
|
|
private interface InfoCallback {
|
|
|
|
void onInfo(SinglePlayQueue item);
|
|
|
|
}
|
|
|
|
|
2021-10-28 02:11:53 +02:00
|
|
|
private static void fetchItemInfoIfSparse(final Fragment fragment,
|
|
|
|
final StreamInfoItem item,
|
|
|
|
final InfoCallback callback) {
|
2021-11-23 16:22:11 +01:00
|
|
|
if ((item.getStreamType() == StreamType.LIVE_STREAM || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) && item.getDuration() < 0) {
|
2021-09-01 01:55:56 +02:00
|
|
|
// Sparse item: fetched by fast fetch
|
2021-12-03 22:30:26 +01:00
|
|
|
ExtractorHelper.getStreamInfo(
|
2021-09-01 01:55:56 +02:00
|
|
|
item.getServiceId(),
|
|
|
|
item.getUrl(),
|
|
|
|
false
|
|
|
|
)
|
2021-10-28 02:11:53 +02:00
|
|
|
|
2021-09-01 01:55:56 +02:00
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe(result -> {
|
2021-10-28 02:11:53 +02:00
|
|
|
final HistoryRecordManager recordManager =
|
|
|
|
new HistoryRecordManager(fragment.getContext());
|
|
|
|
recordManager.saveStreamState(result, 0)
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.doOnError(throwable -> Log.e("StreamDialogEntry",
|
|
|
|
throwable.toString()))
|
|
|
|
.subscribe();
|
|
|
|
|
2021-09-01 01:55:56 +02:00
|
|
|
callback.onInfo(new SinglePlayQueue(result));
|
|
|
|
}, throwable -> Log.e("StreamDialogEntry", throwable.toString()));
|
|
|
|
} else {
|
|
|
|
callback.onInfo(new SinglePlayQueue(item));
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 00:44:12 +02:00
|
|
|
}
|