Skip to content

Commit

Permalink
Deprecate and infer androidNotificationOngoing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Oct 13, 2021
1 parent baf0433 commit 5a6dd55
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,10 @@ private Notification buildNotification() {
final MediaStyle style = new MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(compactActionIndices);
if (config.androidNotificationOngoing) {
style.setShowCancelButton(true);
style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP));
builder.setOngoing(true);
}
boolean isActuallyPlaying = this.isActuallyPlaying();
style.setShowCancelButton(!isActuallyPlaying);
style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP));
builder.setOngoing(isActuallyPlaying);
builder.setStyle(style);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class AudioServiceConfig {
private static final String KEY_ANDROID_NOTIFICATION_ICON = "androidNotificationIcon";
private static final String KEY_ANDROID_SHOW_NOTIFICATION_BADGE = "androidShowNotificationBadge";
private static final String KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY = "androidNotificationClickStartsActivity";
private static final String KEY_ANDROID_NOTIFICATION_ONGOING = "androidNotificationOngoing";
private static final String KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE = "androidStopForegroundOnPause";
private static final String KEY_ART_DOWNSCALE_WIDTH = "artDownscaleWidth";
private static final String KEY_ART_DOWNSCALE_HEIGHT = "artDownscaleHeight";
Expand All @@ -33,7 +32,6 @@ public class AudioServiceConfig {
public String androidNotificationIcon;
public boolean androidShowNotificationBadge;
public boolean androidNotificationClickStartsActivity;
public boolean androidNotificationOngoing;
public boolean androidStopForegroundOnPause;
public int artDownscaleWidth;
public int artDownscaleHeight;
Expand All @@ -50,7 +48,6 @@ public AudioServiceConfig(Context context) {
androidNotificationIcon = preferences.getString(KEY_ANDROID_NOTIFICATION_ICON, "mipmap/ic_launcher");
androidShowNotificationBadge = preferences.getBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, false);
androidNotificationClickStartsActivity = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, true);
androidNotificationOngoing = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, false);
androidStopForegroundOnPause = preferences.getBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, true);
artDownscaleWidth = preferences.getInt(KEY_ART_DOWNSCALE_WIDTH, -1);
artDownscaleHeight = preferences.getInt(KEY_ART_DOWNSCALE_HEIGHT, -1);
Expand Down Expand Up @@ -109,7 +106,6 @@ public void save() {
.putString(KEY_ANDROID_NOTIFICATION_ICON, androidNotificationIcon)
.putBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, androidShowNotificationBadge)
.putBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, androidNotificationClickStartsActivity)
.putBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, androidNotificationOngoing)
.putBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, androidStopForegroundOnPause)
.putInt(KEY_ART_DOWNSCALE_WIDTH, artDownscaleWidth)
.putInt(KEY_ART_DOWNSCALE_HEIGHT, artDownscaleHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ public void onMethodCall(MethodCall call, final Result result) {
Map<?, ?> configMap = (Map<?, ?>)args.get("config");
AudioServiceConfig config = new AudioServiceConfig(context.getApplicationContext());
config.androidNotificationClickStartsActivity = (Boolean)configMap.get("androidNotificationClickStartsActivity");
config.androidNotificationOngoing = (Boolean)configMap.get("androidNotificationOngoing");
config.androidResumeOnClick = (Boolean)configMap.get("androidResumeOnClick");
config.androidNotificationChannelId = (String)configMap.get("androidNotificationChannelId");
config.androidNotificationChannelName = (String)configMap.get("androidNotificationChannelName");
Expand Down
1 change: 0 additions & 1 deletion audio_service/example/lib/example_multiple_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Future<void> main() async {
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
),
);
runApp(MyApp());
Expand Down
1 change: 0 additions & 1 deletion audio_service/example/lib/example_playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Future<void> main() async {
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
),
);
runApp(MyApp());
Expand Down
1 change: 0 additions & 1 deletion audio_service/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Future<void> main() async {
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
),
);
runApp(MyApp());
Expand Down
14 changes: 6 additions & 8 deletions audio_service/lib/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ class AudioService {
androidShowNotificationBadge: androidShowNotificationBadge,
androidNotificationClickStartsActivity:
androidNotificationClickStartsActivity,
androidNotificationOngoing: androidNotificationOngoing,
androidStopForegroundOnPause: androidStopForegroundOnPause,
artDownscaleWidth: androidArtDownscaleSize?.width.round(),
artDownscaleHeight: androidArtDownscaleSize?.height.round(),
Expand Down Expand Up @@ -3305,6 +3304,8 @@ class AudioServiceConfig {
/// If you set this to true, [androidStopForegroundOnPause] must be true as well,
/// otherwise this will not do anything, because when foreground service is active,
/// it forces notification to be ongoing.
@Deprecated(
"Ongoing is now automatically set when your handler is ready and playing")
final bool androidNotificationOngoing;

/// Whether the Android service should switch to a lower priority state when
Expand Down Expand Up @@ -3354,19 +3355,16 @@ class AudioServiceConfig {
this.androidNotificationIcon = 'mipmap/ic_launcher',
this.androidShowNotificationBadge = false,
this.androidNotificationClickStartsActivity = true,
this.androidNotificationOngoing = false,
@Deprecated("Ongoing is now automatically set when your handler is ready and playing")
this.androidNotificationOngoing = false,
this.androidStopForegroundOnPause = true,
this.artDownscaleWidth,
this.artDownscaleHeight,
this.fastForwardInterval = const Duration(seconds: 10),
this.rewindInterval = const Duration(seconds: 10),
this.preloadArtwork = false,
this.androidBrowsableRootExtras,
}) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null)),
assert(
!androidNotificationOngoing || androidStopForegroundOnPause,
'The androidNotificationOngoing will make no effect with androidStopForegroundOnPause set to false',
);
}) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null));

AudioServiceConfigMessage _toMessage() => AudioServiceConfigMessage(
androidResumeOnClick: androidResumeOnClick,
Expand All @@ -3379,7 +3377,7 @@ class AudioServiceConfig {
androidShowNotificationBadge: androidShowNotificationBadge,
androidNotificationClickStartsActivity:
androidNotificationClickStartsActivity,
androidNotificationOngoing: androidNotificationOngoing,
androidNotificationOngoing: false,
androidStopForegroundOnPause: androidStopForegroundOnPause,
artDownscaleWidth: artDownscaleWidth,
artDownscaleHeight: artDownscaleHeight,
Expand Down
14 changes: 0 additions & 14 deletions audio_service/test/data_classes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,4 @@ void main() {
);
});
});

group('$AudioServiceConfig $asciiSquare', () {
test('asserts proper notification ongoing config', () {
expect(
() {
AudioServiceConfig(
androidNotificationOngoing: true,
androidStopForegroundOnPause: false,
);
},
throwsAssertionError,
);
});
});
}

0 comments on commit 5a6dd55

Please sign in to comment.