|
|
|
@ -20,8 +20,6 @@ struct NewCountdownView : View { |
|
|
|
init(isPresented: Binding<Bool>) { |
|
|
|
init(isPresented: Binding<Bool>) { |
|
|
|
_isPresented = isPresented |
|
|
|
_isPresented = isPresented |
|
|
|
self.userActivity = Shortcut.newCountdown.userActivity |
|
|
|
self.userActivity = Shortcut.newCountdown.userActivity |
|
|
|
|
|
|
|
|
|
|
|
// let shortcut = INShortcut(userActivity: self.userActivity) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
var body: some View { |
|
|
|
@ -94,7 +92,6 @@ struct CountdownEditView : View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CountdownFormView( |
|
|
|
CountdownFormView( |
|
|
|
focusedField: _focusedField, |
|
|
|
focusedField: _focusedField, |
|
|
|
nameBinding: $nameString, |
|
|
|
nameBinding: $nameString, |
|
|
|
@ -103,7 +100,6 @@ struct CountdownEditView : View { |
|
|
|
repeatCountBinding: $soundRepeatCount) |
|
|
|
repeatCountBinding: $soundRepeatCount) |
|
|
|
.environmentObject(self.model) |
|
|
|
.environmentObject(self.model) |
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
.toolbar { |
|
|
|
.toolbar { |
|
|
|
ToolbarItemGroup(placement: .keyboard) { |
|
|
|
ToolbarItemGroup(placement: .keyboard) { |
|
|
|
Button { |
|
|
|
Button { |
|
|
|
@ -197,21 +193,6 @@ struct CountdownEditView : View { |
|
|
|
fileprivate func _loadCountdown(_ countdown: Countdown) { |
|
|
|
fileprivate func _loadCountdown(_ countdown: Countdown) { |
|
|
|
|
|
|
|
|
|
|
|
self.duration = countdown.duration |
|
|
|
self.duration = countdown.duration |
|
|
|
|
|
|
|
|
|
|
|
// let hours = Int(countdown.duration / 3600.0) |
|
|
|
|
|
|
|
// let minutes = Int(countdown.duration - Double(hours * 3600)) / 60 |
|
|
|
|
|
|
|
// let seconds = countdown.duration - Double(hours * 3600) - Double(minutes * 60) |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// if hours > 0 { |
|
|
|
|
|
|
|
// self.hoursString = self._numberFormatter.string(from: NSNumber(value: hours)) ?? "" |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// if minutes > 0 { |
|
|
|
|
|
|
|
// self.minutesString = self._numberFormatter.string(from: NSNumber(value: minutes)) ?? "" |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// if seconds > 0 { |
|
|
|
|
|
|
|
// self.secondsString = self._numberFormatter.string(from: NSNumber(value: seconds)) ?? "" |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let name = countdown.activity?.name, !name.isEmpty { |
|
|
|
if let name = countdown.activity?.name, !name.isEmpty { |
|
|
|
self.nameString = name |
|
|
|
self.nameString = name |
|
|
|
} |
|
|
|
} |
|
|
|
@ -226,20 +207,6 @@ struct CountdownEditView : View { |
|
|
|
self.image = coolpic |
|
|
|
self.image = coolpic |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fileprivate let _numberFormatter = NumberFormatter() |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// fileprivate var _seconds: Double { |
|
|
|
|
|
|
|
// return self._numberFormatter.number(from: self.secondsString)?.doubleValue ?? 0.0 |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// fileprivate var _minutes: Double { |
|
|
|
|
|
|
|
// return self._numberFormatter.number(from: self.minutesString)?.doubleValue ?? 0.0 |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// fileprivate var _hours: Double { |
|
|
|
|
|
|
|
// return self._numberFormatter.number(from: self.hoursString)?.doubleValue ?? 0.0 |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _cancel() { |
|
|
|
fileprivate func _cancel() { |
|
|
|
self.viewContext.rollback() |
|
|
|
self.viewContext.rollback() |
|
|
|
@ -255,7 +222,6 @@ struct CountdownEditView : View { |
|
|
|
cd = Countdown(context: viewContext) |
|
|
|
cd = Countdown(context: viewContext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// cd.duration = self._hours * 3600.0 + self._minutes * 60.0 + self._seconds |
|
|
|
|
|
|
|
cd.duration = self.duration |
|
|
|
cd.duration = self.duration |
|
|
|
|
|
|
|
|
|
|
|
if self._isNewCountdown { |
|
|
|
if self._isNewCountdown { |
|
|
|
@ -277,37 +243,34 @@ struct CountdownEditView : View { |
|
|
|
|
|
|
|
|
|
|
|
cd.image = self.image.rawValue |
|
|
|
cd.image = self.image.rawValue |
|
|
|
cd.playableIds = self.model.soundModel.playableIds |
|
|
|
cd.playableIds = self.model.soundModel.playableIds |
|
|
|
|
|
|
|
|
|
|
|
cd.setConfirmationSounds(self.model.confirmationSoundModel.sounds) |
|
|
|
cd.setConfirmationSounds(self.model.confirmationSoundModel.sounds) |
|
|
|
|
|
|
|
|
|
|
|
cd.repeatCount = self.soundRepeatCount |
|
|
|
cd.repeatCount = self.soundRepeatCount |
|
|
|
|
|
|
|
|
|
|
|
if !self.nameString.isEmpty { |
|
|
|
if !self.nameString.isEmpty { |
|
|
|
|
|
|
|
|
|
|
|
let trimmed = self.nameString.trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
let trimmed = self.nameString.trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
|
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: trimmed) |
|
|
|
|
|
|
|
|
|
|
|
if let activity = cd.activity, let currentActivityName = activity.name, trimmed != currentActivityName { |
|
|
|
// if let activity = cd.activity, let currentActivityName = activity.name, trimmed != currentActivityName { |
|
|
|
|
|
|
|
// |
|
|
|
switch self._rename { |
|
|
|
// switch self._rename { |
|
|
|
case .none: |
|
|
|
// case .none: |
|
|
|
self.activityNameConfirmationShown = true |
|
|
|
// self.activityNameConfirmationShown = true |
|
|
|
return |
|
|
|
// return |
|
|
|
case .some(let rename): |
|
|
|
// case .some(let rename): |
|
|
|
if rename { |
|
|
|
// if rename { |
|
|
|
activity.name = trimmed |
|
|
|
// activity.name = trimmed |
|
|
|
} else { |
|
|
|
// } else { |
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: trimmed) |
|
|
|
// cd.activity = CoreDataRequests.getOrCreateActivity(name: trimmed) |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
// } |
|
|
|
} else { |
|
|
|
// } else { |
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: trimmed) |
|
|
|
// cd.activity = CoreDataRequests.getOrCreateActivity(name: trimmed) |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self._saveContext() |
|
|
|
self._saveContext() |
|
|
|
|
|
|
|
|
|
|
|
WidgetCenter.shared.reloadAllTimelines() // refreshes the visual of existing widgets |
|
|
|
WidgetCenter.shared.reloadAllTimelines() // refreshes the visual of existing widgets |
|
|
|
|
|
|
|
|
|
|
|
self._popOrDismiss() |
|
|
|
self._popOrDismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -333,7 +296,6 @@ struct CountdownEditView : View { |
|
|
|
WidgetCenter.shared.reloadAllTimelines() // refreshes the visual of existing widgets |
|
|
|
WidgetCenter.shared.reloadAllTimelines() // refreshes the visual of existing widgets |
|
|
|
|
|
|
|
|
|
|
|
self._popOrDismiss() |
|
|
|
self._popOrDismiss() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _saveContext() { |
|
|
|
fileprivate func _saveContext() { |
|
|
|
|