1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

Merge pull request #9671 from Stypox/fix-toast-crash-api33

Fix popup enablement toast crash on API 33
This commit is contained in:
Stypox 2023-01-15 21:05:05 +01:00 committed by GitHub
commit abe6dfb99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 25 deletions

View File

@ -631,8 +631,7 @@ public class RouterActivity extends AppCompatActivity {
} }
if (selectedChoiceKey.equals(getString(R.string.popup_player_key)) if (selectedChoiceKey.equals(getString(R.string.popup_player_key))
&& !PermissionHelper.isPopupEnabled(this)) { && !PermissionHelper.isPopupEnabledElseAsk(this)) {
PermissionHelper.showPopupEnablementToast(this);
finish(); finish();
return; return;
} }

View File

@ -1068,8 +1068,7 @@ public final class VideoDetailFragment
} }
private void openPopupPlayer(final boolean append) { private void openPopupPlayer(final boolean append) {
if (!PermissionHelper.isPopupEnabled(activity)) { if (!PermissionHelper.isPopupEnabledElseAsk(activity)) {
PermissionHelper.showPopupEnablementToast(activity);
return; return;
} }

View File

@ -143,11 +143,9 @@ public final class PlayQueueActivity extends AppCompatActivity
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true); NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
return true; return true;
case R.id.action_switch_popup: case R.id.action_switch_popup:
if (PermissionHelper.isPopupEnabled(this)) { if (PermissionHelper.isPopupEnabledElseAsk(this)) {
this.player.setRecovery(); this.player.setRecovery();
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true); NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
} else {
PermissionHelper.showPopupEnablementToast(this);
} }
return true; return true;
case R.id.action_switch_background: case R.id.action_switch_background:

View File

@ -156,8 +156,7 @@ public final class NavigationHelper {
public static void playOnPopupPlayer(final Context context, public static void playOnPopupPlayer(final Context context,
final PlayQueue queue, final PlayQueue queue,
final boolean resumePlayback) { final boolean resumePlayback) {
if (!PermissionHelper.isPopupEnabled(context)) { if (!PermissionHelper.isPopupEnabledElseAsk(context)) {
PermissionHelper.showPopupEnablementToast(context);
return; return;
} }
@ -183,8 +182,7 @@ public final class NavigationHelper {
public static void enqueueOnPlayer(final Context context, public static void enqueueOnPlayer(final Context context,
final PlayQueue queue, final PlayQueue queue,
final PlayerType playerType) { final PlayerType playerType) {
if ((playerType == PlayerType.POPUP) && !PermissionHelper.isPopupEnabled(context)) { if (playerType == PlayerType.POPUP && !PermissionHelper.isPopupEnabledElseAsk(context)) {
PermissionHelper.showPopupEnablementToast(context);
return; return;
} }

View File

@ -9,8 +9,6 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@ -128,18 +126,21 @@ public final class PermissionHelper {
} }
} }
public static boolean isPopupEnabled(final Context context) { /**
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M * Determines whether the popup is enabled, and if it is not, starts the system activity to
|| checkSystemAlertWindowPermission(context); * request the permission with {@link #checkSystemAlertWindowPermission(Context)} and shows a
} * toast to the user explaining why the permission is needed.
*
public static void showPopupEnablementToast(final Context context) { * @param context the Android context
final Toast toast = * @return whether the popup is enabled
Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG); */
final TextView messageView = toast.getView().findViewById(android.R.id.message); public static boolean isPopupEnabledElseAsk(final Context context) {
if (messageView != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
messageView.setGravity(Gravity.CENTER); || checkSystemAlertWindowPermission(context)) {
return true;
} else {
Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
return false;
} }
toast.show();
} }
} }