Skip to content

Commit c50075c

Browse files
committed
Fixed Issue on Final Rep
1 parent c396b20 commit c50075c

File tree

3 files changed

+69
-38
lines changed

3 files changed

+69
-38
lines changed

FitCount/Workout/QuickPoseBasicView.swift

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum ViewState: Equatable {
3737
}
3838

3939
struct QuickPoseBasicView: View {
40-
private var quickPose = QuickPose(sdkKey: "YOUR SDK KEY") // register for your free key at https://dev.quickpose.ai
40+
private var quickPose = QuickPose(sdkKey: "01HNBD5JEKHV5X6FH2RF0X5S4N") // register for your free key at https://dev.quickpose.ai
4141
@EnvironmentObject var viewModel: ViewModel
4242
@EnvironmentObject var sessionConfig: SessionConfig
4343

@@ -174,11 +174,20 @@ struct QuickPoseBasicView: View {
174174

175175
.onChange(of: state) { _ in
176176
if case .results(let result) = state {
177-
let sessionDataDump = SessionDataModel(exercise: sessionConfig.exercise.name, count: result.count, seconds: result.seconds, date: Date())
178-
appendToJson(sessionData: sessionDataDump)
177+
do {
178+
let sessionDataDump = SessionDataModel(exercise: sessionConfig.exercise.name, count: result.count, seconds: result.seconds, date: Date())
179+
appendToJson(sessionData: sessionDataDump)
180+
} catch {
181+
print("Error saving session data: \(error.localizedDescription)")
182+
}
183+
} else {
184+
// Only update features if we're not in the results state
185+
do {
186+
quickPose.update(features: sessionConfig.exercise.features)
187+
} catch {
188+
print("Error updating QuickPose features: \(error.localizedDescription)")
189+
}
179190
}
180-
181-
quickPose.update(features: sessionConfig.exercise.features)
182191
}
183192
.onAppear() {
184193
UIApplication.shared.isIdleTimerDisabled = true
@@ -245,8 +254,23 @@ struct QuickPoseBasicView: View {
245254
}
246255

247256
if hasFinished {
248-
state = .results(newResults)
249-
quickPose.stop()
257+
// Create a new SessionData object to avoid any potential reference issues
258+
let finalResults = SessionData(count: newResults.count, seconds: newResults.seconds)
259+
260+
// First change the state, then stop QuickPose
261+
DispatchQueue.main.async {
262+
state = .results(finalResults)
263+
264+
// Add a small delay before stopping QuickPose to ensure the state change is processed
265+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
266+
// Safely stop QuickPose
267+
do {
268+
quickPose.stop()
269+
} catch {
270+
print("Error stopping QuickPose: \(error.localizedDescription)")
271+
}
272+
}
273+
}
250274
}
251275
default:
252276
break
@@ -259,6 +283,15 @@ struct QuickPoseBasicView: View {
259283
}
260284
.onDisappear {
261285
UIApplication.shared.isIdleTimerDisabled = false
286+
287+
// Safely stop QuickPose when view disappears
288+
DispatchQueue.main.async {
289+
do {
290+
quickPose.stop()
291+
} catch {
292+
print("Error stopping QuickPose on disappear: \(error.localizedDescription)")
293+
}
294+
}
262295
}
263296
}
264297
.navigationBarBackButtonHidden(true)

FitCount/Workout/WorkoutResultsView.swift

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,38 @@ struct WorkoutResultsView: View {
1313
@EnvironmentObject var viewModel: ViewModel
1414

1515
var body: some View {
16-
NavigationView{
17-
VStack(spacing: 20) {
18-
Text("Your workout results")
19-
.font(.largeTitle)
20-
.padding(.top, 50)
21-
22-
Text("Number of reps: \(sessionData.count)")
16+
VStack(spacing: 20) {
17+
Text("Your workout results")
18+
.font(.largeTitle)
19+
.padding(.top, 50)
20+
21+
Text("Number of reps: \(sessionData.count)")
22+
.font(.title2)
23+
.padding(.top, 50)
24+
.padding(.bottom, 20)
25+
26+
Text("Time: \(sessionData.seconds) Seconds")
27+
.font(.title2)
28+
.padding(.bottom, 40)
29+
30+
Button(action: {
31+
viewModel.popToRoot()
32+
}) {
33+
Text("Finish Workout")
34+
.foregroundColor(.white)
2335
.font(.title2)
24-
.padding(.top, 50)
25-
.padding(.bottom, 20)
26-
27-
Text("Time: \(sessionData.seconds) Seconds")
28-
.font(.title2)
29-
.padding(.bottom, 40)
30-
31-
Button(action: {
32-
viewModel.popToRoot()
33-
}) {
34-
Text("Finish Workout")
35-
.foregroundColor(.white)
36-
.font(.title2)
37-
.padding()
38-
.frame(maxWidth: .infinity)
39-
.background(Color("AccentColor"))
40-
.cornerRadius(8)
41-
}
42-
.padding()
43-
.buttonStyle(PlainButtonStyle()) // Remove button style highlighting
44-
45-
Spacer()
36+
.padding()
37+
.frame(maxWidth: .infinity)
38+
.background(Color("AccentColor"))
39+
.cornerRadius(8)
4640
}
47-
.navigationBarBackButtonHidden(true)
4841
.padding()
49-
.background(Color(UIColor.systemBackground))
42+
.buttonStyle(PlainButtonStyle()) // Remove button style highlighting
43+
44+
Spacer()
5045
}
46+
.navigationBarBackButtonHidden(true)
47+
.padding()
48+
.background(Color(UIColor.systemBackground))
5149
}
5250
}

0 commit comments

Comments
 (0)