create ER diagram, refactor to conform to diagram, simplify session management
This commit is contained in:
@@ -13,22 +13,24 @@ final class WorkoutSession: Nameable {
|
||||
var id = UUID()
|
||||
var name = ""
|
||||
// The Workout is what *should* happen
|
||||
var workout: Workout? {
|
||||
var workout: Workout {
|
||||
didSet {
|
||||
self.name = workout?.name ?? "Unknown Workout"
|
||||
}
|
||||
}
|
||||
|
||||
init(start with: Workout) {
|
||||
self.workout = with
|
||||
}
|
||||
|
||||
// State
|
||||
// var isPaused: Bool
|
||||
// var isCancelled: Bool
|
||||
// var isDeleted: Bool
|
||||
// var isSynced: Bool
|
||||
|
||||
// Time
|
||||
var creationDate = Date.now
|
||||
// My workout session started at:
|
||||
var startDate: Date? = nil
|
||||
var startDate: Date = Date.now
|
||||
// My workout session was completed at:
|
||||
var stopDate: Date? = nil
|
||||
// My workout session took me x seconds.
|
||||
@@ -39,17 +41,15 @@ final class WorkoutSession: Nameable {
|
||||
// Exercise Progress
|
||||
var currentExercise = 0
|
||||
|
||||
init () { }
|
||||
|
||||
func isActive() -> Bool {
|
||||
return startDate != nil && stopDate == nil
|
||||
return stopDate == nil
|
||||
}
|
||||
|
||||
// MARK: -- Workout Controls
|
||||
func start(with workout: Workout) {
|
||||
self.workout = workout
|
||||
startDate = Date.now
|
||||
}
|
||||
// func start(with workout: Workout) {
|
||||
// self.workout = workout
|
||||
// startDate = Date.now
|
||||
// }
|
||||
|
||||
func pause() {
|
||||
// TODO: Implement proper Pause
|
||||
@@ -57,21 +57,18 @@ final class WorkoutSession: Nameable {
|
||||
|
||||
// Call stop() to terminate the workout.
|
||||
func stop() {
|
||||
guard let startDate = startDate else { return }
|
||||
isCompleted = true
|
||||
stopDate = Date.now
|
||||
duration = stopDate!.timeIntervalSince(startDate)
|
||||
}
|
||||
|
||||
func prevExercise() {
|
||||
guard workout != nil else { return }
|
||||
if currentExercise > 0 {
|
||||
currentExercise -= 1
|
||||
}
|
||||
}
|
||||
|
||||
func nextExercise() {
|
||||
guard let workout = workout else { return }
|
||||
if currentExercise < workout.getWorkoutItems().count - 1 {
|
||||
currentExercise += 1
|
||||
}
|
||||
@@ -79,7 +76,6 @@ final class WorkoutSession: Nameable {
|
||||
|
||||
// MARK: -- Workout Information
|
||||
func getFormattedDuration() -> String {
|
||||
guard let startDate = startDate else { return "00:00:00" }
|
||||
let elapsedTime = Date.now.timeIntervalSince(startDate)
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.allowedUnits = [.hour, .minute, .second]
|
||||
@@ -88,7 +84,6 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
func getTotalExerciseCount() -> Double {
|
||||
guard let workout = workout else { return 0 }
|
||||
return Double(workout.getWorkoutItems().count)
|
||||
}
|
||||
|
||||
@@ -101,12 +96,10 @@ final class WorkoutSession: Nameable {
|
||||
}
|
||||
|
||||
func getCurrentExerciseName() -> String {
|
||||
guard let workout = workout else { return "Unknown Workout" }
|
||||
return workout.getWorkoutItems()[Int(currentExercise)].name
|
||||
}
|
||||
|
||||
func getCurrentExerciseMetric() -> String {
|
||||
guard let workout = workout else { return "Unknown Workout" }
|
||||
return String(workout.getWorkoutItems()[Int(currentExercise)].reps)
|
||||
return String(workout.getWorkoutItems()[Int(currentExercise)].plannedReps)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user