Dyamically updates ETA on any modification in AddAlarm

This commit is contained in:
Aaron
2021-01-24 16:38:50 -05:00
parent fb2b92c381
commit 90ba42d7f7
2 changed files with 28 additions and 11 deletions
+22 -11
View File
@@ -43,19 +43,10 @@ class AddAlarmViewController: UIViewController
Sets the time away at the top of the View. Sets the time away at the top of the View.
*/ */
@IBAction func alarmTimeUpdated(_ sender: Any) { @IBAction func alarmTimeUpdated(_ sender: Any) {
//Create alarm without adding it to the queue. updateETA()
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)"
} }
/** /**
Called when the user clicks the remove button and brings them back to the home page 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 // Dismiss this view
self.dismiss(animated: true, completion: nil) 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 class WVMDataSource: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource
+6
View File
@@ -515,6 +515,9 @@
</label> </label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5oN-BL-Xtu"> <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"/> <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> </switch>
</subviews> </subviews>
</stackView> </stackView>
@@ -529,6 +532,9 @@
</label> </label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WPM-Fh-sRB"> <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"/> <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> </switch>
</subviews> </subviews>
</stackView> </stackView>