Skip to content

Commit 6e49376

Browse files
committed
Deprecate and infer androidNotificationOngoing.
1 parent e6ce459 commit 6e49376

File tree

8 files changed

+10
-35
lines changed

8 files changed

+10
-35
lines changed

audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,10 @@ private Notification buildNotification() {
490490
final MediaStyle style = new MediaStyle()
491491
.setMediaSession(mediaSession.getSessionToken())
492492
.setShowActionsInCompactView(compactActionIndices);
493-
if (config.androidNotificationOngoing) {
494-
style.setShowCancelButton(true);
495-
style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP));
496-
builder.setOngoing(true);
497-
}
493+
boolean isActuallyPlaying = this.isActuallyPlaying();
494+
style.setShowCancelButton(!isActuallyPlaying);
495+
style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP));
496+
builder.setOngoing(isActuallyPlaying);
498497
builder.setStyle(style);
499498
return builder.build();
500499
}

audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServiceConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class AudioServiceConfig {
1717
private static final String KEY_ANDROID_NOTIFICATION_ICON = "androidNotificationIcon";
1818
private static final String KEY_ANDROID_SHOW_NOTIFICATION_BADGE = "androidShowNotificationBadge";
1919
private static final String KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY = "androidNotificationClickStartsActivity";
20-
private static final String KEY_ANDROID_NOTIFICATION_ONGOING = "androidNotificationOngoing";
2120
private static final String KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE = "androidStopForegroundOnPause";
2221
private static final String KEY_ART_DOWNSCALE_WIDTH = "artDownscaleWidth";
2322
private static final String KEY_ART_DOWNSCALE_HEIGHT = "artDownscaleHeight";
@@ -33,7 +32,6 @@ public class AudioServiceConfig {
3332
public String androidNotificationIcon;
3433
public boolean androidShowNotificationBadge;
3534
public boolean androidNotificationClickStartsActivity;
36-
public boolean androidNotificationOngoing;
3735
public boolean androidStopForegroundOnPause;
3836
public int artDownscaleWidth;
3937
public int artDownscaleHeight;
@@ -50,7 +48,6 @@ public AudioServiceConfig(Context context) {
5048
androidNotificationIcon = preferences.getString(KEY_ANDROID_NOTIFICATION_ICON, "mipmap/ic_launcher");
5149
androidShowNotificationBadge = preferences.getBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, false);
5250
androidNotificationClickStartsActivity = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, true);
53-
androidNotificationOngoing = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, false);
5451
androidStopForegroundOnPause = preferences.getBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, true);
5552
artDownscaleWidth = preferences.getInt(KEY_ART_DOWNSCALE_WIDTH, -1);
5653
artDownscaleHeight = preferences.getInt(KEY_ART_DOWNSCALE_HEIGHT, -1);
@@ -109,7 +106,6 @@ public void save() {
109106
.putString(KEY_ANDROID_NOTIFICATION_ICON, androidNotificationIcon)
110107
.putBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, androidShowNotificationBadge)
111108
.putBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, androidNotificationClickStartsActivity)
112-
.putBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, androidNotificationOngoing)
113109
.putBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, androidStopForegroundOnPause)
114110
.putInt(KEY_ART_DOWNSCALE_WIDTH, artDownscaleWidth)
115111
.putInt(KEY_ART_DOWNSCALE_HEIGHT, artDownscaleHeight)

audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ public void onMethodCall(MethodCall call, final Result result) {
414414
Map<?, ?> configMap = (Map<?, ?>)args.get("config");
415415
AudioServiceConfig config = new AudioServiceConfig(context.getApplicationContext());
416416
config.androidNotificationClickStartsActivity = (Boolean)configMap.get("androidNotificationClickStartsActivity");
417-
config.androidNotificationOngoing = (Boolean)configMap.get("androidNotificationOngoing");
418417
config.androidResumeOnClick = (Boolean)configMap.get("androidResumeOnClick");
419418
config.androidNotificationChannelId = (String)configMap.get("androidNotificationChannelId");
420419
config.androidNotificationChannelName = (String)configMap.get("androidNotificationChannelName");

audio_service/example/lib/example_multiple_handlers.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Future<void> main() async {
4747
config: const AudioServiceConfig(
4848
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
4949
androidNotificationChannelName: 'Audio playback',
50-
androidNotificationOngoing: true,
5150
),
5251
);
5352
runApp(MyApp());

audio_service/example/lib/example_playlist.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Future<void> main() async {
2626
config: const AudioServiceConfig(
2727
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
2828
androidNotificationChannelName: 'Audio playback',
29-
androidNotificationOngoing: true,
3029
),
3130
);
3231
runApp(MyApp());

audio_service/example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Future<void> main() async {
3636
config: const AudioServiceConfig(
3737
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
3838
androidNotificationChannelName: 'Audio playback',
39-
androidNotificationOngoing: true,
4039
),
4140
);
4241
runApp(MyApp());

audio_service/lib/audio_service.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,6 @@ class AudioService {
12281228
androidShowNotificationBadge: androidShowNotificationBadge,
12291229
androidNotificationClickStartsActivity:
12301230
androidNotificationClickStartsActivity,
1231-
androidNotificationOngoing: androidNotificationOngoing,
12321231
androidStopForegroundOnPause: androidStopForegroundOnPause,
12331232
artDownscaleWidth: androidArtDownscaleSize?.width.round(),
12341233
artDownscaleHeight: androidArtDownscaleSize?.height.round(),
@@ -3305,6 +3304,8 @@ class AudioServiceConfig {
33053304
/// If you set this to true, [androidStopForegroundOnPause] must be true as well,
33063305
/// otherwise this will not do anything, because when foreground service is active,
33073306
/// it forces notification to be ongoing.
3307+
@Deprecated(
3308+
"Ongoing is now automatically set when your handler is ready and playing")
33083309
final bool androidNotificationOngoing;
33093310

33103311
/// Whether the Android service should switch to a lower priority state when
@@ -3354,19 +3355,16 @@ class AudioServiceConfig {
33543355
this.androidNotificationIcon = 'mipmap/ic_launcher',
33553356
this.androidShowNotificationBadge = false,
33563357
this.androidNotificationClickStartsActivity = true,
3357-
this.androidNotificationOngoing = false,
3358+
@Deprecated("Ongoing is now automatically set when your handler is ready and playing")
3359+
this.androidNotificationOngoing = false,
33583360
this.androidStopForegroundOnPause = true,
33593361
this.artDownscaleWidth,
33603362
this.artDownscaleHeight,
33613363
this.fastForwardInterval = const Duration(seconds: 10),
33623364
this.rewindInterval = const Duration(seconds: 10),
33633365
this.preloadArtwork = false,
33643366
this.androidBrowsableRootExtras,
3365-
}) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null)),
3366-
assert(
3367-
!androidNotificationOngoing || androidStopForegroundOnPause,
3368-
'The androidNotificationOngoing will make no effect with androidStopForegroundOnPause set to false',
3369-
);
3367+
}) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null));
33703368

33713369
AudioServiceConfigMessage _toMessage() => AudioServiceConfigMessage(
33723370
androidResumeOnClick: androidResumeOnClick,
@@ -3379,7 +3377,7 @@ class AudioServiceConfig {
33793377
androidShowNotificationBadge: androidShowNotificationBadge,
33803378
androidNotificationClickStartsActivity:
33813379
androidNotificationClickStartsActivity,
3382-
androidNotificationOngoing: androidNotificationOngoing,
3380+
androidNotificationOngoing: false,
33833381
androidStopForegroundOnPause: androidStopForegroundOnPause,
33843382
artDownscaleWidth: artDownscaleWidth,
33853383
artDownscaleHeight: artDownscaleHeight,

audio_service/test/data_classes_test.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,4 @@ void main() {
357357
);
358358
});
359359
});
360-
361-
group('$AudioServiceConfig $asciiSquare', () {
362-
test('asserts proper notification ongoing config', () {
363-
expect(
364-
() {
365-
AudioServiceConfig(
366-
androidNotificationOngoing: true,
367-
androidStopForegroundOnPause: false,
368-
);
369-
},
370-
throwsAssertionError,
371-
);
372-
});
373-
});
374360
}

0 commit comments

Comments
 (0)