improvements

release
Laurent 3 years ago
parent de5452f859
commit 1dd16f6b3e
  1. 2
      LeCountdown/Views/Components/TimerModel.swift
  2. 30
      LeCountdown/Views/Countdown/CountdownFormView.swift
  3. 6
      LeCountdown/Views/Countdown/NewCountdownView.swift
  4. 18
      LeCountdown/Views/PresetsView.swift

@ -21,6 +21,8 @@ class TimerModel : ObservableObject, SoundHolder {
self._selectPlaylists() self._selectPlaylists()
} }
} }
@Published var group: CountdownIntervalGroup =
CountdownIntervalGroup(repeatCount: 0, intervals: [])
var soundSelection: String { var soundSelection: String {
if !sounds.isEmpty { if !sounds.isEmpty {

@ -22,15 +22,36 @@ struct CountdownFormView : View {
var textFieldIsFocused: FocusState<Bool>.Binding var textFieldIsFocused: FocusState<Bool>.Binding
var intervalRepeatBinding: Binding<Int>? = nil
var body: some View { var body: some View {
Form { Form {
Section(header: Text("Duration")) { Section {
TextField("minutes", text: minutesBinding) TextField("minutes", text: minutesBinding)
.keyboardType(.numberPad) .keyboardType(.numberPad)
.focused(textFieldIsFocused) .focused(textFieldIsFocused)
TextField("seconds", text: secondsBinding) TextField("seconds", text: secondsBinding)
.keyboardType(.numberPad) .keyboardType(.numberPad)
.focused(textFieldIsFocused) .focused(textFieldIsFocused)
} header: {
HStack {
Text("Duration")
Spacer()
Button {
self._addInterval()
} label: {
Label("add interval", image: "plus")
// Image(systemName: "plus")
}
}
} footer: {
if intervalRepeatBinding != nil {
HStack {
Stepper("Repeat", value: intervalRepeatBinding!, in: 0...20)
Text(self.intervalRepeatBinding!.wrappedValue.formatted())
}
}
} }
Section(header: Text("Name for tracking the activity")) { Section(header: Text("Name for tracking the activity")) {
TextField("name", text: nameBinding) TextField("name", text: nameBinding)
@ -45,6 +66,10 @@ struct CountdownFormView : View {
} }
fileprivate func _addInterval() {
}
} }
struct CountdownFormView_Previews: PreviewProvider { struct CountdownFormView_Previews: PreviewProvider {
@ -58,7 +83,8 @@ struct CountdownFormView_Previews: PreviewProvider {
nameBinding: .constant(""), nameBinding: .constant(""),
imageBinding: .constant(.pic3), imageBinding: .constant(.pic3),
repeatCountBinding: .constant(2), repeatCountBinding: .constant(2),
textFieldIsFocused: $textFieldIsFocused) textFieldIsFocused: $textFieldIsFocused,
intervalRepeatBinding: .constant(2))
.environmentObject(TimerModel()) .environmentObject(TimerModel())
} }
} }

@ -173,10 +173,16 @@ struct CountdownEditView : View {
let nf = NumberFormatter() let nf = NumberFormatter()
let minutes = Int(preset.duration / 60.0) let minutes = Int(preset.duration / 60.0)
if minutes > 0 {
self.minutesString = nf.string(from: NSNumber(value: minutes)) ?? "" self.minutesString = nf.string(from: NSNumber(value: minutes)) ?? ""
}
let seconds = Int(preset.duration) - minutes * 60 let seconds = Int(preset.duration) - minutes * 60
if seconds > 0 {
self.secondsString = nf.string(from: NSNumber(value: seconds)) ?? "" self.secondsString = nf.string(from: NSNumber(value: seconds)) ?? ""
}
self.model.group = preset.intervalGroup
self.model.sounds = preset.sound self.model.sounds = preset.sound
} }

@ -63,14 +63,14 @@ enum Preset: Int, Identifiable, CaseIterable {
} }
} }
var intervalGroup: CountdownIntervalGroup? { var intervalGroup: CountdownIntervalGroup {
switch self { switch self {
case .runningSplits: case .runningSplits:
let runInterval = CountdownInterval(duration: 30.0, sound: Sound.sbArpeggio_Loop_River) let runInterval = CountdownInterval(duration: 30.0, sound: Sound.sbArpeggio_Loop_River)
let breakInterval = CountdownInterval(duration: 30.0, sound: Sound.sbLoop_ToneSD_Boavista) let breakInterval = CountdownInterval(duration: 30.0, sound: Sound.sbLoop_ToneSD_Boavista)
return CountdownIntervalGroup(repeatCount: 8, intervals: [runInterval, breakInterval]) return CountdownIntervalGroup(repeatCount: 8, intervals: [runInterval, breakInterval])
default: default:
return nil return CountdownIntervalGroup(repeatCount: 0, intervals: [CountdownInterval(duration: self.duration)])
} }
} }
@ -86,13 +86,17 @@ enum Preset: Int, Identifiable, CaseIterable {
} }
var formattedDuration: String { var formattedDuration: String {
if let group = self.intervalGroup { let group = self.intervalGroup
let count = group.repeatCount.formatted() let count = group.repeatCount.formatted()
let durations = group.intervals.map { $0.duration.formatted() } let durations = group.intervals.map { $0.duration.minuteSecond }
let formattedIntervals = durations.joined(separator: "/") let formattedIntervals = durations.joined(separator: "/")
if group.repeatCount > 1 {
return "\(count) * [\(formattedIntervals)]" return "\(count) * [\(formattedIntervals)]"
} else if durations.count > 1 {
return "[\(formattedIntervals)]"
} else { } else {
return self.duration.minuteSecond return formattedIntervals
} }
} }
@ -137,7 +141,7 @@ struct PresetsView: View {
var body: some View { var body: some View {
VStack { ScrollView {
Text("You can edit the duration, sound and label before adding") Text("You can edit the duration, sound and label before adding")
.padding() .padding()
@ -197,7 +201,7 @@ struct TimerItemView: View {
Text(sound.uppercased()).foregroundColor(Color(white: 0.7)) Text(sound.uppercased()).foregroundColor(Color(white: 0.7))
}.padding() }.padding()
Spacer() Spacer()
}.background(Color(white: 0.15)) }.background(Color(white: 0.1))
.cornerRadius(16.0) .cornerRadius(16.0)
.monospaced() .monospaced()
.font(Font.system(size: 16.0, weight: .semibold)) .font(Font.system(size: 16.0, weight: .semibold))

Loading…
Cancel
Save