Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ enum class AlarmErrorCode(val raw: Int) {
data class AlarmSettingsWire (
val id: Long,
val millisecondsSinceEpoch: Long,
/**
* Path to the audio asset. If null, the device's default alarm sound
* will be used (Android only for now).
*/
val assetAudioPath: String? = null,
val volumeSettings: VolumeSettingsWire,
val notificationSettings: NotificationSettingsWire,
Expand Down Expand Up @@ -247,7 +243,8 @@ data class NotificationSettingsWire (
val iconColorAlpha: Double? = null,
val iconColorRed: Double? = null,
val iconColorGreen: Double? = null,
val iconColorBlue: Double? = null
val iconColorBlue: Double? = null,
val keepNotificationAfterAlarmEnds: Boolean
)
{
companion object {
Expand All @@ -260,7 +257,8 @@ data class NotificationSettingsWire (
val iconColorRed = pigeonVar_list[5] as Double?
val iconColorGreen = pigeonVar_list[6] as Double?
val iconColorBlue = pigeonVar_list[7] as Double?
return NotificationSettingsWire(title, body, stopButton, icon, iconColorAlpha, iconColorRed, iconColorGreen, iconColorBlue)
val keepNotificationAfterAlarmEnds = pigeonVar_list[8] as Boolean
return NotificationSettingsWire(title, body, stopButton, icon, iconColorAlpha, iconColorRed, iconColorGreen, iconColorBlue, keepNotificationAfterAlarmEnds)
}
}
fun toList(): List<Any?> {
Expand All @@ -273,6 +271,7 @@ data class NotificationSettingsWire (
iconColorRed,
iconColorGreen,
iconColorBlue,
keepNotificationAfterAlarmEnds,
)
}
override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ data class NotificationSettings(
val body: String,
val stopButton: String? = null,
val icon: String? = null,
val iconColor: Int? = null
val iconColor: Int? = null,
val keepNotificationAfterAlarmEnds: Boolean = false,
) {
companion object {
fun fromWire(e: NotificationSettingsWire): NotificationSettings {
Expand All @@ -30,6 +31,7 @@ data class NotificationSettings(
e.stopButton,
e.icon,
iconColor,
e.keepNotificationAfterAlarmEnds,
)
}
}
Expand Down
8 changes: 5 additions & 3 deletions ios/Classes/generated/FlutterBindings.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ enum AlarmErrorCode: Int {
struct AlarmSettingsWire: Hashable {
var id: Int64
var millisecondsSinceEpoch: Int64
/// Path to the audio asset. If null, the device's default alarm sound
/// will be used (Android only for now).
var assetAudioPath: String? = nil
var volumeSettings: VolumeSettingsWire
var notificationSettings: NotificationSettingsWire
Expand Down Expand Up @@ -295,6 +293,7 @@ struct NotificationSettingsWire: Hashable {
var iconColorRed: Double? = nil
var iconColorGreen: Double? = nil
var iconColorBlue: Double? = nil
var keepNotificationAfterAlarmEnds: Bool


// swift-format-ignore: AlwaysUseLowerCamelCase
Expand All @@ -307,6 +306,7 @@ struct NotificationSettingsWire: Hashable {
let iconColorRed: Double? = nilOrValue(pigeonVar_list[5])
let iconColorGreen: Double? = nilOrValue(pigeonVar_list[6])
let iconColorBlue: Double? = nilOrValue(pigeonVar_list[7])
let keepNotificationAfterAlarmEnds = pigeonVar_list[8] as! Bool

return NotificationSettingsWire(
title: title,
Expand All @@ -316,7 +316,8 @@ struct NotificationSettingsWire: Hashable {
iconColorAlpha: iconColorAlpha,
iconColorRed: iconColorRed,
iconColorGreen: iconColorGreen,
iconColorBlue: iconColorBlue
iconColorBlue: iconColorBlue,
keepNotificationAfterAlarmEnds: keepNotificationAfterAlarmEnds
)
}
func toList() -> [Any?] {
Expand All @@ -329,6 +330,7 @@ struct NotificationSettingsWire: Hashable {
iconColorRed,
iconColorGreen,
iconColorBlue,
keepNotificationAfterAlarmEnds,
]
}
static func == (lhs: NotificationSettingsWire, rhs: NotificationSettingsWire) -> Bool {
Expand Down
10 changes: 7 additions & 3 deletions ios/Classes/models/NotificationSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ struct NotificationSettings: Codable {
var title: String
var body: String
var stopButton: String?
var keepNotificationAfterAlarmEnds: Bool

static func from(wire: NotificationSettingsWire) -> NotificationSettings {
// NotificationSettingsWire.icon and iconColor values are ignored
// since we can't modify the notification icon on iOS.
return NotificationSettings(
title: wire.title,
body: wire.body,
stopButton: wire.stopButton
stopButton: wire.stopButton,
keepNotificationAfterAlarmEnds: wire.keepNotificationAfterAlarmEnds
)
}

static func fromJson(json: [String: Any]) -> NotificationSettings {
return NotificationSettings(
title: json["title"] as! String,
body: json["body"] as! String,
stopButton: json["stopButton"] as? String
stopButton: json["stopButton"] as? String,
keepNotificationAfterAlarmEnds: json["keepNotificationAfterAlarmEnds"] as? Bool ?? false
)
}

static func toJson(notificationSettings: NotificationSettings) -> [String: Any] {
return [
"title": notificationSettings.title,
"body": notificationSettings.body,
"stopButton": notificationSettings.stopButton as Any
"stopButton": notificationSettings.stopButton as Any,
"keepNotificationAfterAlarmEnds": notificationSettings.keepNotificationAfterAlarmEnds
]
}
}
12 changes: 11 additions & 1 deletion ios/Classes/services/AlarmManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ class AlarmManager: NSObject {
if cancelNotif {
NotificationManager.shared.cancelNotification(id: id)
}
NotificationManager.shared.dismissNotification(id: id)

// When the alarm stops automatically because the sound finished (non-looping
// alarms), we may want to keep the delivered notification so the user can
// still see it in the notification center. This is controlled by
// `NotificationSettings.keepNotificationAfterAlarmEnds`.
let shouldKeepDeliveredNotification =
!cancelNotif && (self.alarms[id]?.settings.notificationSettings.keepNotificationAfterAlarmEnds ?? false)

if !shouldKeepDeliveredNotification {
NotificationManager.shared.dismissNotification(id: id)
}

await AlarmRingManager.shared.stop()

Expand Down
27 changes: 26 additions & 1 deletion lib/model/notification_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class NotificationSettings extends Equatable {
this.stopButton,
this.icon,
this.iconColor,
this.keepNotificationAfterAlarmEnds = false,
});

/// Converts the JSON object to a `NotificationSettings` instance.
Expand Down Expand Up @@ -70,6 +71,19 @@ class NotificationSettings extends Equatable {
/// Defaults to `null`.
final Color? iconColor;

/// Keeps the notification banner visible even after the alarm sound ends.
///
/// **iOS only for now.** On Android, the notification already stays
/// visible after the sound ends because it is tied to the foreground
/// service.
///
/// If `true`, when the alarm finishes ringing automatically (non-looping
/// alarms), the delivered notification will not be dismissed so the user
/// can still see it in the notification center.
///
/// Defaults to `false`.
final bool keepNotificationAfterAlarmEnds;

/// Converts the `NotificationSettings` instance to a JSON object.
Map<String, dynamic> toJson() => _$NotificationSettingsToJson(this);

Expand All @@ -83,6 +97,7 @@ class NotificationSettings extends Equatable {
iconColorRed: iconColor?.r,
iconColorGreen: iconColor?.g,
iconColorBlue: iconColor?.b,
keepNotificationAfterAlarmEnds: keepNotificationAfterAlarmEnds,
);

/// Creates a copy of this notification settings but with the given fields
Expand All @@ -93,6 +108,7 @@ class NotificationSettings extends Equatable {
String? stopButton,
String? icon,
Color? iconColor,
bool? keepNotificationAfterAlarmEnds,
}) {
assert(title != null, 'NotificationSettings.title cannot be null');
assert(body != null, 'NotificationSettings.body cannot be null');
Expand All @@ -103,9 +119,18 @@ class NotificationSettings extends Equatable {
stopButton: stopButton ?? this.stopButton,
icon: icon ?? this.icon,
iconColor: iconColor ?? this.iconColor,
keepNotificationAfterAlarmEnds:
keepNotificationAfterAlarmEnds ?? this.keepNotificationAfterAlarmEnds,
);
}

@override
List<Object?> get props => [title, body, stopButton, icon, iconColor];
List<Object?> get props => [
title,
body,
stopButton,
icon,
iconColor,
keepNotificationAfterAlarmEnds,
];
}
11 changes: 11 additions & 0 deletions lib/model/notification_settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/src/generated/platform_bindings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class AlarmSettingsWire {

int millisecondsSinceEpoch;

/// Path to the audio asset. If null, the device's default alarm sound
/// will be used (Android only for now).
String? assetAudioPath;

VolumeSettingsWire volumeSettings;
Expand Down Expand Up @@ -271,6 +269,7 @@ class NotificationSettingsWire {
this.iconColorRed,
this.iconColorGreen,
this.iconColorBlue,
required this.keepNotificationAfterAlarmEnds,
});

String title;
Expand All @@ -289,6 +288,8 @@ class NotificationSettingsWire {

double? iconColorBlue;

bool keepNotificationAfterAlarmEnds;

List<Object?> _toList() {
return <Object?>[
title,
Expand All @@ -299,6 +300,7 @@ class NotificationSettingsWire {
iconColorRed,
iconColorGreen,
iconColorBlue,
keepNotificationAfterAlarmEnds,
];
}

Expand All @@ -317,6 +319,7 @@ class NotificationSettingsWire {
iconColorRed: result[5] as double?,
iconColorGreen: result[6] as double?,
iconColorBlue: result[7] as double?,
keepNotificationAfterAlarmEnds: result[8]! as bool,
);
}

Expand Down
2 changes: 2 additions & 0 deletions pigeons/alarm_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class NotificationSettingsWire {
required this.iconColorRed,
required this.iconColorGreen,
required this.iconColorBlue,
required this.keepNotificationAfterAlarmEnds,
});

final String title;
Expand All @@ -89,6 +90,7 @@ class NotificationSettingsWire {
final double? iconColorRed;
final double? iconColorGreen;
final double? iconColorBlue;
final bool keepNotificationAfterAlarmEnds;
}

/// Errors that can occur when interacting with the Alarm API.
Expand Down