clean up ActiveWorkoutSession

This commit is contained in:
Felix Förtsch
2024-11-12 14:47:59 +01:00
parent 19b3d89010
commit 370e070fcd
20 changed files with 281 additions and 238 deletions
@@ -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
}
}