Alarms with the same time, but different repeats/title can be added.
This commit is contained in:
@@ -130,17 +130,6 @@ class AddAlarmViewController: UIViewController
|
|||||||
let (h, m, _) = timePicker.date.getHMS()
|
let (h, m, _) = timePicker.date.getHMS()
|
||||||
var oldAlarm: Alarm? = nil
|
var oldAlarm: Alarm? = nil
|
||||||
|
|
||||||
// Check if editing alarm
|
|
||||||
if (editFlag)
|
|
||||||
{
|
|
||||||
oldAlarm = removeCurrentAlarm()
|
|
||||||
} // Check for existing alarm
|
|
||||||
else if ((Alarms.fromLocal().list.contains { $0.hour == h && $0.minute == m }))
|
|
||||||
{
|
|
||||||
msg("Nope", "You already have an alarm at " + String(format: "%i:%02i", h, m))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the alarm
|
// Create the alarm
|
||||||
let alarm = Alarm(hour: h, minute: m,
|
let alarm = Alarm(hour: h, minute: m,
|
||||||
text: alarmNameTextField.text ?? "Alarm",
|
text: alarmNameTextField.text ?? "Alarm",
|
||||||
@@ -152,6 +141,21 @@ class AddAlarmViewController: UIViewController
|
|||||||
if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } }
|
if repeatWeekdaysSwitch.isOn { (1...5).forEach { alarm.repeats[$0] = true } }
|
||||||
if repeatWeekendsSwitch.isOn { [0, 6].forEach { alarm.repeats[$0] = true } }
|
if repeatWeekendsSwitch.isOn { [0, 6].forEach { alarm.repeats[$0] = true } }
|
||||||
|
|
||||||
|
// Check if editing alarm
|
||||||
|
if (editFlag)
|
||||||
|
{
|
||||||
|
oldAlarm = removeCurrentAlarm()
|
||||||
|
} // Check for existing alarm
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for a in Alarms.fromLocal().list {
|
||||||
|
if a == alarm {
|
||||||
|
msg("Sorry", "An identical or similar alarm already exists, please try again")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add the alarm to the list and save the list
|
// Add the alarm to the list and save the list
|
||||||
Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave();
|
Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave();
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ class Alarm: Codable, Equatable
|
|||||||
{
|
{
|
||||||
static func == (lhs: Alarm, rhs: Alarm) -> Bool {
|
static func == (lhs: Alarm, rhs: Alarm) -> Bool {
|
||||||
return lhs.hour == rhs.hour && lhs.minute == rhs.minute && lhs.text == rhs.text &&
|
return lhs.hour == rhs.hour && lhs.minute == rhs.minute && lhs.text == rhs.text &&
|
||||||
lhs.alarmTone == rhs.alarmTone && lhs.notificationID == rhs.notificationID &&
|
lhs.alarmTone == rhs.alarmTone && lhs.repeats == rhs.repeats
|
||||||
lhs.repeats == rhs.repeats
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var enabled: Bool
|
var enabled: Bool
|
||||||
|
|||||||
Reference in New Issue
Block a user