|
|
|
|
@ -32,6 +32,8 @@ struct CountdownEditView : View { |
|
|
|
|
|
|
|
|
|
@State var secondsString: String = "" |
|
|
|
|
@State var minutesString: String = "" |
|
|
|
|
|
|
|
|
|
@State var deleteConfirmationShown: Bool = false |
|
|
|
|
|
|
|
|
|
@State var errorShown: Bool = false |
|
|
|
|
@State var error: Error? = nil |
|
|
|
|
@ -57,7 +59,19 @@ struct CountdownEditView : View { |
|
|
|
|
Text("Image") |
|
|
|
|
Text("Sound") |
|
|
|
|
} |
|
|
|
|
}.onAppear { |
|
|
|
|
self._initDuration() |
|
|
|
|
} |
|
|
|
|
.confirmationDialog("", isPresented: $deleteConfirmationShown, actions: { |
|
|
|
|
Button("Yes", role: .destructive) { |
|
|
|
|
withAnimation { |
|
|
|
|
self._delete() |
|
|
|
|
} |
|
|
|
|
}.keyboardShortcut(.defaultAction) |
|
|
|
|
Button("No", role: .cancel) {} |
|
|
|
|
}, message: { |
|
|
|
|
Text("Do you really want to delete?") |
|
|
|
|
}) |
|
|
|
|
.alert("", isPresented: $errorShown, actions: { }, message: { |
|
|
|
|
Text(error?.localizedDescription ?? "error") |
|
|
|
|
}) |
|
|
|
|
@ -74,6 +88,13 @@ struct CountdownEditView : View { |
|
|
|
|
self._save() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ToolbarItem(placement: .bottomBar) { |
|
|
|
|
Button { |
|
|
|
|
self.deleteConfirmationShown = true |
|
|
|
|
} label: { |
|
|
|
|
Image(systemName: "trash") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ToolbarItemGroup(placement: .keyboard) { |
|
|
|
|
Button { |
|
|
|
|
textFieldIsFocused = false |
|
|
|
|
@ -87,6 +108,20 @@ struct CountdownEditView : View { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _initDuration() { |
|
|
|
|
|
|
|
|
|
let minutes = Int(self.countdown.duration / 60.0) |
|
|
|
|
let seconds = self.countdown.duration - Double(minutes * 60) |
|
|
|
|
|
|
|
|
|
if minutes > 0 { |
|
|
|
|
self.minutesString = self._numberFormatter.string(from: NSNumber(value: minutes)) ?? "" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if seconds > 0 { |
|
|
|
|
self.secondsString = self._numberFormatter.string(from: NSNumber(value: seconds)) ?? "" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate let _numberFormatter = NumberFormatter() |
|
|
|
|
|
|
|
|
|
fileprivate var _seconds: Double { |
|
|
|
|
|