From 1b47a1a994e009a298f12ad6570d2565cb49b7dd Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 2 Nov 2020 18:06:14 +0100 Subject: [PATCH] Fix switching to main player when MainActivity is closed --- .../java/org/schabi/newpipe/MainActivity.java | 15 ++++++++++++--- .../fragments/detail/VideoDetailFragment.java | 4 +++- .../org/schabi/newpipe/player/MainPlayer.java | 2 ++ .../org/schabi/newpipe/util/NavigationHelper.java | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 84235d4fb..9bcbe4ff1 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -88,6 +88,7 @@ import org.schabi.newpipe.views.FocusOverlayView; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; @@ -822,15 +823,23 @@ public class MainActivity extends AppCompatActivity { } private void openMiniPlayerUponPlayerStarted() { + if (getIntent().getSerializableExtra(Constants.KEY_LINK_TYPE) + == StreamingService.LinkType.STREAM) { + // handleIntent() already takes care of opening video detail fragment + // due to an intent containing a STREAM link + return; + } + if (PlayerHolder.isPlayerOpen()) { - // no need for a broadcast receiver if the player is already open + // if the player is already open, no need for a broadcast receiver openMiniPlayerIfMissing(); } else { - // listen for player intents being sent around + // listen for player start intent being sent around broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { - if (intent.getAction().equals(VideoDetailFragment.ACTION_PLAYER_STARTED)) { + if (Objects.equals(intent.getAction(), + VideoDetailFragment.ACTION_PLAYER_STARTED)) { openMiniPlayerIfMissing(); // At this point the player is added 100%, we can unregister. Other actions // are useless since the fragment will not be removed after that. diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 92032986d..3296f5bf8 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1111,7 +1111,9 @@ public final class VideoDetailFragment // Video view can have elements visible from popup, // We hide it here but once it ready the view will be shown in handleIntent() - playerService.getView().setVisibility(View.GONE); + if (playerService.getView() != null) { + playerService.getView().setVisibility(View.GONE); + } addVideoPlayerView(); final Intent playerIntent = NavigationHelper diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java index 07ca7b339..63f6a400e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -30,6 +30,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import org.schabi.newpipe.R; @@ -231,6 +232,7 @@ public final class MainPlayer extends Service { return metrics.heightPixels < metrics.widthPixels; } + @Nullable public View getView() { if (playerImpl == null) { return null; diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 3c791d44d..b45a1e7b9 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -486,6 +486,7 @@ public final class NavigationHelper { final Intent intent = getOpenIntent(context, url, serviceId, StreamingService.LinkType.STREAM); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Constants.KEY_TITLE, title); intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers);