|
|
|
|
@ -9,6 +9,7 @@ import SwiftUI |
|
|
|
|
|
|
|
|
|
enum CountdownField: Int, Hashable { |
|
|
|
|
case name |
|
|
|
|
case hours |
|
|
|
|
case minutes |
|
|
|
|
case seconds |
|
|
|
|
} |
|
|
|
|
@ -19,9 +20,11 @@ struct CountdownFormView : View { |
|
|
|
|
|
|
|
|
|
@EnvironmentObject var model: TimerModel |
|
|
|
|
|
|
|
|
|
var nameBinding: Binding<String> |
|
|
|
|
|
|
|
|
|
var secondsBinding: Binding<String> |
|
|
|
|
var minutesBinding: Binding<String> |
|
|
|
|
var nameBinding: Binding<String> |
|
|
|
|
var hoursBinding: Binding<String> |
|
|
|
|
|
|
|
|
|
var imageBinding: Binding<CoolPic> |
|
|
|
|
|
|
|
|
|
@ -32,15 +35,27 @@ struct CountdownFormView : View { |
|
|
|
|
var body: some View { |
|
|
|
|
|
|
|
|
|
Group { |
|
|
|
|
Section("Name") { |
|
|
|
|
Section { |
|
|
|
|
TextField("Name", text: nameBinding) |
|
|
|
|
.focused($focusedField, equals: .name) |
|
|
|
|
.onSubmit { |
|
|
|
|
self.focusNextField($focusedField) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
Text("Name") |
|
|
|
|
} footer: { |
|
|
|
|
if !self.nameBinding.wrappedValue.isEmpty { |
|
|
|
|
Text("Ask Siri: \(Bundle.main.applicationName) \(self.nameBinding.wrappedValue)!") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Section("Duration") { |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
TextField("Hours", text: hoursBinding) |
|
|
|
|
.keyboardType(.numberPad) |
|
|
|
|
.focused($focusedField, equals: .hours) |
|
|
|
|
.onSubmit { |
|
|
|
|
self.focusNextField($focusedField) |
|
|
|
|
} |
|
|
|
|
TextField("Minutes", text: minutesBinding) |
|
|
|
|
.keyboardType(.numberPad) |
|
|
|
|
.focused($focusedField, equals: .minutes) |
|
|
|
|
@ -53,6 +68,8 @@ struct CountdownFormView : View { |
|
|
|
|
.onSubmit { |
|
|
|
|
self.focusedField = nil |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
LabeledContent("Duration", value: self.duration().hourMinuteSecond).font(.footnote) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SoundFormView( |
|
|
|
|
@ -64,6 +81,23 @@ struct CountdownFormView : View { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func duration() -> TimeInterval { |
|
|
|
|
let formatter = NumberFormatter() |
|
|
|
|
var hours: Int = 0 |
|
|
|
|
var minutes: Int = 0 |
|
|
|
|
var seconds: Int = 0 |
|
|
|
|
if let h = formatter.number(from: hoursBinding.wrappedValue) { |
|
|
|
|
hours = h.intValue |
|
|
|
|
} |
|
|
|
|
if let m = formatter.number(from: minutesBinding.wrappedValue) { |
|
|
|
|
minutes = m.intValue |
|
|
|
|
} |
|
|
|
|
if let s = formatter.number(from: secondsBinding.wrappedValue) { |
|
|
|
|
seconds = s.intValue |
|
|
|
|
} |
|
|
|
|
return Double(seconds) + 60 * Double(minutes) + 60 * 60 * Double(hours) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct CountdownFormView_Previews: PreviewProvider { |
|
|
|
|
@ -74,9 +108,10 @@ struct CountdownFormView_Previews: PreviewProvider { |
|
|
|
|
|
|
|
|
|
Form { |
|
|
|
|
CountdownFormView( |
|
|
|
|
nameBinding: .constant(""), |
|
|
|
|
secondsBinding: .constant(""), |
|
|
|
|
minutesBinding: .constant(""), |
|
|
|
|
nameBinding: .constant(""), |
|
|
|
|
hoursBinding: .constant(""), |
|
|
|
|
imageBinding: .constant(.pic3), |
|
|
|
|
repeatCountBinding: .constant(2), |
|
|
|
|
intervalRepeatBinding: .constant(2)) |
|
|
|
|
|