Dyamically updates ETA on any modification in AddAlarm
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -515,6 +515,9 @@
|
||||
</label>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5oN-BL-Xtu">
|
||||
<rect key="frame" x="285" y="0.0" width="51" height="31"/>
|
||||
<connections>
|
||||
<action selector="alarmTimeUpdated:" destination="Mki-dC-5Kc" eventType="valueChanged" id="KrO-lK-2lG"/>
|
||||
</connections>
|
||||
</switch>
|
||||
</subviews>
|
||||
</stackView>
|
||||
@@ -529,6 +532,9 @@
|
||||
</label>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WPM-Fh-sRB">
|
||||
<rect key="frame" x="285" y="0.0" width="51" height="31"/>
|
||||
<connections>
|
||||
<action selector="alarmTimeUpdated:" destination="Mki-dC-5Kc" eventType="valueChanged" id="FGC-Oc-gFj"/>
|
||||
</connections>
|
||||
</switch>
|
||||
</subviews>
|
||||
</stackView>
|
||||
|
||||
Reference in New Issue
Block a user