Skip to content

Commit 58d58ab

Browse files
committed
fix count/seconds issue
1 parent 690e4ba commit 58d58ab

File tree

3 files changed

+47
-48
lines changed

3 files changed

+47
-48
lines changed

FitCount/Workout/ExerciseDetailsView.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ struct TitleNavBarItem: View {
2121
}
2222
}
2323

24+
class SessionConfig: ObservableObject {
25+
@Published var nReps : Int = 0
26+
@Published var nMinutes : Int = 0
27+
@Published var nSeconds : Int = 0
28+
29+
@Published var useReps: Bool = true
30+
}
31+
2432

2533
struct ExerciseDetailsView: View {
2634
@EnvironmentObject var viewModel: ViewModel
35+
@StateObject var sessionConfig: SessionConfig = SessionConfig()
2736

2837
let exercise: Exercise
2938

30-
@State private var nReps : Int = 1
31-
@State private var nMinutes : Int = 1
32-
@State private var nSeconds: Int = 0
33-
3439
@State var selection = 1
3540

3641
var body: some View {
@@ -52,7 +57,7 @@ struct ExerciseDetailsView: View {
5257
.font(.headline)
5358
.padding(.top, 8)
5459

55-
Picker("Reps", selection: $nReps) {
60+
Picker("Reps", selection: $sessionConfig.nReps) {
5661
ForEach(1...100, id: \.self) { number in
5762
Text("\(number) reps")
5863
}
@@ -74,30 +79,30 @@ struct ExerciseDetailsView: View {
7479

7580
HStack{
7681

77-
Picker("Minutes", selection: $nMinutes) {
82+
Picker("Minutes", selection: $sessionConfig.nMinutes) {
7883
ForEach(0...30, id: \.self) { number in
7984
Text("\(number) min")
8085
}
8186
}
82-
.onChange(of: nMinutes) { min in
87+
.onChange(of: sessionConfig.nMinutes) { min in
8388
// make sure that time is not 0
84-
if (min <= 0 && nSeconds <= 0) {
85-
nMinutes = 0
86-
nSeconds = 1
89+
if (min <= 0 && sessionConfig.nSeconds <= 0) {
90+
sessionConfig.nMinutes = 0
91+
sessionConfig.nSeconds = 1
8792
}
8893
}
8994
.pickerStyle(WheelPickerStyle())
9095

91-
Picker("Seconds", selection: $nSeconds) {
96+
Picker("Seconds", selection: $sessionConfig.nSeconds) {
9297
ForEach(0...59, id: \.self) { number in
9398
Text("\(number) sec")
9499
}
95100
}
96-
.onChange(of: nSeconds) { sec in
101+
.onChange(of: sessionConfig.nSeconds) { sec in
97102
// make sure that time is not 0
98-
if (nMinutes <= 0 && sec <= 0) {
99-
nMinutes = 1
100-
nSeconds = 0
103+
if (sessionConfig.nMinutes <= 0 && sec <= 0) {
104+
sessionConfig.nMinutes = 1
105+
sessionConfig.nSeconds = 0
101106
}
102107
}
103108
.pickerStyle(WheelPickerStyle())
@@ -108,10 +113,14 @@ struct ExerciseDetailsView: View {
108113
.clipped()
109114
.cornerRadius(10)
110115
.shadow(color: Color.black.opacity(0.2), radius: 4, x: 0, y: 2)
111-
.padding().pagerTabItem(tag: 2) {
116+
.padding()
117+
.pagerTabItem(tag: 2) {
112118
TitleNavBarItem(title: "Timer")
113119
}
114120
}
121+
.onChange(of: selection) { newValue in
122+
sessionConfig.useReps = newValue == 1
123+
}
115124

116125
NavigationLink(value: "Workout") {
117126
Text("Start workout")
@@ -122,17 +131,11 @@ struct ExerciseDetailsView: View {
122131

123132
}
124133
.navigationDestination(for: String.self) { _ in
125-
WorkoutView(exercise: exercise, nReps: selection == 1 ? nReps : nil, nSeconds: selection == 2 ? nMinutes * 60 + nSeconds : nil).environmentObject(viewModel)
134+
WorkoutView(exercise: exercise).environmentObject(viewModel).environmentObject(sessionConfig)
126135
}
127136

128137

129138
}
130139
.navigationBarTitle(Text(exercise.name))
131140
}
132141
}
133-
134-
//struct ExerciseDetailsView_Previews: PreviewProvider {
135-
// static var previews: some View {
136-
// ExerciseDetailsView(exercise: Exercise(name: "Exercise 1", details: "Exercise 1 details"))
137-
// }
138-
//}

FitCount/Workout/QuickPoseBasicView.swift

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ enum WorkoutState {
2727
struct QuickPoseBasicView: View {
2828
private var quickPose = QuickPose(sdkKey: "01H122Z3J6NY33V548V2D55K3J") // register for your free key at https://dev.quickpose.ai
2929
@EnvironmentObject var viewModel: ViewModel
30+
@EnvironmentObject var sessionConfig: SessionConfig
3031

31-
private var nReps: Int?
32-
private var nSeconds: Int?
3332
private var exercise: Exercise
3433

3534
@State private var overlayImage: UIImage?
@@ -43,7 +42,7 @@ struct QuickPoseBasicView: View {
4342
let exerciseTimer = TimerManager()
4443

4544
@State var isInBBox = false
46-
@State var state = WorkoutState.exercise
45+
@State var state = WorkoutState.bbox
4746

4847
@State private var indicatorWidth: CGFloat = 0.0
4948

@@ -55,10 +54,8 @@ struct QuickPoseBasicView: View {
5554

5655
let bboxTimer = TimerManager()
5756

58-
init(exercise: Exercise, nReps: Int?, nSeconds: Int?) {
57+
init(exercise: Exercise) {
5958
self.exercise = exercise
60-
self.nReps = nReps
61-
self.nSeconds = nSeconds
6259
}
6360

6461
var body: some View {
@@ -86,22 +83,20 @@ struct QuickPoseBasicView: View {
8683

8784
.overlay(alignment: .bottom) {
8885
if (state == WorkoutState.exercise) {
89-
Text("Reps: " + String(count))
90-
.font(.system(size: 26, weight: .semibold))
91-
.foregroundColor(.white)
92-
.padding(16)
93-
.background(Color.blue)
94-
.cornerRadius(10)
95-
.scaleEffect(countScale)
96-
}
97-
}
98-
.overlay(alignment: .top) {
99-
Text("Time: " + String(seconds) + " sec")
100-
.font(.system(size: 26, weight: .semibold))
86+
HStack {
87+
Text(String(count) + (sessionConfig.useReps ? " \\ " + String(sessionConfig.nReps) : "") + " reps")
88+
.font(.system(size: 30, weight: .semibold))
89+
.padding(16)
90+
.scaleEffect(countScale)
91+
92+
Text(String(seconds) + (!sessionConfig.useReps ? " \\ " + String(sessionConfig.nSeconds) : "") + " sec")
93+
.font(.system(size: 30, weight: .semibold))
94+
.padding(16)
95+
}
96+
.frame(maxWidth: .infinity)
10197
.foregroundColor(.white)
102-
.padding(16)
103-
.background(Color.blue)
104-
.cornerRadius(10)
98+
.background(.indigo)
99+
}
105100
}
106101
.overlay(alignment: .center) {
107102
if (state == WorkoutState.exercise) {
@@ -189,7 +184,7 @@ struct QuickPoseBasicView: View {
189184
}
190185
count = counter.getCount()
191186

192-
if (nReps != nil && count >= nReps! || nSeconds != nil && Int(exerciseTimer.getTotalSeconds()) >= nSeconds!) {
187+
if (sessionConfig.useReps && count >= sessionConfig.nReps || !sessionConfig.useReps && Int(exerciseTimer.getTotalSeconds()) >= (sessionConfig.nSeconds + sessionConfig.nMinutes * 60)) {
193188
DispatchQueue.main.async {
194189
sessionData.seconds = Int(exerciseTimer.getTotalSeconds())
195190
sessionData.count = Int(counter.getCount())

FitCount/Workout/WorkoutView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import AVFoundation
1010

1111
struct WorkoutView: View {
1212
@EnvironmentObject var viewModel: ViewModel
13+
@EnvironmentObject var sessionConfig: SessionConfig
1314

1415
@State var cameraPermissionGranted = false
1516
var exercise: Exercise
16-
var nReps: Int?
17-
var nSeconds: Int?
17+
// var nReps: Int?
18+
// var nSeconds: Int?
1819

1920

2021
var body: some View {
2122
GeometryReader { geometry in
2223
if cameraPermissionGranted {
23-
QuickPoseBasicView(exercise: exercise, nReps: nReps, nSeconds: nSeconds).environmentObject(viewModel)
24+
QuickPoseBasicView(exercise: exercise).environmentObject(viewModel).environmentObject(sessionConfig)
2425
}
2526
}.onAppear {
2627
AVCaptureDevice.requestAccess(for: .video) { accessGranted in

0 commit comments

Comments
 (0)