diff --git a/ProjectClock/AddAlarmViewController.swift b/ProjectClock/AddAlarmViewController.swift
index e8efce5..d6ad026 100644
--- a/ProjectClock/AddAlarmViewController.swift
+++ b/ProjectClock/AddAlarmViewController.swift
@@ -43,19 +43,10 @@ class AddAlarmViewController: UIViewController
Sets the time away at the top of the View.
*/
@IBAction func alarmTimeUpdated(_ sender: Any) {
- //Create alarm without adding it to the queue.
- let (h, m, _) = timePicker.date.getHMS()
-
- // Create the alarm
- let a = Alarm(hour: h, minute: m,
- text: alarmNameTextField.text ?? "Alarm",
- wakeMethod: wvms[wvmPicker.selectedRow(inComponent: 0)],
- lastActivate: Date())
- var timeTill = a.nextActivate!.timeIntervalSince(Date()).str()
- print(timeTill)
- timeTillAlarmLabel.text = "Going off in \(timeTill)"
+ updateETA()
}
+
/**
Called when the user clicks the remove button and brings them back to the home page
*/
@@ -95,6 +86,26 @@ class AddAlarmViewController: UIViewController
// Dismiss this view
self.dismiss(animated: true, completion: nil)
}
+
+ // Dynamically the ETA label for the alarm
+ func updateETA() {
+ //Create alarm without adding it to the queue.
+ let (h, m, _) = timePicker.date.getHMS()
+
+ // Create the alarm
+ let a = Alarm(hour: h, minute: m,
+ text: alarmNameTextField.text ?? "Alarm",
+ wakeMethod: wvms[wvmPicker.selectedRow(inComponent: 0)],
+ lastActivate: Date())
+ // Set alarm.repeats to correspond with what the user selects
+ (0...6).forEach { a.repeats[$0] = false }
+ if repeatWeekdaysSwitch.isOn { (1...5).forEach { a.repeats[$0] = true } }
+ if repeatWeekendsSwitch.isOn { [0, 6].forEach { a.repeats[$0] = true } }
+
+ let timeTill = a.nextActivate!.timeIntervalSince(Date()).str()
+ //print(timeTill)
+ timeTillAlarmLabel.text = "Going off in \(timeTill)"
+ }
}
class WVMDataSource: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource
diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard
index 0553771..1403bf7 100644
--- a/ProjectClock/Base.lproj/Main.storyboard
+++ b/ProjectClock/Base.lproj/Main.storyboard
@@ -515,6 +515,9 @@
+
+
+
@@ -529,6 +532,9 @@
+
+
+