feat(watch): add workout summary screen with HealthKit data
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import SwiftUI
|
||||
|
||||
struct WorkoutSummaryView: View {
|
||||
@ObservedObject var workoutManager: WorkoutManager
|
||||
|
||||
var body: some View {
|
||||
if let summary = workoutManager.workoutSummary {
|
||||
List {
|
||||
Section {
|
||||
VStack(spacing: 8) {
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.font(.system(size: 40))
|
||||
.foregroundColor(.green)
|
||||
|
||||
Text("Workout complete!")
|
||||
.font(.headline)
|
||||
.foregroundColor(.green)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
Section("Stats") {
|
||||
HStack {
|
||||
Text("Total time")
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
Text(formatTime(summary.duration))
|
||||
.monospacedDigit()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Distance")
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
Text("\(summary.totalDistance)m")
|
||||
.monospacedDigit()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Calories")
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
Text("\(summary.calories)kcal")
|
||||
.monospacedDigit()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Laps")
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
Text("\(summary.laps.count)")
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
Button {
|
||||
workoutManager.dismissSummary()
|
||||
} label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("OK")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(.cyan)
|
||||
}
|
||||
}
|
||||
.listStyle(.automatic)
|
||||
}
|
||||
}
|
||||
|
||||
private func formatTime(_ seconds: TimeInterval) -> String {
|
||||
let mins = Int(seconds) / 60
|
||||
let secs = Int(seconds) % 60
|
||||
return String(format: "%d:%02d", mins, secs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user