Dynamically sets time until alarm during addition.
This commit is contained in:
@@ -26,6 +26,7 @@ class AddAlarmViewController: UIViewController
|
||||
@IBOutlet weak var repeatWeekdaysSwitch: UISwitch!
|
||||
@IBOutlet weak var repeatWeekendsSwitch: UISwitch!
|
||||
@IBOutlet weak var alarmNameTextField: UITextField!
|
||||
@IBOutlet weak var timeTillAlarmLabel: UILabel!
|
||||
|
||||
@IBAction func defaultRingtonesButton(_ sender: Any)
|
||||
{
|
||||
@@ -37,6 +38,24 @@ class AddAlarmViewController: UIViewController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Called when the time for the alarm is changed.
|
||||
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)"
|
||||
}
|
||||
|
||||
/**
|
||||
Called when the user clicks the remove button and brings them back to the home page
|
||||
*/
|
||||
|
||||
@@ -438,6 +438,9 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="220" id="VCm-rY-H4H"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="alarmTimeUpdated:" destination="Mki-dC-5Kc" eventType="valueChanged" id="4e5-2Z-7gj"/>
|
||||
</connections>
|
||||
</datePicker>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Alarm Ringtone" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="O5c-Ga-0xh">
|
||||
<rect key="frame" x="0.0" y="228" width="374" height="20.5"/>
|
||||
@@ -596,6 +599,7 @@
|
||||
<outlet property="scrollView" destination="ybc-8d-6pJ" id="m1B-ff-zeC"/>
|
||||
<outlet property="scrollViewInner" destination="N7f-vi-SFU" id="LQW-6T-f6x"/>
|
||||
<outlet property="timePicker" destination="qSt-1V-2DQ" id="aDM-jE-0OP"/>
|
||||
<outlet property="timeTillAlarmLabel" destination="Xqs-n0-H9G" id="fg6-18-oAG"/>
|
||||
<outlet property="wvmPicker" destination="oae-b2-SoF" id="ADd-1r-iNM"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
|
||||
Reference in New Issue
Block a user