clean up ActiveWorkoutSession
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
//
|
||||
// Created by Felix Förtsch on 12.09.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
@@ -15,22 +16,21 @@ struct ActiveWorkoutSession: View {
|
||||
|
||||
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("Exercises")) {
|
||||
ForEach(activeWorkoutSession.workoutSessionItems) { workoutItem in
|
||||
ActiveWorkoutSessionListItem(workoutItem: workoutItem)
|
||||
Section {
|
||||
ForEach(activeWorkoutSession.workoutSessionItems.reversed()) { workoutSessionItem in
|
||||
ActiveWorkoutSessionListItem(workoutSessionItem: workoutSessionItem)
|
||||
}
|
||||
}
|
||||
}.listStyle(.plain)
|
||||
|
||||
VStack {
|
||||
Text(activeWorkoutSession.name)
|
||||
ActiveWorkoutSessionControls(session: $activeWorkoutSession)
|
||||
}
|
||||
.frame(height: 200)
|
||||
}
|
||||
.background(.bar)
|
||||
// .navigationTitle(activeWorkoutSession.name)
|
||||
// .navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
|
||||
@@ -13,8 +13,13 @@ struct ActiveWorkoutSessionControls: View {
|
||||
var body: some View {
|
||||
|
||||
VStack {
|
||||
SimpleStopWatch(
|
||||
startDate: session.startDate,
|
||||
duration: $session.workoutDuration)
|
||||
.font(.system(.largeTitle, design: .monospaced))
|
||||
.fontWeight(.bold)
|
||||
HStack {
|
||||
Text(session.getCurrentTodo())
|
||||
Text(session.getCurrentExerciseName())
|
||||
.font(.system(size: 24, weight: .bold, design: .rounded))
|
||||
}
|
||||
ProgressView("",
|
||||
@@ -32,7 +37,7 @@ struct ActiveWorkoutSessionControls: View {
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.fontWeight(.bold)
|
||||
.tint(.primary)
|
||||
.tint(.accentColor)
|
||||
Button(action: {
|
||||
// TODO: Implement proper Pausing
|
||||
session.isPaused = true
|
||||
@@ -56,7 +61,7 @@ struct ActiveWorkoutSessionControls: View {
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.fontWeight(.bold)
|
||||
.tint(.primary)
|
||||
.tint(.accentColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,15 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ActiveWorkoutSessionListItem: View {
|
||||
var workoutItem: WorkoutSessionItem
|
||||
var workoutSessionItem: WorkoutSessionItem
|
||||
|
||||
var body: some View {
|
||||
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)
|
||||
Text(String(workoutSessionItem.plannedReps) + "x")
|
||||
Text(String(workoutSessionItem.plannedValue))
|
||||
|
||||
Text(workoutSessionItem.name)
|
||||
.fontWeight(.bold)
|
||||
Spacer()
|
||||
Button(action: {
|
||||
@@ -32,7 +29,7 @@ struct ActiveWorkoutSessionListItem: View {
|
||||
HStack {
|
||||
Text("Planned: ")
|
||||
|
||||
if let actualRepsDone = workoutItem.actualReps {
|
||||
if let actualRepsDone = workoutSessionItem.actualReps {
|
||||
Text("Actual: ")
|
||||
Text(String(actualRepsDone))
|
||||
} else {
|
||||
@@ -41,6 +38,11 @@ struct ActiveWorkoutSessionListItem: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.listRowBackground(
|
||||
workoutSessionItem.isCompleted()
|
||||
? Color.gray.opacity(0.2)
|
||||
: nil
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +50,8 @@ struct ActiveWorkoutSessionListItem: View {
|
||||
@Previewable @State var workoutSession = WorkoutSession(start: Workout.sampleData.first!)
|
||||
List {
|
||||
ForEach(WorkoutItem.sampleDataRecommendedRoutine) { item in
|
||||
ActiveWorkoutSessionListItem(workoutItem: WorkoutSessionItem(workoutSession: workoutSession, planned: item))
|
||||
ActiveWorkoutSessionListItem(workoutSessionItem: WorkoutSessionItem(workoutSession: workoutSession, planned: item))
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,7 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
}
|
||||
|
||||
// State
|
||||
var isPaused = false
|
||||
// var isCancelled: Bool
|
||||
// var isDeleted: Bool
|
||||
// var isSynced: Bool
|
||||
|
||||
// My workout session started at:
|
||||
var startDate: Date = Date.now
|
||||
@@ -36,14 +32,12 @@ final class WorkoutSession: Nameable {
|
||||
// My workout session took me x seconds.
|
||||
var workoutDuration: TimeInterval = 0.0
|
||||
var pauseDuration: TimeInterval = 0.0
|
||||
// My workout session is completed and moved to the workout log.
|
||||
var isCompleted = false
|
||||
|
||||
// Exercise Progress
|
||||
var currentExercise = 0
|
||||
|
||||
func isActive() -> Bool {
|
||||
return stopDate == nil
|
||||
func isCompleted() -> Bool {
|
||||
stopDate != nil
|
||||
}
|
||||
|
||||
// MARK: -- Workout Controls
|
||||
@@ -56,20 +50,25 @@ final class WorkoutSession: Nameable {
|
||||
// }
|
||||
|
||||
// Call stop() to terminate the workout.
|
||||
func stop() {
|
||||
isCompleted = true
|
||||
func stop() -> WorkoutLogItem {
|
||||
stopDate = Date.now
|
||||
// duration = stopDate!.timeIntervalSince(startDate)
|
||||
|
||||
return WorkoutLogItem(log: self)
|
||||
}
|
||||
|
||||
func prevExercise() {
|
||||
workoutSessionItems[currentExercise].startDate = Date.now
|
||||
if currentExercise > 0 {
|
||||
currentExercise -= 1
|
||||
}
|
||||
}
|
||||
|
||||
func nextExercise() {
|
||||
|
||||
workoutSessionItems[currentExercise].stopDate = Date.now
|
||||
if currentExercise < workoutSessionItems.count - 1 {
|
||||
currentExercise += 1
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -- Workout Information
|
||||
@@ -82,22 +81,14 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
func getTotalExerciseCount() -> Double {
|
||||
return 100.0
|
||||
return Double(workoutSessionItems.count)
|
||||
}
|
||||
|
||||
func getCurrentExerciseIndex() -> Double {
|
||||
return Double(currentExercise)
|
||||
}
|
||||
|
||||
func getCurrentTodo() -> String {
|
||||
return getCurrentExerciseMetric() + " " + getCurrentExerciseName()
|
||||
}
|
||||
|
||||
func getCurrentExerciseName() -> String {
|
||||
return "Hello"
|
||||
}
|
||||
|
||||
func getCurrentExerciseMetric() -> String {
|
||||
return "Hello"
|
||||
return workoutSessionItems[currentExercise].name
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,15 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
||||
|
||||
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 unit: ExerciseUnit?
|
||||
var metric: ExerciseType? // kg (weight) | km (distance)
|
||||
|
||||
var actualReps: Int?
|
||||
var actualValue: Double?
|
||||
|
||||
var startDate: Date?
|
||||
var stopDate: Date?
|
||||
func isCompleted() -> Bool { stopDate != nil }
|
||||
|
||||
init(workoutSession: WorkoutSession, planned: WorkoutItem) {
|
||||
self.workoutSession = workoutSession
|
||||
@@ -33,8 +34,6 @@ 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
|
||||
}
|
||||
|
||||
func start() { startDate = .now }
|
||||
|
||||
Reference in New Issue
Block a user