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-10-30 21:15:06 +01:00
|
|
|
import android.content.ActivityNotFoundException;
|
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;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.preference.PreferenceManager;
|
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;
|
2019-12-29 22:15:01 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
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
|
|
|
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
|
|
|
import org.schabi.newpipe.MainActivity;
|
|
|
|
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;
|
2018-09-23 03:32:19 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
|
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;
|
2019-12-29 22:15:01 +01:00
|
|
|
import org.schabi.newpipe.player.*;
|
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;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2018-01-23 01:40:00 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
@SuppressWarnings({"unused", "WeakerAccess"})
|
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";
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private NavigationHelper() { }
|
|
|
|
|
2017-04-26 21:32:20 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Players
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-01-23 01:40:00 +01:00
|
|
|
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2018-03-01 02:47:12 +01:00
|
|
|
public static Intent getPlayerIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class targetClazz,
|
|
|
|
@NonNull final PlayQueue playQueue,
|
2019-04-13 09:31:32 +02:00
|
|
|
@Nullable final String quality,
|
|
|
|
final boolean resumePlayback) {
|
2018-03-01 02:47:12 +01:00
|
|
|
Intent intent = new Intent(context, targetClazz);
|
|
|
|
|
|
|
|
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (cacheKey != null) {
|
|
|
|
intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey);
|
|
|
|
}
|
|
|
|
if (quality != null) {
|
|
|
|
intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality);
|
|
|
|
}
|
2019-04-13 09:31:32 +02:00
|
|
|
intent.putExtra(VideoPlayer.RESUME_PLAYBACK, resumePlayback);
|
2020-06-27 05:25:50 +02:00
|
|
|
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO);
|
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
|
2018-03-01 02:47:12 +01:00
|
|
|
public static Intent getPlayerIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class targetClazz,
|
2019-04-13 09:31:32 +02:00
|
|
|
@NonNull final PlayQueue playQueue,
|
|
|
|
final boolean resumePlayback) {
|
|
|
|
return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback);
|
2017-10-13 02:02:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2018-03-01 02:47:12 +01:00
|
|
|
public static Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class targetClazz,
|
|
|
|
@NonNull final PlayQueue playQueue,
|
2019-04-13 09:31:32 +02:00
|
|
|
final boolean selectOnAppend,
|
|
|
|
final boolean resumePlayback) {
|
|
|
|
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
2018-01-23 01:40:00 +01:00
|
|
|
.putExtra(BasePlayer.APPEND_ONLY, true)
|
|
|
|
.putExtra(BasePlayer.SELECT_ON_APPEND, selectOnAppend);
|
2017-04-17 06:21:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:25:45 +01:00
|
|
|
@NonNull
|
2018-03-01 02:47:12 +01:00
|
|
|
public static Intent getPlayerIntent(@NonNull final Context context,
|
|
|
|
@NonNull final Class targetClazz,
|
|
|
|
@NonNull final PlayQueue playQueue,
|
2017-10-25 06:47:14 +02:00
|
|
|
final int repeatMode,
|
|
|
|
final float playbackSpeed,
|
|
|
|
final float playbackPitch,
|
2018-05-08 20:24:42 +02:00
|
|
|
final boolean playbackSkipSilence,
|
2019-04-13 09:31:32 +02:00
|
|
|
@Nullable final String playbackQuality,
|
2020-07-13 03:17:21 +02:00
|
|
|
final boolean resumePlayback,
|
|
|
|
final boolean startPaused,
|
2020-02-27 22:30:18 +01:00
|
|
|
final boolean isMuted) {
|
2019-04-13 09:31:32 +02:00
|
|
|
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback)
|
2017-10-25 06:47:14 +02:00
|
|
|
.putExtra(BasePlayer.REPEAT_MODE, repeatMode)
|
2020-02-27 22:30:18 +01:00
|
|
|
.putExtra(BasePlayer.START_PAUSED, startPaused)
|
|
|
|
.putExtra(BasePlayer.IS_MUTED, isMuted);
|
2017-10-25 06:47:14 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 02:59:47 +02:00
|
|
|
public static void playOnMainPlayer(
|
|
|
|
final AppCompatActivity activity,
|
|
|
|
final PlayQueue queue,
|
|
|
|
final boolean autoPlay) {
|
2020-01-08 17:16:50 +01:00
|
|
|
playOnMainPlayer(activity.getSupportFragmentManager(), queue, autoPlay);
|
2019-12-29 22:15:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 02:59:47 +02:00
|
|
|
public static void playOnMainPlayer(
|
|
|
|
final FragmentManager fragmentManager,
|
|
|
|
final PlayQueue queue,
|
|
|
|
final boolean autoPlay) {
|
|
|
|
final PlayQueueItem currentStream = queue.getItem();
|
|
|
|
openVideoDetailFragment(
|
|
|
|
fragmentManager,
|
|
|
|
currentStream.getServiceId(),
|
|
|
|
currentStream.getUrl(),
|
|
|
|
currentStream.getTitle(),
|
|
|
|
autoPlay,
|
|
|
|
queue);
|
2020-06-27 05:25:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void playOnMainPlayer(@NonNull final Context context,
|
|
|
|
@NonNull final PlayQueue queue,
|
|
|
|
@NonNull final StreamingService.LinkType linkType,
|
|
|
|
@NonNull final String url,
|
|
|
|
@NonNull final String title,
|
|
|
|
final boolean autoPlay,
|
|
|
|
final boolean resumePlayback) {
|
|
|
|
|
2020-07-12 02:59:47 +02:00
|
|
|
final Intent intent = getPlayerIntent(context, MainActivity.class, queue, resumePlayback);
|
2020-06-27 05:25:50 +02:00
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
intent.putExtra(Constants.KEY_LINK_TYPE, linkType);
|
|
|
|
intent.putExtra(Constants.KEY_URL, url);
|
|
|
|
intent.putExtra(Constants.KEY_TITLE, title);
|
|
|
|
intent.putExtra(VideoDetailFragment.AUTO_PLAY, autoPlay);
|
|
|
|
context.startActivity(intent);
|
2018-01-23 01:40:00 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void playOnPopupPlayer(final Context context, final PlayQueue queue,
|
|
|
|
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);
|
2019-12-29 22:15:01 +01:00
|
|
|
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP);
|
|
|
|
startService(context, intent);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 09:31:32 +02:00
|
|
|
public static void playOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
|
2017-11-02 06:33:13 +01:00
|
|
|
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);
|
2019-12-29 22:15:01 +01:00
|
|
|
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO);
|
|
|
|
startService(context, intent);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue,
|
|
|
|
final boolean resumePlayback) {
|
2019-04-13 09:31:32 +02:00
|
|
|
enqueueOnPopupPlayer(context, queue, false, resumePlayback);
|
2018-01-23 01:40:00 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue,
|
|
|
|
final boolean selectOnAppend,
|
|
|
|
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_append, Toast.LENGTH_SHORT).show();
|
2020-07-12 02:59:47 +02:00
|
|
|
final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
|
2019-12-29 22:15:01 +01:00
|
|
|
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP);
|
|
|
|
startService(context, intent);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue,
|
|
|
|
final boolean resumePlayback) {
|
2019-04-13 09:31:32 +02:00
|
|
|
enqueueOnBackgroundPlayer(context, queue, false, resumePlayback);
|
2018-01-23 01:40:00 +01:00
|
|
|
}
|
|
|
|
|
2020-07-13 03:17:21 +02:00
|
|
|
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean selectOnAppend,
|
2020-03-31 19:20:15 +02:00
|
|
|
final boolean resumePlayback) {
|
2017-11-02 06:33:13 +01:00
|
|
|
Toast.makeText(context, R.string.background_player_append, Toast.LENGTH_SHORT).show();
|
2020-07-12 02:59:47 +02:00
|
|
|
final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
|
2019-12-29 22:15:01 +01:00
|
|
|
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO);
|
|
|
|
startService(context, intent);
|
2018-03-06 04:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void startService(@NonNull final Context context, @NonNull final Intent intent) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
context.startForegroundService(intent);
|
|
|
|
} else {
|
|
|
|
context.startService(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioStream audioStream = info.getAudioStreams().get(index);
|
|
|
|
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) {
|
|
|
|
ArrayList<VideoStream> videoStreamsList = new ArrayList<>(
|
|
|
|
ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), null, false));
|
2018-01-23 01:40:00 +01:00
|
|
|
int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
Toast.makeText(context, R.string.video_streams_empty, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoStream videoStream = videoStreamsList.get(index);
|
|
|
|
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) {
|
2018-01-23 01:40:00 +01:00
|
|
|
Intent intent = new Intent();
|
|
|
|
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) {
|
|
|
|
context.startActivity(intent);
|
|
|
|
} else {
|
|
|
|
if (context instanceof Activity) {
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setMessage(R.string.no_player_found)
|
|
|
|
.setPositiveButton(R.string.install, (dialog, which) -> {
|
|
|
|
Intent i = new Intent();
|
|
|
|
i.setAction(Intent.ACTION_VIEW);
|
|
|
|
i.setData(Uri.parse(context.getString(R.string.fdroid_vlc_url)));
|
|
|
|
context.startActivity(i);
|
|
|
|
})
|
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();
|
2020-03-31 19:20:15 +02:00
|
|
|
// Log.e("NavigationHelper",
|
|
|
|
// "Either no Streaming player for audio was installed, "
|
|
|
|
// + "or something important crashed:");
|
2018-01-23 01:40:00 +01:00
|
|
|
} 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) {
|
2017-06-05 21:33:01 +02:00
|
|
|
ImageLoader.getInstance().clearMemoryCache();
|
2017-07-10 05:09:57 +02:00
|
|
|
|
|
|
|
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-03-31 19:20:15 +02:00
|
|
|
public static void openVideoDetailFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
|
|
|
final String title) {
|
2019-12-29 22:15:01 +01:00
|
|
|
openVideoDetailFragment(fragmentManager, serviceId, url, title, true, null);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-07-12 02:59:47 +02:00
|
|
|
public static void openVideoDetailFragment(
|
2020-07-13 03:17:21 +02:00
|
|
|
final FragmentManager fragmentManager,
|
|
|
|
final int serviceId,
|
|
|
|
final String url,
|
|
|
|
final String title,
|
|
|
|
final boolean autoPlay,
|
|
|
|
final PlayQueue playQueue) {
|
2020-07-12 02:59:47 +02:00
|
|
|
final Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_player_holder);
|
2017-06-05 21:33:01 +02:00
|
|
|
|
|
|
|
if (fragment instanceof VideoDetailFragment && fragment.isVisible()) {
|
2020-07-12 02:59:47 +02:00
|
|
|
expandMainPlayer(fragment.requireActivity());
|
|
|
|
final VideoDetailFragment detailFragment = (VideoDetailFragment) fragment;
|
2017-06-05 21:33:01 +02:00
|
|
|
detailFragment.setAutoplay(autoPlay);
|
2020-07-13 03:17:21 +02:00
|
|
|
detailFragment.selectAndLoadVideo(serviceId, url, title == null ? "" : title, playQueue);
|
2019-12-31 17:06:39 +01:00
|
|
|
detailFragment.scrollToTop();
|
2017-06-05 21:33:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-13 03:17:21 +02:00
|
|
|
final VideoDetailFragment instance = VideoDetailFragment.getInstance(serviceId, url, title == null ? "" : title, playQueue);
|
2017-06-05 21:33:01 +02:00
|
|
|
instance.setAutoplay(autoPlay);
|
|
|
|
|
2018-03-08 15:50:46 +01:00
|
|
|
defaultTransaction(fragmentManager)
|
2019-12-29 22:15:01 +01:00
|
|
|
.replace(R.id.fragment_player_holder, instance)
|
2020-07-12 02:59:47 +02:00
|
|
|
.runOnCommit(() -> expandMainPlayer(instance.requireActivity()))
|
2017-06-05 21:33:01 +02:00
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-07-13 03:17:21 +02:00
|
|
|
public static void expandMainPlayer(final Context context) {
|
2019-12-29 22:15:01 +01:00
|
|
|
final Intent intent = new Intent(VideoDetailFragment.ACTION_SHOW_MAIN_PLAYER);
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openChannelFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
|
|
|
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, ChannelFragment.getInstance(serviceId, url,
|
|
|
|
name == null ? "" : 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 openCommentsFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
|
|
|
final String name) {
|
|
|
|
fragmentManager.beginTransaction()
|
|
|
|
.setCustomAnimations(R.anim.switch_service_in, R.anim.switch_service_out)
|
|
|
|
.replace(R.id.fragment_holder, CommentsFragment.getInstance(serviceId, url,
|
|
|
|
name == null ? "" : name))
|
2018-09-23 03:32:19 +02:00
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openPlaylistFragment(final FragmentManager fragmentManager,
|
|
|
|
final int serviceId, final String url,
|
|
|
|
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, PlaylistFragment.getInstance(serviceId, url,
|
|
|
|
name == null ? "" : 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) {
|
2017-06-05 21:33:01 +02:00
|
|
|
Intent mIntent = new Intent(context, MainActivity.class);
|
|
|
|
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-03-31 19:20:15 +02:00
|
|
|
public static void openChannel(final Context context, final int serviceId, final String url) {
|
2017-04-09 19:34:00 +02:00
|
|
|
openChannel(context, serviceId, url, null);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openChannel(final Context context, final int serviceId,
|
|
|
|
final String url, final String name) {
|
|
|
|
Intent openIntent = getOpenIntent(context, url, serviceId,
|
|
|
|
StreamingService.LinkType.CHANNEL);
|
|
|
|
if (name != null && !name.isEmpty()) {
|
|
|
|
openIntent.putExtra(Constants.KEY_TITLE, name);
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
context.startActivity(openIntent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openVideoDetail(final Context context, final int serviceId,
|
|
|
|
final String url) {
|
2017-04-09 19:34:00 +02:00
|
|
|
openVideoDetail(context, serviceId, url, null);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openVideoDetail(final Context context, final int serviceId,
|
|
|
|
final String url, final String title) {
|
|
|
|
Intent openIntent = getOpenIntent(context, url, serviceId,
|
|
|
|
StreamingService.LinkType.STREAM);
|
|
|
|
if (title != null && !title.isEmpty()) {
|
|
|
|
openIntent.putExtra(Constants.KEY_TITLE, title);
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
context.startActivity(openIntent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openMainActivity(final Context context) {
|
2017-04-09 19:34:00 +02:00
|
|
|
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) {
|
2019-03-02 00:42:06 +01:00
|
|
|
Intent mIntent = new Intent(context, RouterActivity.class);
|
|
|
|
mIntent.setData(Uri.parse(url));
|
2020-03-31 19:20:15 +02:00
|
|
|
mIntent.putExtra(RouterActivity.INTERNAL_ROUTE_KEY, true);
|
2019-03-02 00:42:06 +01:00
|
|
|
context.startActivity(mIntent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openAbout(final Context context) {
|
2017-09-03 08:04:18 +02:00
|
|
|
Intent intent = new Intent(context, AboutActivity.class);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void openSettings(final Context context) {
|
2017-09-03 08:04:18 +02:00
|
|
|
Intent intent = new Intent(context, SettingsActivity.class);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static boolean openDownloads(final Activity activity) {
|
|
|
|
if (!PermissionHelper.checkStoragePermissions(
|
|
|
|
activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
|
2019-08-15 04:00:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
Intent intent = new Intent(activity, DownloadActivity.class);
|
|
|
|
activity.startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-04 07:53:31 +01:00
|
|
|
public static Intent getBackgroundPlayerActivityIntent(final Context context) {
|
|
|
|
return getServicePlayerActivityIntent(context, BackgroundPlayerActivity.class);
|
2017-11-02 06:33:13 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 07:53:31 +01:00
|
|
|
private static Intent getServicePlayerActivityIntent(final Context context,
|
|
|
|
final Class activityClass) {
|
|
|
|
Intent intent = new Intent(context, activityClass);
|
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;
|
|
|
|
}
|
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) {
|
2017-04-09 19:34:00 +02:00
|
|
|
Intent mIntent = new Intent(context, MainActivity.class);
|
|
|
|
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-03-31 19:20:15 +02:00
|
|
|
public static Intent getIntentByLink(final Context context, final StreamingService service,
|
|
|
|
final String url) throws ExtractionException {
|
2017-09-03 08:04:18 +02:00
|
|
|
StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-23 01:40:00 +01:00
|
|
|
Intent rIntent = getOpenIntent(context, url, service.getServiceId(), linkType);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (linkType == StreamingService.LinkType.STREAM) {
|
|
|
|
rIntent.putExtra(VideoDetailFragment.AUTO_PLAY,
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
|
|
|
context.getString(R.string.autoplay_through_intent_key), false));
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
2017-07-04 09:31:53 +02:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
return rIntent;
|
2017-07-04 09:31:53 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static Uri openMarketUrl(final String packageName) {
|
2017-10-30 21:15:06 +01:00
|
|
|
return Uri.parse("market://details")
|
|
|
|
.buildUpon()
|
|
|
|
.appendQueryParameter("id", packageName)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static Uri getGooglePlayUrl(final String packageName) {
|
2017-10-30 21:15:06 +01:00
|
|
|
return Uri.parse("https://play.google.com/store/apps/details")
|
|
|
|
.buildUpon()
|
|
|
|
.appendQueryParameter("id", packageName)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static void installApp(final Context context, final String packageName) {
|
2017-10-30 21:15:06 +01:00
|
|
|
try {
|
|
|
|
// Try market:// scheme
|
|
|
|
context.startActivity(new Intent(Intent.ACTION_VIEW, openMarketUrl(packageName)));
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
// Fall back to google play URL (don't worry F-Droid can handle it :)
|
|
|
|
context.startActivity(new Intent(Intent.ACTION_VIEW, getGooglePlayUrl(packageName)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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) {
|
2017-10-30 21:15:06 +01:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setPackage(context.getString(R.string.kore_package));
|
|
|
|
intent.setData(videoURL);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|