2017-04-09 19:34:00 +02:00
|
|
|
package org.schabi.newpipe.util;
|
|
|
|
|
2018-03-08 15:50:46 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2017-07-04 09:31:53 +02:00
|
|
|
import android.app.Activity;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2017-10-30 21:15:06 +01:00
|
|
|
import android.net.Uri;
|
2017-11-02 06:33:13 +01:00
|
|
|
import android.os.Build;
|
2020-03-31 19:20:15 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-10-06 13:33:44 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2020-09-13 13:53:16 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2017-06-05 21:33:01 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.MainActivity;
|
2021-07-10 10:17:00 +02:00
|
|
|
import org.schabi.newpipe.NewPipeDatabase;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2019-03-02 00:42:06 +01:00
|
|
|
import org.schabi.newpipe.RouterActivity;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.about.AboutActivity;
|
2020-01-28 06:59:49 +01:00
|
|
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity;
|
2017-07-04 09:31:53 +02:00
|
|
|
import org.schabi.newpipe.download.DownloadActivity;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
2017-09-15 19:27:39 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2018-01-23 01:40:00 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.Stream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
2017-06-05 21:33:01 +02:00
|
|
|
import org.schabi.newpipe.fragments.MainFragment;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.channel.ChannelFragment;
|
2017-10-05 14:57:19 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment;
|
|
|
|
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
2019-03-02 00:42:06 +01:00
|
|
|
import org.schabi.newpipe.local.bookmark.BookmarkFragment;
|
|
|
|
import org.schabi.newpipe.local.feed.FeedFragment;
|
2018-04-28 15:37:27 +02:00
|
|
|
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
2018-04-12 23:46:03 +02:00
|
|
|
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
2018-06-08 21:07:25 +02:00
|
|
|
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
|
2018-04-15 20:29:58 +02:00
|
|
|
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
2021-01-15 17:11:04 +01:00
|
|
|
import org.schabi.newpipe.player.MainPlayer;
|
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
|
|
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
|
|
|
import org.schabi.newpipe.player.NotificationUtil;
|
2021-01-12 21:15:06 +01:00
|
|
|
import org.schabi.newpipe.player.PlayQueueActivity;
|
2021-01-08 18:35:33 +01:00
|
|
|
import org.schabi.newpipe.player.Player;
|
2020-10-18 20:19:50 +02:00
|
|
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
|
|
|
import org.schabi.newpipe.player.helper.PlayerHolder;
|
2018-04-21 23:10:01 +02:00
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
2019-12-29 22:15:01 +01:00
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
2017-07-04 09:31:53 +02:00
|
|
|
import org.schabi.newpipe.settings.SettingsActivity;
|
2021-03-26 13:28:11 +01:00
|
|
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2018-01-23 01:40:00 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2021-03-26 13:28:11 +01:00
|
|
|
import static org.schabi.newpipe.util.external_communication.ShareUtils.installApp;
|
2021-01-15 17:11:04 +01:00
|
|
|
|
2021-09-06 20:47:44 +02:00
|
|
|
import com.jakewharton.processphoenix.ProcessPhoenix;
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public final class NavigationHelper {
|
2017-07-10 05:09:57 +02:00
|
|
|
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
|
2018-02-03 12:03:55 +01:00
|
|
|
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
|
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
|
|
|
private static final String TAG = NotificationUtil.class.getSimpleName();
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2021-03-31 17:18:02 +02:00
|
|
|
private NavigationHelper() {
|
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2017-04-26 21:32:20 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Players
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
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
|
|
|
/* INTENT */
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2020-09-08 21:42:25 +02:00
|
|
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class<T> targetClazz,
|
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
|
|
|
@Nullable final PlayQueue playQueue) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, targetClazz);
|
2018-03-01 02:47:12 +01:00
|
|
|
|
2020-09-08 21:42:25 +02:00
|
|
|
if (playQueue != null) {
|
|
|
|
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
|
|
|
if (cacheKey != null) {
|
2021-01-08 18:35:33 +01:00
|
|
|
intent.putExtra(Player.PLAY_QUEUE_KEY, cacheKey);
|
2020-09-08 21:42:25 +02:00
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2021-01-08 18:35:33 +01:00
|
|
|
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal());
|
2019-12-29 22:15:01 +01:00
|
|
|
|
2017-10-25 06:47:14 +02:00
|
|
|
return intent;
|
2017-04-12 08:07:15 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2020-09-08 21:42:25 +02:00
|
|
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class<T> targetClazz,
|
|
|
|
@Nullable final PlayQueue playQueue,
|
2020-10-31 20:26:09 +01:00
|
|
|
final boolean playWhenReady) {
|
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
|
|
|
return getPlayerIntent(context, targetClazz, playQueue)
|
2021-01-08 18:35:33 +01:00
|
|
|
.putExtra(Player.PLAY_WHEN_READY, playWhenReady);
|
2017-10-13 02:02:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2020-09-08 21:42:25 +02:00
|
|
|
public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class<T> targetClazz,
|
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
|
|
|
@Nullable final PlayQueue playQueue) {
|
|
|
|
return getPlayerIntent(context, targetClazz, playQueue)
|
|
|
|
.putExtra(Player.ENQUEUE, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class<T> targetClazz,
|
|
|
|
@Nullable final PlayQueue playQueue) {
|
|
|
|
return getPlayerIntent(context, targetClazz, playQueue)
|
|
|
|
.putExtra(Player.ENQUEUE_NEXT, true);
|
2017-04-17 06:21:48 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
/* PLAY */
|
2020-09-08 21:42:25 +02:00
|
|
|
public static void playOnMainPlayer(final AppCompatActivity activity,
|
2020-10-18 20:19:50 +02:00
|
|
|
@NonNull final PlayQueue playQueue) {
|
|
|
|
final PlayQueueItem item = playQueue.getItem();
|
2021-03-31 17:18:02 +02:00
|
|
|
if (item != null) {
|
|
|
|
openVideoDetailFragment(activity, activity.getSupportFragmentManager(),
|
|
|
|
item.getServiceId(), item.getUrl(), item.getTitle(), playQueue,
|
|
|
|
false);
|
|
|
|
}
|
2018-01-23 01:40:00 +01:00
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
public static void playOnMainPlayer(final Context context,
|
2020-10-31 20:26:09 +01:00
|
|
|
@NonNull final PlayQueue playQueue,
|
|
|
|
final boolean switchingPlayers) {
|
2020-10-18 20:19:50 +02:00
|
|
|
final PlayQueueItem item = playQueue.getItem();
|
2021-03-31 17:18:02 +02:00
|
|
|
if (item != null) {
|
|
|
|
openVideoDetail(context,
|
|
|
|
item.getServiceId(), item.getUrl(), item.getTitle(), playQueue,
|
|
|
|
switchingPlayers);
|
|
|
|
}
|
2020-10-18 20:19:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void playOnPopupPlayer(final Context context,
|
|
|
|
final PlayQueue queue,
|
2020-03-31 19:20:15 +02:00
|
|
|
final boolean resumePlayback) {
|
2018-01-23 01:40:00 +01:00
|
|
|
if (!PermissionHelper.isPopupEnabled(context)) {
|
|
|
|
PermissionHelper.showPopupEnablementToast(context);
|
2018-01-04 07:53:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 01:40:00 +01:00
|
|
|
|
|
|
|
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
|
2020-07-12 02:59:47 +02:00
|
|
|
final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback);
|
2021-01-08 18:35:33 +01:00
|
|
|
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.POPUP.ordinal());
|
2020-09-13 13:53:16 +02:00
|
|
|
ContextCompat.startForegroundService(context, intent);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
2020-07-14 19:21:32 +02:00
|
|
|
public static void playOnBackgroundPlayer(final Context context,
|
|
|
|
final PlayQueue queue,
|
|
|
|
final boolean resumePlayback) {
|
|
|
|
Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2020-07-12 02:59:47 +02:00
|
|
|
final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback);
|
2021-01-08 18:35:33 +01:00
|
|
|
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.AUDIO.ordinal());
|
2020-09-13 13:53:16 +02:00
|
|
|
ContextCompat.startForegroundService(context, intent);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
public static void enqueueOnPlayer(final Context context,
|
|
|
|
final PlayQueue queue,
|
|
|
|
final PlayerType playerType) {
|
2020-10-06 21:17:52 +02:00
|
|
|
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
|
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
|
|
|
final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue);
|
2020-10-06 13:33:44 +02:00
|
|
|
|
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
|
|
|
intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal());
|
2020-09-13 13:53:16 +02:00
|
|
|
ContextCompat.startForegroundService(context, intent);
|
2020-10-06 13:33:44 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
public static void enqueueOnPlayer(final Context context, final PlayQueue queue) {
|
|
|
|
PlayerType playerType = PlayerHolder.getInstance().getType();
|
|
|
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
|
|
|
Log.e(TAG, "Enqueueing but no player is open; defaulting to background player");
|
|
|
|
playerType = MainPlayer.PlayerType.AUDIO;
|
2018-01-04 07:53:31 +01:00
|
|
|
}
|
2018-01-23 01:40:00 +01:00
|
|
|
|
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
|
|
|
enqueueOnPlayer(context, queue, playerType);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
public static void enqueueNextOnPlayer(final Context context, final PlayQueue queue) {
|
|
|
|
PlayerType playerType = PlayerHolder.getInstance().getType();
|
|
|
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
|
|
|
Log.e(TAG, "Enqueueing next but no player is open; defaulting to background player");
|
|
|
|
playerType = MainPlayer.PlayerType.AUDIO;
|
|
|
|
}
|
|
|
|
Toast.makeText(context, R.string.enqueued_next, Toast.LENGTH_SHORT).show();
|
|
|
|
final Intent intent = getPlayerEnqueueNextIntent(context, MainPlayer.class, queue);
|
2018-01-23 01:40:00 +01:00
|
|
|
|
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
|
|
|
intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal());
|
2020-09-13 13:53:16 +02:00
|
|
|
ContextCompat.startForegroundService(context, intent);
|
2018-01-23 01:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// External Players
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void playOnExternalAudioPlayer(final Context context, final StreamInfo info) {
|
2018-01-23 01:40:00 +01:00
|
|
|
final int index = ListHelper.getDefaultAudioFormat(context, info.getAudioStreams());
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
Toast.makeText(context, R.string.audio_streams_empty, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final AudioStream audioStream = info.getAudioStreams().get(index);
|
2018-01-23 01:40:00 +01:00
|
|
|
playOnExternalPlayer(context, info.getName(), info.getUploaderName(), audioStream);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void playOnExternalVideoPlayer(final Context context, final StreamInfo info) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final ArrayList<VideoStream> videoStreamsList = new ArrayList<>(
|
2020-03-31 19:20:15 +02:00
|
|
|
ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), null, false));
|
2020-08-16 10:24:58 +02:00
|
|
|
final int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
|
2018-01-23 01:40:00 +01:00
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
Toast.makeText(context, R.string.video_streams_empty, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final VideoStream videoStream = videoStreamsList.get(index);
|
2018-01-23 01:40:00 +01:00
|
|
|
playOnExternalPlayer(context, info.getName(), info.getUploaderName(), videoStream);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void playOnExternalPlayer(final Context context, final String name,
|
|
|
|
final String artist, final Stream stream) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent();
|
2018-01-23 01:40:00 +01:00
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.parse(stream.getUrl()), stream.getFormat().getMimeType());
|
|
|
|
intent.putExtra(Intent.EXTRA_TITLE, name);
|
|
|
|
intent.putExtra("title", name);
|
|
|
|
intent.putExtra("artist", artist);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
|
|
|
resolveActivityOrAskToInstall(context, intent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void resolveActivityOrAskToInstall(final Context context, final Intent intent) {
|
2018-01-23 01:40:00 +01:00
|
|
|
if (intent.resolveActivity(context.getPackageManager()) != null) {
|
2021-03-13 12:37:54 +01:00
|
|
|
ShareUtils.openIntentInApp(context, intent, false);
|
2018-01-23 01:40:00 +01:00
|
|
|
} else {
|
|
|
|
if (context instanceof Activity) {
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setMessage(R.string.no_player_found)
|
2021-03-27 14:37:44 +01:00
|
|
|
.setPositiveButton(R.string.install,
|
|
|
|
(dialog, which) -> ShareUtils.openUrlInBrowser(context,
|
|
|
|
context.getString(R.string.fdroid_vlc_url), false))
|
2020-03-31 19:20:15 +02:00
|
|
|
.setNegativeButton(R.string.cancel, (dialog, which)
|
|
|
|
-> Log.i("NavigationHelper", "You unlocked a secret unicorn."))
|
2018-01-23 01:40:00 +01:00
|
|
|
.show();
|
|
|
|
} else {
|
|
|
|
Toast.makeText(context, R.string.no_player_found_toast, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
2018-01-23 01:40:00 +01:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2017-06-05 21:33:01 +02:00
|
|
|
// Through FragmentManager
|
2017-04-09 19:34:00 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-03-08 15:50:46 +01:00
|
|
|
@SuppressLint("CommitTransaction")
|
2020-03-31 19:20:15 +02:00
|
|
|
private static FragmentTransaction defaultTransaction(final FragmentManager fragmentManager) {
|
2018-03-08 15:50:46 +01:00
|
|
|
return fragmentManager.beginTransaction()
|
2020-03-31 19:20:15 +02:00
|
|
|
.setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out,
|
|
|
|
R.animator.custom_fade_in, R.animator.custom_fade_out);
|
2018-03-08 15:50:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void gotoMainFragment(final FragmentManager fragmentManager) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final boolean popped = fragmentManager.popBackStackImmediate(MAIN_FRAGMENT_TAG, 0);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (!popped) {
|
|
|
|
openMainFragment(fragmentManager);
|
|
|
|
}
|
2017-07-10 05:09:57 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openMainFragment(final FragmentManager fragmentManager) {
|
2017-09-03 08:04:18 +02:00
|
|
|
InfoCache.getInstance().trimCache();
|
|
|
|
|
2017-07-10 05:09:57 +02:00
|
|
|
fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2017-06-05 21:33:01 +02:00
|
|
|
.replace(R.id.fragment_holder, new MainFragment())
|
2017-07-10 05:09:57 +02:00
|
|
|
.addToBackStack(MAIN_FRAGMENT_TAG)
|
2017-06-05 21:33:01 +02:00
|
|
|
.commit();
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static boolean tryGotoSearchFragment(final FragmentManager fragmentManager) {
|
2018-02-03 12:03:55 +01:00
|
|
|
if (MainActivity.DEBUG) {
|
|
|
|
for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) {
|
2020-03-31 19:20:15 +02:00
|
|
|
Log.d("NavigationHelper", "tryGoToSearchFragment() [" + i + "]"
|
|
|
|
+ " = [" + fragmentManager.getBackStackEntryAt(i) + "]");
|
2018-02-03 12:03:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fragmentManager.popBackStackImmediate(SEARCH_FRAGMENT_TAG, 0);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSearchFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String searchString) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2018-07-10 16:26:42 +02:00
|
|
|
.replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, searchString))
|
2018-02-03 12:03:55 +01:00
|
|
|
.addToBackStack(SEARCH_FRAGMENT_TAG)
|
2017-06-05 21:33:01 +02:00
|
|
|
.commit();
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 03:17:21 +02:00
|
|
|
public static void expandMainPlayer(final Context context) {
|
2020-09-29 05:22:53 +02:00
|
|
|
context.sendBroadcast(new Intent(VideoDetailFragment.ACTION_SHOW_MAIN_PLAYER));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendPlayerStartedEvent(final Context context) {
|
|
|
|
context.sendBroadcast(new Intent(VideoDetailFragment.ACTION_PLAYER_STARTED));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showMiniPlayer(final FragmentManager fragmentManager) {
|
2020-09-29 23:49:34 +02:00
|
|
|
final VideoDetailFragment instance = VideoDetailFragment.getInstanceInCollapsedState();
|
2020-09-29 05:22:53 +02:00
|
|
|
defaultTransaction(fragmentManager)
|
|
|
|
.replace(R.id.fragment_player_holder, instance)
|
|
|
|
.runOnCommit(() -> sendPlayerStartedEvent(instance.requireActivity()))
|
2020-10-17 16:13:42 +02:00
|
|
|
.commitAllowingStateLoss();
|
2019-12-29 22:15:01 +01:00
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
private interface RunnableWithVideoDetailFragment {
|
|
|
|
void run(VideoDetailFragment detailFragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void openVideoDetailFragment(@NonNull final Context context,
|
|
|
|
@NonNull final FragmentManager fragmentManager,
|
|
|
|
final int serviceId,
|
|
|
|
@Nullable final String url,
|
|
|
|
@NonNull final String title,
|
|
|
|
@Nullable final PlayQueue playQueue,
|
|
|
|
final boolean switchingPlayers) {
|
|
|
|
|
|
|
|
final boolean autoPlay;
|
2021-06-24 10:00:56 +02:00
|
|
|
@Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
|
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
|
|
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
2020-10-18 20:19:50 +02:00
|
|
|
// no player open
|
|
|
|
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
|
|
|
} else if (switchingPlayers) {
|
|
|
|
// switching player to main player
|
2021-06-24 10:00:56 +02:00
|
|
|
autoPlay = PlayerHolder.getInstance().isPlaying(); // keep play/pause state
|
2020-10-18 20:19:50 +02:00
|
|
|
} else if (playerType == MainPlayer.PlayerType.VIDEO) {
|
|
|
|
// opening new stream while already playing in main player
|
|
|
|
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
|
|
|
} else {
|
|
|
|
// opening new stream while already playing in another player
|
|
|
|
autoPlay = false;
|
|
|
|
}
|
|
|
|
|
2021-09-04 22:36:20 +02:00
|
|
|
final RunnableWithVideoDetailFragment onVideoDetailFragmentReady = detailFragment -> {
|
2020-10-18 20:19:50 +02:00
|
|
|
expandMainPlayer(detailFragment.requireActivity());
|
|
|
|
detailFragment.setAutoPlay(autoPlay);
|
|
|
|
if (switchingPlayers) {
|
|
|
|
// Situation when user switches from players to main player. All needed data is
|
|
|
|
// here, we can start watching (assuming newQueue equals playQueue).
|
2021-07-27 11:02:32 +02:00
|
|
|
// Starting directly in fullscreen if the previous player type was popup.
|
|
|
|
detailFragment.openVideoPlayer(playerType == MainPlayer.PlayerType.POPUP
|
|
|
|
|| PlayerHelper.isStartMainPlayerFullscreenEnabled(context));
|
2020-10-18 20:19:50 +02:00
|
|
|
} else {
|
|
|
|
detailFragment.selectAndLoadVideo(serviceId, url, title, playQueue);
|
|
|
|
}
|
|
|
|
detailFragment.scrollToTop();
|
|
|
|
};
|
|
|
|
|
|
|
|
final Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_player_holder);
|
|
|
|
if (fragment instanceof VideoDetailFragment && fragment.isVisible()) {
|
|
|
|
onVideoDetailFragmentReady.run((VideoDetailFragment) fragment);
|
|
|
|
} else {
|
|
|
|
final VideoDetailFragment instance = VideoDetailFragment
|
|
|
|
.getInstance(serviceId, url, title, playQueue);
|
|
|
|
instance.setAutoPlay(autoPlay);
|
|
|
|
|
|
|
|
defaultTransaction(fragmentManager)
|
|
|
|
.replace(R.id.fragment_player_holder, instance)
|
|
|
|
.runOnCommit(() -> onVideoDetailFragmentReady.run(instance))
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openChannelFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
2020-10-18 20:19:50 +02:00
|
|
|
@NonNull final String name) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2020-10-18 20:19:50 +02:00
|
|
|
.replace(R.id.fragment_holder, ChannelFragment.getInstance(serviceId, url, name))
|
2017-06-05 21:33:01 +02:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openPlaylistFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
2020-10-18 20:19:50 +02:00
|
|
|
@NonNull final String name) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2020-10-18 20:19:50 +02:00
|
|
|
.replace(R.id.fragment_holder, PlaylistFragment.getInstance(serviceId, url, name))
|
2017-09-03 08:04:18 +02:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openFeedFragment(final FragmentManager fragmentManager) {
|
2020-01-28 06:59:49 +01:00
|
|
|
openFeedFragment(fragmentManager, FeedGroupEntity.GROUP_ALL_ID, null);
|
2019-04-28 22:43:54 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openFeedFragment(final FragmentManager fragmentManager, final long groupId,
|
|
|
|
@Nullable final String groupName) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2019-04-28 22:43:54 +02:00
|
|
|
.replace(R.id.fragment_holder, FeedFragment.newInstance(groupId, groupName))
|
2017-08-07 15:02:30 +02:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openBookmarksFragment(final FragmentManager fragmentManager) {
|
2018-06-08 21:07:25 +02:00
|
|
|
defaultTransaction(fragmentManager)
|
|
|
|
.replace(R.id.fragment_holder, new BookmarkFragment())
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSubscriptionFragment(final FragmentManager fragmentManager) {
|
2018-06-08 21:07:25 +02:00
|
|
|
defaultTransaction(fragmentManager)
|
|
|
|
.replace(R.id.fragment_holder, new SubscriptionFragment())
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openKioskFragment(final FragmentManager fragmentManager, final int serviceId,
|
|
|
|
final String kioskId) throws ExtractionException {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2017-10-05 14:57:19 +02:00
|
|
|
.replace(R.id.fragment_holder, KioskFragment.getInstance(serviceId, kioskId))
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openLocalPlaylistFragment(final FragmentManager fragmentManager,
|
|
|
|
final long playlistId, final String name) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2020-03-31 19:20:15 +02:00
|
|
|
.replace(R.id.fragment_holder, LocalPlaylistFragment.getInstance(playlistId,
|
|
|
|
name == null ? "" : name))
|
2018-01-17 06:12:03 +01:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openStatisticFragment(final FragmentManager fragmentManager) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2018-04-28 15:37:27 +02:00
|
|
|
.replace(R.id.fragment_holder, new StatisticsPlaylistFragment())
|
2018-01-17 06:12:03 +01:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
2018-03-08 15:50:46 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSubscriptionsImportFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId) {
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
|
|
|
.replace(R.id.fragment_holder, SubscriptionsImportFragment.getInstance(serviceId))
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Through Intents
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSearch(final Context context, final int serviceId,
|
|
|
|
final String searchString) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent mIntent = new Intent(context, MainActivity.class);
|
2017-06-05 21:33:01 +02:00
|
|
|
mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId);
|
2018-07-08 17:46:21 +02:00
|
|
|
mIntent.putExtra(Constants.KEY_SEARCH_STRING, searchString);
|
2017-06-05 21:33:01 +02:00
|
|
|
mIntent.putExtra(Constants.KEY_OPEN_SEARCH, true);
|
|
|
|
context.startActivity(mIntent);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
public static void openVideoDetail(final Context context,
|
|
|
|
final int serviceId,
|
|
|
|
final String url,
|
|
|
|
@NonNull final String title,
|
2020-10-31 20:26:09 +01:00
|
|
|
@Nullable final PlayQueue playQueue,
|
|
|
|
final boolean switchingPlayers) {
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
final Intent intent = getOpenIntent(context, url, serviceId,
|
2020-03-31 19:20:15 +02:00
|
|
|
StreamingService.LinkType.STREAM);
|
2020-11-02 18:06:14 +01:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2020-10-18 20:19:50 +02:00
|
|
|
intent.putExtra(Constants.KEY_TITLE, title);
|
2020-10-31 20:26:09 +01:00
|
|
|
intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers);
|
2020-10-18 20:19:50 +02:00
|
|
|
|
|
|
|
if (playQueue != null) {
|
|
|
|
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
|
|
|
if (cacheKey != null) {
|
2021-01-08 18:35:33 +01:00
|
|
|
intent.putExtra(Player.PLAY_QUEUE_KEY, cacheKey);
|
2020-10-18 20:19:50 +02:00
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2020-10-18 20:19:50 +02:00
|
|
|
context.startActivity(intent);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openMainActivity(final Context context) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent mIntent = new Intent(context, MainActivity.class);
|
2017-09-03 08:04:18 +02:00
|
|
|
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
2017-04-09 19:34:00 +02:00
|
|
|
context.startActivity(mIntent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openRouterActivity(final Context context, final String url) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent mIntent = new Intent(context, RouterActivity.class);
|
2019-03-02 00:42:06 +01:00
|
|
|
mIntent.setData(Uri.parse(url));
|
|
|
|
context.startActivity(mIntent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openAbout(final Context context) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, AboutActivity.class);
|
2017-09-03 08:04:18 +02:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSettings(final Context context) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, SettingsActivity.class);
|
2017-09-03 08:04:18 +02:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
public static void openDownloads(final Activity activity) {
|
|
|
|
if (PermissionHelper.checkStoragePermissions(
|
2020-03-31 19:20:15 +02:00
|
|
|
activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
|
2020-10-18 20:19:50 +02:00
|
|
|
final Intent intent = new Intent(activity, DownloadActivity.class);
|
|
|
|
activity.startActivity(intent);
|
2019-08-15 04:00:11 +02:00
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 21:42:25 +02:00
|
|
|
public static Intent getPlayQueueActivityIntent(final Context context) {
|
2021-01-12 21:15:06 +01:00
|
|
|
final Intent intent = new Intent(context, PlayQueueActivity.class);
|
2017-11-02 06:33:13 +01:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
}
|
2017-12-29 17:29:15 +01:00
|
|
|
return intent;
|
|
|
|
}
|
2020-09-08 21:42:25 +02:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Link handling
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static Intent getOpenIntent(final Context context, final String url,
|
|
|
|
final int serviceId, final StreamingService.LinkType type) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent mIntent = new Intent(context, MainActivity.class);
|
2017-04-09 19:34:00 +02:00
|
|
|
mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId);
|
|
|
|
mIntent.putExtra(Constants.KEY_URL, url);
|
|
|
|
mIntent.putExtra(Constants.KEY_LINK_TYPE, type);
|
|
|
|
return mIntent;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static Intent getIntentByLink(final Context context, final String url)
|
|
|
|
throws ExtractionException {
|
2017-09-15 19:27:39 +02:00
|
|
|
return getIntentByLink(context, NewPipe.getServiceByUrl(url), url);
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
public static Intent getIntentByLink(final Context context,
|
|
|
|
final StreamingService service,
|
2020-03-31 19:20:15 +02:00
|
|
|
final String url) throws ExtractionException {
|
2020-08-16 10:24:58 +02:00
|
|
|
final StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
|
|
|
if (linkType == StreamingService.LinkType.NONE) {
|
2020-03-31 19:20:15 +02:00
|
|
|
throw new ExtractionException("Url not known to service. service=" + service
|
|
|
|
+ " url=" + url);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:50 +02:00
|
|
|
return getOpenIntent(context, url, service.getServiceId(), linkType);
|
2017-07-04 09:31:53 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 21:15:06 +01:00
|
|
|
/**
|
2020-03-31 19:20:15 +02:00
|
|
|
* Start an activity to install Kore.
|
2020-07-12 02:59:47 +02:00
|
|
|
*
|
2017-10-30 21:15:06 +01:00
|
|
|
* @param context the context
|
|
|
|
*/
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void installKore(final Context context) {
|
2017-10-30 21:15:06 +01:00
|
|
|
installApp(context, context.getString(R.string.kore_package));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-31 19:20:15 +02:00
|
|
|
* Start Kore app to show a video on Kodi.
|
2020-07-12 02:59:47 +02:00
|
|
|
* <p>
|
2017-10-30 21:31:59 +01:00
|
|
|
* For a list of supported urls see the
|
|
|
|
* <a href="https://github.com/xbmc/Kore/blob/master/app/src/main/AndroidManifest.xml">
|
2020-07-12 02:59:47 +02:00
|
|
|
* Kore source code
|
2017-10-30 21:31:59 +01:00
|
|
|
* </a>.
|
|
|
|
*
|
2020-07-12 02:59:47 +02:00
|
|
|
* @param context the context to use
|
2017-10-30 21:31:59 +01:00
|
|
|
* @param videoURL the url to the video
|
2017-10-30 21:15:06 +01:00
|
|
|
*/
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void playWithKore(final Context context, final Uri videoURL) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
2017-10-30 21:15:06 +01:00
|
|
|
intent.setPackage(context.getString(R.string.kore_package));
|
|
|
|
intent.setData(videoURL);
|
2021-06-05 12:48:34 +02:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2017-10-30 21:15:06 +01:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2021-06-15 18:09:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finish this <code>Activity</code> as well as all <code>Activities</code> running below it
|
|
|
|
* and then start <code>MainActivity</code>.
|
|
|
|
*
|
|
|
|
* @param activity the activity to finish
|
|
|
|
*/
|
|
|
|
public static void restartApp(final Activity activity) {
|
2021-07-10 14:46:51 +02:00
|
|
|
NewPipeDatabase.close();
|
2021-09-06 20:47:44 +02:00
|
|
|
|
|
|
|
ProcessPhoenix.triggerRebirth(activity.getApplicationContext());
|
2021-06-15 18:09:54 +02:00
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|