Fix switching to main player when MainActivity is closed
This commit is contained in:
parent
5a87cfc25d
commit
1b47a1a994
4 changed files with 18 additions and 4 deletions
|
@ -88,6 +88,7 @@ import org.schabi.newpipe.views.FocusOverlayView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||||
|
|
||||||
|
@ -822,15 +823,23 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openMiniPlayerUponPlayerStarted() {
|
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()) {
|
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();
|
openMiniPlayerIfMissing();
|
||||||
} else {
|
} else {
|
||||||
// listen for player intents being sent around
|
// listen for player start intent being sent around
|
||||||
broadcastReceiver = new BroadcastReceiver() {
|
broadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, final Intent intent) {
|
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();
|
openMiniPlayerIfMissing();
|
||||||
// At this point the player is added 100%, we can unregister. Other actions
|
// At this point the player is added 100%, we can unregister. Other actions
|
||||||
// are useless since the fragment will not be removed after that.
|
// are useless since the fragment will not be removed after that.
|
||||||
|
|
|
@ -1111,7 +1111,9 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
// Video view can have elements visible from popup,
|
// Video view can have elements visible from popup,
|
||||||
// We hide it here but once it ready the view will be shown in handleIntent()
|
// We hide it here but once it ready the view will be shown in handleIntent()
|
||||||
|
if (playerService.getView() != null) {
|
||||||
playerService.getView().setVisibility(View.GONE);
|
playerService.getView().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
addVideoPlayerView();
|
addVideoPlayerView();
|
||||||
|
|
||||||
final Intent playerIntent = NavigationHelper
|
final Intent playerIntent = NavigationHelper
|
||||||
|
|
|
@ -30,6 +30,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
@ -231,6 +232,7 @@ public final class MainPlayer extends Service {
|
||||||
return metrics.heightPixels < metrics.widthPixels;
|
return metrics.heightPixels < metrics.widthPixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public View getView() {
|
public View getView() {
|
||||||
if (playerImpl == null) {
|
if (playerImpl == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -486,6 +486,7 @@ public final class NavigationHelper {
|
||||||
|
|
||||||
final Intent intent = getOpenIntent(context, url, serviceId,
|
final Intent intent = getOpenIntent(context, url, serviceId,
|
||||||
StreamingService.LinkType.STREAM);
|
StreamingService.LinkType.STREAM);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.putExtra(Constants.KEY_TITLE, title);
|
intent.putExtra(Constants.KEY_TITLE, title);
|
||||||
intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers);
|
intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue