change folders to the "feature" mindset
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// WorkoutSession.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 07.09.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftData
|
||||
|
||||
@Model
|
||||
final class WorkoutSession: Nameable {
|
||||
var id = UUID()
|
||||
var name: String
|
||||
// TODO: Think about if a refrence to the workout makes sense; a Workout could change.
|
||||
// var workout: Workout
|
||||
var workoutSessionItems: [WorkoutSessionItem] = []
|
||||
|
||||
init(start workout: Workout) {
|
||||
self.name = workout.name
|
||||
for workoutItem in workout.getWorkoutItems() {
|
||||
workoutSessionItems.append(WorkoutSessionItem(workoutSession: self, planned: workoutItem))
|
||||
}
|
||||
}
|
||||
|
||||
// State
|
||||
// var isPaused: Bool
|
||||
// var isCancelled: Bool
|
||||
// var isDeleted: Bool
|
||||
// var isSynced: Bool
|
||||
|
||||
// My workout session started at:
|
||||
var startDate: Date = Date.now
|
||||
// My workout session was completed at:
|
||||
var stopDate: Date? = nil
|
||||
// My workout session took me x seconds.
|
||||
var duration: TimeInterval? = nil
|
||||
// My workout session is completed and moved to the workout log.
|
||||
var isCompleted: Bool = false
|
||||
|
||||
// Exercise Progress
|
||||
var currentExercise = 0
|
||||
|
||||
func isActive() -> Bool {
|
||||
return stopDate == nil
|
||||
}
|
||||
|
||||
// MARK: -- Workout Controls
|
||||
// func start(with workout: Workout) {
|
||||
// self.workout = workout
|
||||
// startDate = Date.now
|
||||
// }
|
||||
|
||||
func pause() {
|
||||
// TODO: Implement proper Pause
|
||||
}
|
||||
|
||||
// Call stop() to terminate the workout.
|
||||
func stop() {
|
||||
isCompleted = true
|
||||
stopDate = Date.now
|
||||
duration = stopDate!.timeIntervalSince(startDate)
|
||||
}
|
||||
|
||||
func prevExercise() {
|
||||
if currentExercise > 0 {
|
||||
currentExercise -= 1
|
||||
}
|
||||
}
|
||||
|
||||
func nextExercise() {
|
||||
|
||||
}
|
||||
|
||||
// MARK: -- Workout Information
|
||||
func getFormattedDuration() -> String {
|
||||
let elapsedTime = Date.now.timeIntervalSince(startDate)
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.allowedUnits = [.hour, .minute, .second]
|
||||
formatter.unitsStyle = .positional
|
||||
return formatter.string(from: elapsedTime) ?? "00:00:00"
|
||||
}
|
||||
|
||||
func getTotalExerciseCount() -> Double {
|
||||
return 100.0
|
||||
}
|
||||
|
||||
func getCurrentExerciseIndex() -> Double {
|
||||
return Double(currentExercise)
|
||||
}
|
||||
|
||||
func getCurrentTodo() -> String {
|
||||
return getCurrentExerciseMetric() + " " + getCurrentExerciseName()
|
||||
}
|
||||
|
||||
func getCurrentExerciseName() -> String {
|
||||
return "Hello"
|
||||
}
|
||||
|
||||
func getCurrentExerciseMetric() -> String {
|
||||
return "Hello"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user