Fix switching to main player when MainActivity is closed

This commit is contained in:
Stypox 2020-11-02 18:06:14 +01:00
parent 5a87cfc25d
commit 1b47a1a994
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
4 changed files with 18 additions and 4 deletions

View file

@ -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.

View file

@ -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

View file

@ -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;

View file

@ -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);