Fixes in countdown edition

release
Laurent 3 years ago
parent 6ebaedd641
commit b1eab23a03
  1. 2
      LeCountdown.xcodeproj/project.pbxproj
  2. 35
      LeCountdown/NewCountdownView.swift

@ -114,13 +114,13 @@
C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */,
C438C7C02980228B00BF3EF9 /* CountdownScheduler.swift */,
C4060DC3297AE73D003FAB80 /* Assets.xcassets */,
C438C7C829803CA000BF3EF9 /* AppDelegate.swift */,
C4060DC8297AE73D003FAB80 /* Persistence.swift */,
C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */,
C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */,
C4060DCD297AE73D003FAB80 /* Info.plist */,
C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */,
C4060DC5297AE73D003FAB80 /* Preview Content */,
C438C7C829803CA000BF3EF9 /* AppDelegate.swift */,
);
path = LeCountdown;
sourceTree = "<group>";

@ -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 {

Loading…
Cancel
Save