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. 10
      LeCountdown/Views/Countdown/NewCountdownView.swift
  4. 22
      LeCountdown/Views/PresetsView.swift

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

@ -22,15 +22,36 @@ struct CountdownFormView : View {
var textFieldIsFocused: FocusState<Bool>.Binding
var intervalRepeatBinding: Binding<Int>? = nil
var body: some View {
Form {
Section(header: Text("Duration")) {
Section {
TextField("minutes", text: minutesBinding)
.keyboardType(.numberPad)
.focused(textFieldIsFocused)
TextField("seconds", text: secondsBinding)
.keyboardType(.numberPad)
.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")) {
TextField("name", text: nameBinding)
@ -45,6 +66,10 @@ struct CountdownFormView : View {
}
fileprivate func _addInterval() {
}
}
struct CountdownFormView_Previews: PreviewProvider {
@ -58,7 +83,8 @@ struct CountdownFormView_Previews: PreviewProvider {
nameBinding: .constant(""),
imageBinding: .constant(.pic3),
repeatCountBinding: .constant(2),
textFieldIsFocused: $textFieldIsFocused)
textFieldIsFocused: $textFieldIsFocused,
intervalRepeatBinding: .constant(2))
.environmentObject(TimerModel())
}
}

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

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

Loading…
Cancel
Save