summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-08-30 10:39:23 +0200
committerByteHamster <info@bytehamster.com>2019-08-30 13:07:58 +0200
commit4678297ec3bb13238abaadf5737f0288d1f62c23 (patch)
tree92d8881b20be7ef2332058fac8507c215a6d5581
parente6ad131d3737dbc13d25195b8ce0ec13e561307d (diff)
downloadAntennaPod-4678297ec3bb13238abaadf5737f0288d1f62c23.zip
Added button to always allow streaming
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java35
-rw-r--r--core/src/main/res/values/strings.xml1
2 files changed, 30 insertions, 6 deletions
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());
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index a4084b76b..3afe5a30d 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -267,6 +267,7 @@
<string name="confirm_mobile_download_dialog_message">Downloading over mobile data connection is disabled in the settings.\n\nDo you want to allow downloading temporarily?\n\n<small>Your choice will be remembered for 10 minutes.</small></string>
<string name="confirm_mobile_streaming_notification_title">Confirm Mobile streaming</string>
<string name="confirm_mobile_streaming_notification_message">Streaming over mobile data connection is disabled in the settings. Tap to stream anyway.</string>
+ <string name="confirm_mobile_streaming_button_always">Always allow</string>
<string name="confirm_mobile_download_dialog_only_add_to_queue">Enqueue</string>
<string name="confirm_mobile_download_dialog_enable_temporarily">Allow temporarily</string>