|
|
|
|
@ -27,12 +27,14 @@ class CountdownScheduler { |
|
|
|
|
content.title = NSLocalizedString("It's time!", comment: "") |
|
|
|
|
|
|
|
|
|
let duration = countdown.duration |
|
|
|
|
let minutes = duration / 60.0 |
|
|
|
|
let body: String |
|
|
|
|
if let name = countdown.activity?.name { |
|
|
|
|
body = NSLocalizedString("Time's up for \(name)!", comment: "") |
|
|
|
|
} else { |
|
|
|
|
body = NSLocalizedString("Your \(duration.minuteSecond) countdown is over!", comment: "") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let minutesLabel = minutes > 1 ? NSLocalizedString("minutes", comment: "") : NSLocalizedString("minute", comment: "") |
|
|
|
|
let isOrAre = minutes > 1 ? NSLocalizedString("are", comment: "") : NSLocalizedString("is", comment: "") |
|
|
|
|
|
|
|
|
|
content.body = NSLocalizedString("The \(minutes) \(minutesLabel) \(isOrAre) over!", comment: "") |
|
|
|
|
content.body = body |
|
|
|
|
content.sound = UNNotificationSound.defaultCritical |
|
|
|
|
|
|
|
|
|
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: duration, repeats: false) |
|
|
|
|
@ -81,13 +83,17 @@ class AppEnvironment : ObservableObject { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func startCountdown(_ date: Date, countdown: Countdown) { |
|
|
|
|
let dateInterval = DateInterval(start: Date(), end: date) |
|
|
|
|
self.notificationDates[countdown.stringId] = dateInterval |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
let dateInterval = DateInterval(start: Date(), end: date) |
|
|
|
|
self.notificationDates[countdown.stringId] = dateInterval |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func endCountdown(countdownId: String) { |
|
|
|
|
self._recordActivityIfPossible(countdownId: countdownId) |
|
|
|
|
self.notificationDates.removeValue(forKey: countdownId) |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
self._recordActivityIfPossible(countdownId: countdownId) |
|
|
|
|
self.notificationDates.removeValue(forKey: countdownId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func cleanup() { |
|
|
|
|
|