[+] Implement adding alarms sent by family members

This commit is contained in:
Hykilpikonna
2021-01-26 18:06:40 -05:00
parent ddc47e8679
commit 3bb39b0027
2 changed files with 28 additions and 5 deletions
+26 -1
View File
@@ -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()
}
}
}
+2 -4
View File
@@ -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<String>(loc: "/family/action")
static let familyAlarmUpdates = API<String>(loc: "/family/get_alarm_updates")
/**
Add alarm to a family member