add SimpleStopWatch to ActiveWorkoutSession
This commit is contained in:
@@ -1,43 +1,51 @@
|
||||
//
|
||||
// ActiveWorkoutSession.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 12.09.24.
|
||||
//
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
// This view can only be viewed, if there exists a WorkoutSession that can be considered active (a person working out).
|
||||
struct ActiveWorkoutSession: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
@Default(\.isWorkingOut) var isWorkingOut
|
||||
@State var isTimerRunning: Bool = true
|
||||
|
||||
@Query(sort: \WorkoutSession.name) var workoutSessions: [WorkoutSession]
|
||||
@Binding var activeWorkoutSession: WorkoutSession?
|
||||
@Binding var activeWorkoutSession: WorkoutSession
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack {
|
||||
Text(activeWorkoutSession.name)
|
||||
SimpleStopWatch(
|
||||
startDate: activeWorkoutSession.startDate,
|
||||
duration: $activeWorkoutSession.workoutDuration)
|
||||
.font(.system(.largeTitle, design: .monospaced))
|
||||
.fontWeight(.bold)
|
||||
}
|
||||
List {
|
||||
Section(header: Text("Workout")) {
|
||||
Text(activeWorkoutSession!.name)
|
||||
}
|
||||
Section(header: Text("Exercises")) {
|
||||
ForEach(activeWorkoutSession!.workoutSessionItems) { workoutItem in
|
||||
ForEach(activeWorkoutSession.workoutSessionItems) { workoutItem in
|
||||
ActiveWorkoutSessionListItem(workoutItem: workoutItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Session")
|
||||
// .navigationTitle(activeWorkoutSession.name)
|
||||
// .navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
Button(action: {
|
||||
isWorkingOut = false
|
||||
activeWorkoutSession?.stop()
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "stop.fill")
|
||||
Text("Stop")
|
||||
}
|
||||
Button(action: {
|
||||
isWorkingOut = false
|
||||
activeWorkoutSession.isPaused.toggle()
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "stop.fill")
|
||||
Text("Stop")
|
||||
}
|
||||
.bold()
|
||||
.fontDesign(.rounded)
|
||||
.tint(.red)
|
||||
}
|
||||
.fontWeight(.bold)
|
||||
.fontDesign(.rounded)
|
||||
.tint(.red)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +62,7 @@ struct ActiveWorkoutSession: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
@Previewable @State var activeWorkoutSession: WorkoutSession?
|
||||
@Previewable @State var workout = Workout.sampleData.first!
|
||||
@Previewable @State var activeWorkoutSession = Workout.sampleData.first!.start()
|
||||
|
||||
NavigationStack {
|
||||
ActiveWorkoutSession(activeWorkoutSession: $activeWorkoutSession)
|
||||
@@ -65,14 +72,3 @@ struct ActiveWorkoutSession: View {
|
||||
}
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
}
|
||||
|
||||
//#Preview("Empty modelContainer") {
|
||||
// @Previewable @State var activeWorkoutSession: WorkoutSession?
|
||||
//
|
||||
// NavigationStack {
|
||||
// ActiveWorkoutSession(activeWorkoutSession: $activeWorkoutSession)
|
||||
// }
|
||||
// .onAppear {
|
||||
// Defaults.shared.isWorkingOut = false
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -31,11 +31,11 @@ struct ActiveWorkoutSessionControls: View {
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.bold()
|
||||
.fontWeight(.bold)
|
||||
.tint(.primary)
|
||||
Button(action: {
|
||||
// TODO: Implement proper Pausing
|
||||
session.pause()
|
||||
session.isPaused = true
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "pause.fill")
|
||||
@@ -43,7 +43,7 @@ struct ActiveWorkoutSessionControls: View {
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.bold()
|
||||
.fontWeight(.bold)
|
||||
.tint(.gray)
|
||||
.disabled(true)
|
||||
Button(action: {
|
||||
@@ -55,7 +55,7 @@ struct ActiveWorkoutSessionControls: View {
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.bold()
|
||||
.fontWeight(.bold)
|
||||
.tint(.primary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,16 @@ struct ActiveWorkoutSessionListItem: View {
|
||||
var workoutItem: WorkoutSessionItem
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(String(workoutItem.plannedReps) + "x")
|
||||
Text(String(workoutItem.plannedValue))
|
||||
Text(String(workoutItem.unit.symbol))
|
||||
if let metric = workoutItem.metric {
|
||||
Text(metric.rawValue)
|
||||
}
|
||||
Text(workoutItem.name)
|
||||
.fontWeight(.bold)
|
||||
Spacer()
|
||||
Button(action: {
|
||||
// TODO: Implement a sheet view; don't use ExerciseDetail since its purpose is editing
|
||||
@@ -20,6 +28,18 @@ struct ActiveWorkoutSessionListItem: View {
|
||||
Image(systemName: "info.circle")
|
||||
.foregroundColor(.blue)
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Text("Planned: ")
|
||||
|
||||
if let actualRepsDone = workoutItem.actualReps {
|
||||
Text("Actual: ")
|
||||
Text(String(actualRepsDone))
|
||||
} else {
|
||||
Text("Actual: ")
|
||||
TextField("", text: .constant(""))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
// State
|
||||
// var isPaused: Bool
|
||||
var isPaused = false
|
||||
// var isCancelled: Bool
|
||||
// var isDeleted: Bool
|
||||
// var isSynced: Bool
|
||||
@@ -34,9 +34,10 @@ final class WorkoutSession: Nameable {
|
||||
// My workout session was completed at:
|
||||
var stopDate: Date? = nil
|
||||
// My workout session took me x seconds.
|
||||
var duration: TimeInterval? = nil
|
||||
var workoutDuration: TimeInterval = 0.0
|
||||
var pauseDuration: TimeInterval = 0.0
|
||||
// My workout session is completed and moved to the workout log.
|
||||
var isCompleted: Bool = false
|
||||
var isCompleted = false
|
||||
|
||||
// Exercise Progress
|
||||
var currentExercise = 0
|
||||
@@ -46,20 +47,19 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
// MARK: -- Workout Controls
|
||||
// func start(with workout: Workout) {
|
||||
// self.workout = workout
|
||||
// startDate = Date.now
|
||||
// }
|
||||
|
||||
func pause() {
|
||||
// TODO: Implement proper Pause
|
||||
}
|
||||
// func pause() {
|
||||
// isPaused = true
|
||||
// }
|
||||
//
|
||||
// func resume() {
|
||||
// isPaused = false
|
||||
// }
|
||||
|
||||
// Call stop() to terminate the workout.
|
||||
func stop() {
|
||||
isCompleted = true
|
||||
stopDate = Date.now
|
||||
duration = stopDate!.timeIntervalSince(startDate)
|
||||
// duration = stopDate!.timeIntervalSince(startDate)
|
||||
}
|
||||
|
||||
func prevExercise() {
|
||||
@@ -69,7 +69,7 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
func nextExercise() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: -- Workout Information
|
||||
|
||||
@@ -16,9 +16,10 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
||||
|
||||
var workoutSession: WorkoutSession
|
||||
|
||||
var plannedReps: Int // 8 times | 1 time
|
||||
var plannedValue: Double // With 10 | 42,187
|
||||
var metric: ExerciseMetric? // kg (weight) | km (distance)
|
||||
var plannedReps: Int // 8 times | 1 time
|
||||
var plannedValue: Double // With 10 | 42,187
|
||||
var unit: ExerciseUnit
|
||||
var metric: ExerciseMetric? // kg (weight) | km (distance)
|
||||
|
||||
var actualReps: Int?
|
||||
var actualValue: Double?
|
||||
@@ -29,6 +30,7 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
||||
self.position = planned.position
|
||||
self.plannedReps = planned.plannedReps
|
||||
self.plannedValue = planned.plannedValue
|
||||
self.unit = planned.unit
|
||||
self.metric = planned.metric
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user