From 6bea4aa96b46dd5513c323b1e5d674120437229b Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 27 Jan 2018 00:55:28 -0200 Subject: [PATCH] Fix player switching - Background to popup wasn't asking for permission - The new task flag is needed to switch from the background/popup UI to the main player --- .../schabi/newpipe/player/BackgroundPlayerActivity.java | 7 +++++++ .../java/org/schabi/newpipe/player/MainVideoPlayer.java | 8 ++------ .../org/schabi/newpipe/player/ServicePlayerActivity.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java index de711f9ac..761b50d85 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.view.MenuItem; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.PermissionHelper; import static org.schabi.newpipe.player.BackgroundPlayer.ACTION_CLOSE; @@ -48,6 +49,12 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity { @Override public boolean onPlayerOptionSelected(MenuItem item) { if (item.getItemId() == R.id.action_switch_popup) { + + if (!PermissionHelper.isPopupEnabled(this)) { + PermissionHelper.showPopupEnablementToast(this); + return true; + } + this.player.setRecovery(); getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class)); diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 2ec0dc14f..8081dcad7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -25,7 +25,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; -import android.content.res.Resources; import android.graphics.Color; import android.media.AudioManager; import android.os.Build; @@ -65,8 +64,6 @@ import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.PopupMenuIconHacker; import org.schabi.newpipe.util.ThemeHelper; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.List; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -400,9 +397,8 @@ public final class MainVideoPlayer extends Activity { if (DEBUG) Log.d(TAG, "onFullScreenButtonClicked() called"); if (simpleExoPlayer == null) return; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && !PermissionHelper.checkSystemAlertWindowPermission(MainVideoPlayer.this)) { - Toast.makeText(MainVideoPlayer.this, R.string.msg_popup_permission, Toast.LENGTH_LONG).show(); + if (!PermissionHelper.isPopupEnabled(context)) { + PermissionHelper.showPopupEnablementToast(context); return; } diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 58c117017..4165dc087 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -183,7 +183,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity this.player.getPlaybackSpeed(), this.player.getPlaybackPitch(), null - ); + ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } //////////////////////////////////////////////////////////////////////////// // Service Connection