From 4678297ec3bb13238abaadf5737f0288d1f62c23 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 30 Aug 2019 10:39:23 +0200 Subject: Added button to always allow streaming --- .../core/service/playback/PlaybackService.java | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'core/src/main/java') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 197302ed2..4ba33919a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -98,6 +98,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { */ public static final String EXTRA_SHOULD_STREAM = "extra.de.danoeh.antennapod.core.service.shouldStream"; public static final String EXTRA_ALLOW_STREAM_THIS_TIME = "extra.de.danoeh.antennapod.core.service.allowStream"; + public static final String EXTRA_ALLOW_STREAM_ALWAYS = "extra.de.danoeh.antennapod.core.service.allowStreamAlways"; /** * True if playback should be started immediately after media has been * prepared. @@ -453,6 +454,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { startForeground(NOTIFICATION_ID, notificationBuilder.build()); } + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); + notificationManager.cancel(NOTIFICATION_ID_STREAMING); + final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1); final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false); Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE); @@ -477,6 +481,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { stateManager.validStartCommandWasReceived(); boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, true); boolean allowStreamThisTime = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false); + boolean allowStreamAlways = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false); boolean startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false); boolean prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false); sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); @@ -485,6 +490,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (playable instanceof FeedMedia) { playable = DBReader.getFeedMedia(((FeedMedia) playable).getId()); } + if (allowStreamAlways) { + UserPreferences.setAllowMobileStreaming(true); + } if (stream && !NetworkUtils.isStreamingAllowed() && !allowStreamThisTime) { displayStreamingNotAllowedNotification(intent); writePlaybackPreferencesNoMediaPlaying(); @@ -502,13 +510,22 @@ public class PlaybackService extends MediaBrowserServiceCompat { } private void displayStreamingNotAllowedNotification(Intent originalIntent) { - Intent intent = new Intent(originalIntent); - intent.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); - PendingIntent pendingIntent; + Intent intentAllowThisTime = new Intent(originalIntent); + intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); + PendingIntent pendingIntentAllowThisTime; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + } else { + pendingIntentAllowThisTime = PendingIntent.getService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + } + + Intent intentAlwaysAllow = new Intent(intentAllowThisTime); + intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true); + PendingIntent pendingIntentAlwaysAllow; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntent = PendingIntent.getForegroundService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION) @@ -518,7 +535,13 @@ public class PlaybackService extends MediaBrowserServiceCompat { .setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.confirm_mobile_streaming_notification_message))) .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .setContentIntent(pendingIntent) + .setContentIntent(pendingIntentAllowThisTime) + .addAction(R.drawable.stat_notify_sync_error, + getString(R.string.stream_label), + pendingIntentAllowThisTime) + .addAction(R.drawable.stat_notify_sync_error, + getString(R.string.confirm_mobile_streaming_button_always), + pendingIntentAlwaysAllow) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID_STREAMING, builder.build()); -- cgit v1.2.3