diff --git a/ProjectClock/AlarmActivator.swift b/ProjectClock/AlarmActivator.swift index 16fee0f..21820e0 100644 --- a/ProjectClock/AlarmActivator.swift +++ b/ProjectClock/AlarmActivator.swift @@ -22,6 +22,9 @@ class AlarmActivator: UITabBarController var timer: Timer? var alarm: Alarm? + /// Timer for getting family alarm updates + var familyTimer: Timer? + override func viewDidLoad() { start() @@ -34,6 +37,7 @@ class AlarmActivator: UITabBarController { if timer != nil { return } timer = Timer.scheduledTimer(timeInterval: AlarmActivator.interval, target: self, selector: #selector(AlarmActivator.check), userInfo: nil, repeats: true) + familyTimer = Timer.scheduledTimer(timeInterval: 30.0, target: self, selector: #selector(AlarmActivator.checkFamily), userInfo: nil, repeats: true) } /** @@ -69,7 +73,28 @@ class AlarmActivator: UITabBarController performSegue(withIdentifier: "activate-alarm", sender: alarm) } - @IBSegueAction func sendAlarm(_ coder: NSCoder) -> AlarmActivationViewController? { + @IBSegueAction func sendAlarm(_ coder: NSCoder) -> AlarmActivationViewController? + { return AlarmActivationViewController(coder: coder, currentAlarm: alarm!) } + + /** + Check family alarm updates + */ + @objc func checkFamily() + { + send(APIs.familyAlarmUpdates) + { + let alarms = Alarms.fromLocal() + $0.components(separatedBy: ",").forEach + { + guard let alarm = JSON.parse(Alarm.self, $0) else { return } + if (!alarms.list.contains { $0.timeText == alarm.timeText }) + { + alarms.list.append(alarm) + } + } + alarms.localSave() + } + } } diff --git a/ProjectClock/Net.swift b/ProjectClock/Net.swift index 1a19ff3..896539f 100644 --- a/ProjectClock/Net.swift +++ b/ProjectClock/Net.swift @@ -151,14 +151,12 @@ class APIs Get updates about alarms that other family members added ## Parameters (Besides from username and password) - - fid: Family ID - - pin: Admin pin - - action: get_alarm_updates + None ## Returns Alarm updates */ - static let familyAlarmUpdates = API(loc: "/family/action") + static let familyAlarmUpdates = API(loc: "/family/get_alarm_updates") /** Add alarm to a family member