84 lines
2.4 KiB
Swift
84 lines
2.4 KiB
Swift
//
|
|
// ActiveWorkoutSessionControls.swift
|
|
// WorkoutsPlus
|
|
//
|
|
// Created by Felix Förtsch on 16.09.24.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ActiveWorkoutSessionControls: View {
|
|
@Environment(WorkoutStateManager.self) private var workoutStateManager
|
|
private var activeWorkoutSession: WorkoutSession? { workoutStateManager.activeWorkoutSession }
|
|
|
|
var body: some View {
|
|
if let session = activeWorkoutSession, workoutStateManager.isWorkoutInProgress {
|
|
VStack {
|
|
Text(session.name)
|
|
SimpleStopWatch(
|
|
startDate: session.startDate,
|
|
duration: Binding(
|
|
get: { session.workoutDuration },
|
|
set: { session.workoutDuration = $0 }))
|
|
.font(.system(.largeTitle, design: .monospaced))
|
|
.fontWeight(.bold)
|
|
HStack {
|
|
Text(session.getCurrentExerciseName())
|
|
.font(.system(size: 24, weight: .bold, design: .rounded))
|
|
}
|
|
ProgressView("",
|
|
value: session.getCurrentExerciseIndex(),
|
|
total: session.getTotalExerciseCount() - 1
|
|
)
|
|
HStack {
|
|
Button(action: {
|
|
workoutStateManager.prevExercise()
|
|
}) {
|
|
HStack {
|
|
Image(systemName: "backward.end.fill")
|
|
Text("Prev")
|
|
}
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.fontWeight(.bold)
|
|
.tint(.accentColor)
|
|
|
|
Button(action: {
|
|
// TODO: Implement proper Pausing
|
|
session.workoutSessionStatus = .paused
|
|
}) {
|
|
HStack {
|
|
Image(systemName: "pause.fill")
|
|
Text("Pause")
|
|
}
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.fontWeight(.bold)
|
|
.tint(.gray)
|
|
.disabled(true)
|
|
|
|
Button(action: {
|
|
workoutStateManager.nextExercise()
|
|
}) {
|
|
HStack {
|
|
Text("Next")
|
|
Image(systemName: "forward.end.fill")
|
|
}
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.fontWeight(.bold)
|
|
.tint(.accentColor)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview("isWorkingOut = true") {
|
|
@Previewable @State var stateManager = WorkoutStateManager(modelContext: SampleData.shared.modelContainer.mainContext)
|
|
|
|
ActiveWorkoutSessionControls()
|
|
.modelContainer(SampleData.shared.modelContainer)
|
|
.environment(stateManager)
|
|
}
|