clean up ActiveWorkoutSession
This commit is contained in:
@@ -142,7 +142,6 @@ struct ValueKeyboard: View {
|
|||||||
@Previewable @State var isPresented: Bool = true
|
@Previewable @State var isPresented: Bool = true
|
||||||
|
|
||||||
let value = 0
|
let value = 0
|
||||||
let unit = ExerciseMetric.allCases
|
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
// ValueKeyboard(isPresented: $isPresented, value: value, unit: unit)
|
// ValueKeyboard(isPresented: $isPresented, value: value, unit: unit)
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ struct ContentView: View {
|
|||||||
case .workoutLibrary:
|
case .workoutLibrary:
|
||||||
WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession)
|
WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession)
|
||||||
case .workoutLog:
|
case .workoutLog:
|
||||||
WorkoutLog()
|
WorkoutLogs()
|
||||||
case .exerciseLibrary:
|
case .exerciseLibrary:
|
||||||
ExerciseLibrary()
|
ExerciseLibrary()
|
||||||
case .settings:
|
case .settings:
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
//
|
||||||
|
// AddExercise.swift
|
||||||
|
// WorkoutsPlus
|
||||||
|
//
|
||||||
|
// Created by Felix Förtsch on 21.09.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import SwiftData
|
||||||
|
|
||||||
|
struct AddExercise: View {
|
||||||
|
@Environment(\.modelContext) private var modelContext
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
var isPresentedAsSheet: Bool = false
|
||||||
|
|
||||||
|
@State var exercise: Exercise = Exercise("")
|
||||||
|
|
||||||
|
@State private var name: String = ""
|
||||||
|
@State private var description: String = ""
|
||||||
|
@State private var type = ExerciseType("")
|
||||||
|
@State private var unit = ExerciseUnit("", symbol: "")
|
||||||
|
|
||||||
|
@State private var isPartOfProgression: Bool = false
|
||||||
|
|
||||||
|
@Query(sort: \ExerciseType.name) private var exerciseTypes: [ExerciseType]
|
||||||
|
@Query(sort: \ExerciseUnit.name) private var exerciseUnits: [ExerciseUnit]
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
VStack {
|
||||||
|
Form {
|
||||||
|
Section {
|
||||||
|
TextField("Exercise Name", text: $name)
|
||||||
|
// TODO: Add Autocomplete
|
||||||
|
TextEditorWithPlaceholder(text: $description, placeholder: "Description (optional)")
|
||||||
|
}
|
||||||
|
Section(footer: Text("""
|
||||||
|
Examples:
|
||||||
|
• Pull-up → None
|
||||||
|
• Weighted Pull-up → Weight
|
||||||
|
• Sprint → Time or Distance
|
||||||
|
""")) {
|
||||||
|
Picker("Exercise Type", selection: $type) {
|
||||||
|
ForEach(exerciseTypes, id: \.self) { type in
|
||||||
|
Text("\(type.name)").tag(type as ExerciseType?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(NavigationLinkPickerStyle())
|
||||||
|
Picker("Exercise Unit", selection: $unit) {
|
||||||
|
ForEach(exerciseUnits, id: \.self) { unit in
|
||||||
|
Text("\(unit.name) (\(unit.symbol))").tag(unit as ExerciseUnit?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(NavigationLinkPickerStyle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("Add New Exercise")
|
||||||
|
.toolbar {
|
||||||
|
if isPresentedAsSheet {
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button("Cancel", role: .cancel) {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
Button("Save") {
|
||||||
|
withAnimation {
|
||||||
|
save()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func save() {
|
||||||
|
let exerciseToSave = Exercise(name)
|
||||||
|
modelContext.insert(exerciseToSave)
|
||||||
|
|
||||||
|
exerciseToSave.name = name
|
||||||
|
exerciseToSave.exerciseDescription = description
|
||||||
|
exerciseToSave.type = type
|
||||||
|
exerciseToSave.isPartOfProgression = isPartOfProgression
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
AddExercise()
|
||||||
|
}
|
||||||
@@ -26,53 +26,42 @@ final class Exercise: Nameable {
|
|||||||
@Attribute(.unique) var name: String
|
@Attribute(.unique) var name: String
|
||||||
var exerciseDescription = ""
|
var exerciseDescription = ""
|
||||||
|
|
||||||
var metric = ExerciseMetric.none
|
var type: ExerciseType?
|
||||||
var unit: ExerciseUnit
|
var unit: ExerciseUnit?
|
||||||
|
|
||||||
var isPartOfProgression = false
|
var isPartOfProgression = false
|
||||||
|
|
||||||
var equipment: [Equipment] = []
|
var equipment: [Equipment] = []
|
||||||
|
|
||||||
init(_ name: String, _ metric: ExerciseMetric = .none) {
|
init(_ name: String) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.metric = metric
|
|
||||||
self.unit = ExerciseUnit(name: "Meters", symbol: "m")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExerciseMetric: String, Codable, CaseIterable, Identifiable {
|
|
||||||
case none = ""
|
|
||||||
case distance = "Distance"
|
|
||||||
case time = "Time"
|
|
||||||
case weight = "Weight"
|
|
||||||
|
|
||||||
var id: Self { self }
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Exercise {
|
extension Exercise {
|
||||||
static let sampleDataRecommendedRoutine: [Exercise] = [
|
static let sampleDataRecommendedRoutine: [Exercise] = [
|
||||||
Exercise("Shoulder Band Warm-up"),
|
Exercise("Shoulder Band Warm-up"),
|
||||||
Exercise("Squat Sky Reaches"),
|
Exercise("Squat Sky Reaches"),
|
||||||
Exercise("GMB Wrist Prep", .time),
|
Exercise("GMB Wrist Prep"),
|
||||||
Exercise("Dead Bugs"),
|
Exercise("Dead Bugs"),
|
||||||
Exercise("Pull-up Progression", .weight),
|
Exercise("Pull-up Progression"),
|
||||||
Exercise("Dip Progression", .weight),
|
Exercise("Dip Progression"),
|
||||||
Exercise("Squat Progression", .weight),
|
Exercise("Squat Progression"),
|
||||||
Exercise("Hinge Progression", .weight),
|
Exercise("Hinge Progression"),
|
||||||
Exercise("Row Progression", .weight),
|
Exercise("Row Progression"),
|
||||||
Exercise("Push-up Progression", .weight),
|
Exercise("Push-up Progression"),
|
||||||
Exercise("Handstand Practice", .time),
|
Exercise("Handstand Practice"),
|
||||||
Exercise("Support Practice", .time)
|
Exercise("Support Practice")
|
||||||
]
|
]
|
||||||
|
|
||||||
static let sampleDataRings: [Exercise] = [
|
static let sampleDataRings: [Exercise] = [
|
||||||
Exercise("Dips", .weight),
|
Exercise("Dips"),
|
||||||
Exercise("Chin-ups", .weight),
|
Exercise("Chin-ups"),
|
||||||
Exercise("Push-ups", .weight),
|
Exercise("Push-ups"),
|
||||||
Exercise("Inverted Rows", .weight),
|
Exercise("Inverted Rows"),
|
||||||
Exercise("Hanging Knee Raises", .weight),
|
Exercise("Hanging Knee Raises"),
|
||||||
Exercise("Pistol Squats", .weight),
|
Exercise("Pistol Squats"),
|
||||||
Exercise("Hanging Leg Curls", .weight),
|
Exercise("Hanging Leg Curls"),
|
||||||
Exercise("Sissy Squats")
|
Exercise("Sissy Squats")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,56 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SwiftData
|
||||||
|
|
||||||
struct ExerciseDetail: View {
|
struct ExerciseDetail: View {
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@Environment(\.modelContext) private var modelContext
|
@Environment(\.modelContext) private var modelContext
|
||||||
|
|
||||||
@State var exercise: Exercise
|
@State var exercise: Exercise
|
||||||
|
@State private var description: String = ""
|
||||||
|
@State private var isPartOfProgression: Bool = false
|
||||||
|
|
||||||
|
@State private var type: ExerciseType?
|
||||||
|
@State private var unit: ExerciseUnit?
|
||||||
|
|
||||||
|
@Query(sort: \ExerciseType.name) private var exerciseTypes: [ExerciseType]
|
||||||
|
@Query(sort: \ExerciseUnit.name) private var exerciseUnits: [ExerciseUnit]
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
|
Section {
|
||||||
TextField("Exercise Name", text: $exercise.name)
|
TextField("Exercise Name", text: $exercise.name)
|
||||||
|
TextEditorWithPlaceholder(text: $description, placeholder: "Description (optional)")
|
||||||
|
}
|
||||||
|
Section(footer: Text("""
|
||||||
|
Examples:
|
||||||
|
• Pull-up → None
|
||||||
|
• Weighted Pull-up → Weight
|
||||||
|
• Sprint → Time or Distance
|
||||||
|
""")) {
|
||||||
|
Picker("Exercise Type", selection: $type) {
|
||||||
|
ForEach(exerciseTypes, id: \.self) { type in
|
||||||
|
Text("\(type.name)").tag(type as ExerciseType?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(NavigationLinkPickerStyle())
|
||||||
|
Picker("Exercise Unit", selection: $unit) {
|
||||||
|
ForEach(exerciseUnits, id: \.self) { unit in
|
||||||
|
Text("\(unit.name) (\(unit.symbol))").tag(unit as ExerciseUnit?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(NavigationLinkPickerStyle())
|
||||||
|
}
|
||||||
|
Section(footer: Text("Feature coming soon.")) {
|
||||||
|
Toggle(isOn: $isPartOfProgression) {
|
||||||
|
Text("Exercise is Part of a Progression")
|
||||||
|
.foregroundStyle(.gray)
|
||||||
|
}
|
||||||
|
.disabled(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("Edit Exercise")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
Button("Save") {
|
Button("Save") {
|
||||||
@@ -25,8 +65,6 @@ struct ExerciseDetail: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Exercise Details")
|
|
||||||
}
|
|
||||||
|
|
||||||
private func saveItem() {
|
private func saveItem() {
|
||||||
if modelContext.hasChanges {
|
if modelContext.hasChanges {
|
||||||
@@ -41,6 +79,6 @@ struct ExerciseDetail: View {
|
|||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ExerciseDetail(exercise: Exercise.sampleDataRecommendedRoutine.first!)
|
ExerciseDetail(exercise: Exercise("Squat Sky Reaches"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
//
|
|
||||||
// AddExercise.swift
|
|
||||||
// WorkoutsPlus
|
|
||||||
//
|
|
||||||
// Created by Felix Förtsch on 21.09.24.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import SwiftData
|
|
||||||
|
|
||||||
struct ExerciseEditor: View {
|
|
||||||
@Environment(\.modelContext) private var modelContext
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
|
||||||
var isPresentedAsSheet: Bool = false
|
|
||||||
|
|
||||||
@State var exercise: Exercise?
|
|
||||||
|
|
||||||
@State private var name: String = ""
|
|
||||||
@State private var description: String = ""
|
|
||||||
@State private var metric = ExerciseMetric.none
|
|
||||||
@State private var unit = ExerciseUnit(name: "", symbol: "")
|
|
||||||
|
|
||||||
@State private var isPartOfProgression: Bool = false
|
|
||||||
|
|
||||||
let exerciseUnits = ExerciseUnit.getUnits
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
NavigationStack {
|
|
||||||
VStack {
|
|
||||||
ScrollViewReader { proxy in
|
|
||||||
VStack {
|
|
||||||
Form {
|
|
||||||
Section {
|
|
||||||
TextField("Exercise Name", text: $name)
|
|
||||||
// TODO: Add Autocomplete
|
|
||||||
TextEditorWithPlaceholder(text: $description, placeholder: "Description (optional)")
|
|
||||||
}
|
|
||||||
Section(footer: Text("""
|
|
||||||
Examples:
|
|
||||||
• Pull-up → None
|
|
||||||
• Weighted Pull-up → Weight
|
|
||||||
• Sprint → Time or Distance
|
|
||||||
""")) {
|
|
||||||
Picker("Exercise Metric", selection: $metric) {
|
|
||||||
ForEach(ExerciseMetric.allCases) { metric in
|
|
||||||
Text(metric.rawValue.isEmpty ? "None" : metric.rawValue)
|
|
||||||
.tag(metric)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(SegmentedPickerStyle())
|
|
||||||
Picker("Select Exercise Unit", selection: $unit) {
|
|
||||||
ForEach(exerciseUnits, id: \.self) { unit in
|
|
||||||
Text("\(unit.name) (\(unit.symbol))").tag(unit as ExerciseUnit?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(NavigationLinkPickerStyle())
|
|
||||||
}
|
|
||||||
Section(footer: Text("Feature coming soon.")) {
|
|
||||||
Toggle(isOn: $isPartOfProgression) {
|
|
||||||
Text("Exercise is Part of a Progression")
|
|
||||||
.foregroundStyle(.gray)
|
|
||||||
}
|
|
||||||
.disabled(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.navigationTitle("Edit")
|
|
||||||
.toolbar {
|
|
||||||
if isPresentedAsSheet {
|
|
||||||
ToolbarItem(placement: .cancellationAction) {
|
|
||||||
Button("Cancel", role: .cancel) {
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
|
||||||
Button("Save") {
|
|
||||||
withAnimation {
|
|
||||||
save()
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onAppear {
|
|
||||||
if let exercise {
|
|
||||||
self.name = exercise.name
|
|
||||||
self.description = exercise.exerciseDescription
|
|
||||||
self.metric = exercise.metric
|
|
||||||
self.isPartOfProgression = exercise.isPartOfProgression
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func save() {
|
|
||||||
let exerciseToSave: Exercise
|
|
||||||
|
|
||||||
if let exercise = exercise {
|
|
||||||
exerciseToSave = exercise
|
|
||||||
} else {
|
|
||||||
exerciseToSave = Exercise(name)
|
|
||||||
modelContext.insert(exerciseToSave)
|
|
||||||
}
|
|
||||||
|
|
||||||
exerciseToSave.name = name
|
|
||||||
exerciseToSave.exerciseDescription = description
|
|
||||||
exerciseToSave.metric = metric
|
|
||||||
exerciseToSave.isPartOfProgression = isPartOfProgression
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Preview {
|
|
||||||
ExerciseEditor()
|
|
||||||
}
|
|
||||||
@@ -31,17 +31,7 @@ struct ExerciseLibrary: View {
|
|||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
ForEach(filteredItems) { exercise in
|
ForEach(filteredItems) { exercise in
|
||||||
NavigationLink {
|
NavigationLink(destination: ExerciseDetail(exercise: exercise), label: {Text(exercise.name)})
|
||||||
ExerciseEditor(exercise: exercise)
|
|
||||||
} label: {
|
|
||||||
HStack {
|
|
||||||
Text(exercise.name)
|
|
||||||
Spacer()
|
|
||||||
// Text(exercise.metric.rawValue)
|
|
||||||
// .font(.footnote)
|
|
||||||
// .foregroundStyle(.gray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onDelete(perform: deleteExercise)
|
.onDelete(perform: deleteExercise)
|
||||||
if filteredItems.isEmpty {
|
if filteredItems.isEmpty {
|
||||||
@@ -66,7 +56,7 @@ struct ExerciseLibrary: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $isAddingExercise) {
|
.sheet(isPresented: $isAddingExercise) {
|
||||||
ExerciseEditor(isPresentedAsSheet: true)
|
AddExercise(isPresentedAsSheet: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// ExerciseType.swift
|
||||||
|
// WorkoutsPlus
|
||||||
|
//
|
||||||
|
// Created by Felix Förtsch on 09.11.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftData
|
||||||
|
|
||||||
|
@Model
|
||||||
|
final class ExerciseType: Identifiable {
|
||||||
|
@Attribute(.unique) var name: String
|
||||||
|
|
||||||
|
@Relationship(deleteRule: .nullify, inverse: \Exercise.type)
|
||||||
|
var exercises = [Exercise]()
|
||||||
|
|
||||||
|
init(_ name: String) {
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ExerciseType {
|
||||||
|
static let getTypes = [
|
||||||
|
ExerciseType("Kilograms"),
|
||||||
|
ExerciseType("Kilometers"),
|
||||||
|
ExerciseType("Meters"),
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -9,20 +9,23 @@ import Foundation
|
|||||||
import SwiftData
|
import SwiftData
|
||||||
|
|
||||||
@Model
|
@Model
|
||||||
final class ExerciseUnit: Unit {
|
final class ExerciseUnit: Unit, Identifiable {
|
||||||
var name: String
|
@Attribute(.unique) var name: String
|
||||||
var symbol: String
|
@Attribute(.unique) var symbol: String
|
||||||
|
|
||||||
init(name: String, symbol: String) {
|
@Relationship(deleteRule: .cascade, inverse: \Exercise.unit)
|
||||||
|
var exercises = [Exercise]()
|
||||||
|
|
||||||
|
init(_ name: String, symbol: String) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ExerciseUnit: Identifiable {
|
extension ExerciseUnit {
|
||||||
static let getUnits = [
|
static let getUnits = [
|
||||||
ExerciseUnit(name: "Kilograms", symbol: "kg"),
|
ExerciseUnit("Kilograms", symbol: "kg"),
|
||||||
ExerciseUnit(name: "Kilometers", symbol: "km"),
|
ExerciseUnit("Kilometers", symbol: "km"),
|
||||||
ExerciseUnit(name: "Meters", symbol: "m"),
|
ExerciseUnit("Meters", symbol: "m"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ final class WorkoutItem: Nameable, Positionable {
|
|||||||
var exercise: Exercise // Do Push-up | Run Marathon
|
var exercise: Exercise // Do Push-up | Run Marathon
|
||||||
var plannedReps: Int // 8 times | 1 time
|
var plannedReps: Int // 8 times | 1 time
|
||||||
var plannedValue: Double // With 10 | 42,187
|
var plannedValue: Double // With 10 | 42,187
|
||||||
var unit: ExerciseUnit
|
|
||||||
var metric: ExerciseMetric? // kg (weight) | km (distance)
|
var unit: ExerciseUnit?
|
||||||
|
var type: ExerciseType?
|
||||||
|
|
||||||
enum WorkoutItemType: Codable {
|
enum WorkoutItemType: Codable {
|
||||||
case exercise
|
case exercise
|
||||||
@@ -64,8 +65,6 @@ final class WorkoutItem: Nameable, Positionable {
|
|||||||
self.plannedReps = 1
|
self.plannedReps = 1
|
||||||
// 0
|
// 0
|
||||||
self.plannedValue = 0
|
self.plannedValue = 0
|
||||||
// kg
|
|
||||||
self.unit = exercise.unit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init(set: [WorkoutItem] = []) {
|
// init(set: [WorkoutItem] = []) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ struct WorkoutListItem: View {
|
|||||||
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Push-ups")))
|
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Push-ups")))
|
||||||
// WorkoutListItem(Workout(name: "RR"), WorkoutItem(rest: 15))
|
// WorkoutListItem(Workout(name: "RR"), WorkoutItem(rest: 15))
|
||||||
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Push-ups")))
|
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Push-ups")))
|
||||||
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Sprint", .distance)))
|
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Sprint")))
|
||||||
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Run", .time)))
|
WorkoutListItem(Workout(name: "RR"), WorkoutItem(Exercise("Run")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// WorkoutLogItem.swift
|
||||||
|
// WorkoutsPlus
|
||||||
|
//
|
||||||
|
// Created by Felix Förtsch on 05.11.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftData
|
||||||
|
|
||||||
|
@Model
|
||||||
|
class WorkoutLogItem {
|
||||||
|
var date = Date.now
|
||||||
|
var workoutSession: WorkoutSession
|
||||||
|
|
||||||
|
init(log session: WorkoutSession) {
|
||||||
|
workoutSession = session
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -8,7 +8,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SwiftData
|
import SwiftData
|
||||||
|
|
||||||
struct WorkoutLog: View {
|
struct WorkoutLogs: View {
|
||||||
@Environment(\.modelContext) private var modelContext
|
@Environment(\.modelContext) private var modelContext
|
||||||
@Query(sort: \WorkoutSession.name) private var workoutSessions: [WorkoutSession]
|
@Query(sort: \WorkoutSession.name) private var workoutSessions: [WorkoutSession]
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ struct WorkoutLog: View {
|
|||||||
|
|
||||||
#Preview("Active WorkoutSession") {
|
#Preview("Active WorkoutSession") {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
WorkoutLog()
|
WorkoutLogs()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
Defaults.shared.isWorkingOut = true
|
Defaults.shared.isWorkingOut = true
|
||||||
}
|
}
|
||||||
@@ -105,5 +105,5 @@ struct WorkoutLog: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview("No Active WorkoutSession") {
|
#Preview("No Active WorkoutSession") {
|
||||||
WorkoutLog()
|
WorkoutLogs()
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
// Created by Felix Förtsch on 12.09.24.
|
// Created by Felix Förtsch on 12.09.24.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SwiftData
|
import SwiftData
|
||||||
|
|
||||||
@@ -15,22 +16,21 @@ struct ActiveWorkoutSession: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
|
List {
|
||||||
|
Section {
|
||||||
|
ForEach(activeWorkoutSession.workoutSessionItems.reversed()) { workoutSessionItem in
|
||||||
|
ActiveWorkoutSessionListItem(workoutSessionItem: workoutSessionItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.listStyle(.plain)
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
Text(activeWorkoutSession.name)
|
Text(activeWorkoutSession.name)
|
||||||
SimpleStopWatch(
|
ActiveWorkoutSessionControls(session: $activeWorkoutSession)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.frame(height: 200)
|
||||||
}
|
}
|
||||||
|
.background(.bar)
|
||||||
// .navigationTitle(activeWorkoutSession.name)
|
// .navigationTitle(activeWorkoutSession.name)
|
||||||
// .navigationBarTitleDisplayMode(.inline)
|
// .navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|||||||
@@ -13,8 +13,13 @@ struct ActiveWorkoutSessionControls: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
|
SimpleStopWatch(
|
||||||
|
startDate: session.startDate,
|
||||||
|
duration: $session.workoutDuration)
|
||||||
|
.font(.system(.largeTitle, design: .monospaced))
|
||||||
|
.fontWeight(.bold)
|
||||||
HStack {
|
HStack {
|
||||||
Text(session.getCurrentTodo())
|
Text(session.getCurrentExerciseName())
|
||||||
.font(.system(size: 24, weight: .bold, design: .rounded))
|
.font(.system(size: 24, weight: .bold, design: .rounded))
|
||||||
}
|
}
|
||||||
ProgressView("",
|
ProgressView("",
|
||||||
@@ -32,7 +37,7 @@ struct ActiveWorkoutSessionControls: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
.tint(.primary)
|
.tint(.accentColor)
|
||||||
Button(action: {
|
Button(action: {
|
||||||
// TODO: Implement proper Pausing
|
// TODO: Implement proper Pausing
|
||||||
session.isPaused = true
|
session.isPaused = true
|
||||||
@@ -56,7 +61,7 @@ struct ActiveWorkoutSessionControls: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
.tint(.primary)
|
.tint(.accentColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,15 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ActiveWorkoutSessionListItem: View {
|
struct ActiveWorkoutSessionListItem: View {
|
||||||
var workoutItem: WorkoutSessionItem
|
var workoutSessionItem: WorkoutSessionItem
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
HStack {
|
HStack {
|
||||||
Text(String(workoutItem.plannedReps) + "x")
|
Text(String(workoutSessionItem.plannedReps) + "x")
|
||||||
Text(String(workoutItem.plannedValue))
|
Text(String(workoutSessionItem.plannedValue))
|
||||||
Text(String(workoutItem.unit.symbol))
|
|
||||||
if let metric = workoutItem.metric {
|
Text(workoutSessionItem.name)
|
||||||
Text(metric.rawValue)
|
|
||||||
}
|
|
||||||
Text(workoutItem.name)
|
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: {
|
Button(action: {
|
||||||
@@ -32,7 +29,7 @@ struct ActiveWorkoutSessionListItem: View {
|
|||||||
HStack {
|
HStack {
|
||||||
Text("Planned: ")
|
Text("Planned: ")
|
||||||
|
|
||||||
if let actualRepsDone = workoutItem.actualReps {
|
if let actualRepsDone = workoutSessionItem.actualReps {
|
||||||
Text("Actual: ")
|
Text("Actual: ")
|
||||||
Text(String(actualRepsDone))
|
Text(String(actualRepsDone))
|
||||||
} else {
|
} 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!)
|
@Previewable @State var workoutSession = WorkoutSession(start: Workout.sampleData.first!)
|
||||||
List {
|
List {
|
||||||
ForEach(WorkoutItem.sampleDataRecommendedRoutine) { item in
|
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 isPaused = false
|
||||||
// var isCancelled: Bool
|
|
||||||
// var isDeleted: Bool
|
|
||||||
// var isSynced: Bool
|
|
||||||
|
|
||||||
// My workout session started at:
|
// My workout session started at:
|
||||||
var startDate: Date = Date.now
|
var startDate: Date = Date.now
|
||||||
@@ -36,14 +32,12 @@ final class WorkoutSession: Nameable {
|
|||||||
// My workout session took me x seconds.
|
// My workout session took me x seconds.
|
||||||
var workoutDuration: TimeInterval = 0.0
|
var workoutDuration: TimeInterval = 0.0
|
||||||
var pauseDuration: TimeInterval = 0.0
|
var pauseDuration: TimeInterval = 0.0
|
||||||
// My workout session is completed and moved to the workout log.
|
|
||||||
var isCompleted = false
|
|
||||||
|
|
||||||
// Exercise Progress
|
// Exercise Progress
|
||||||
var currentExercise = 0
|
var currentExercise = 0
|
||||||
|
|
||||||
func isActive() -> Bool {
|
func isCompleted() -> Bool {
|
||||||
return stopDate == nil
|
stopDate != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: -- Workout Controls
|
// MARK: -- Workout Controls
|
||||||
@@ -56,20 +50,25 @@ final class WorkoutSession: Nameable {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// Call stop() to terminate the workout.
|
// Call stop() to terminate the workout.
|
||||||
func stop() {
|
func stop() -> WorkoutLogItem {
|
||||||
isCompleted = true
|
|
||||||
stopDate = Date.now
|
stopDate = Date.now
|
||||||
// duration = stopDate!.timeIntervalSince(startDate)
|
// duration = stopDate!.timeIntervalSince(startDate)
|
||||||
|
|
||||||
|
return WorkoutLogItem(log: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prevExercise() {
|
func prevExercise() {
|
||||||
|
workoutSessionItems[currentExercise].startDate = Date.now
|
||||||
if currentExercise > 0 {
|
if currentExercise > 0 {
|
||||||
currentExercise -= 1
|
currentExercise -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func nextExercise() {
|
func nextExercise() {
|
||||||
|
workoutSessionItems[currentExercise].stopDate = Date.now
|
||||||
|
if currentExercise < workoutSessionItems.count - 1 {
|
||||||
|
currentExercise += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: -- Workout Information
|
// MARK: -- Workout Information
|
||||||
@@ -82,22 +81,14 @@ final class WorkoutSession: Nameable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTotalExerciseCount() -> Double {
|
func getTotalExerciseCount() -> Double {
|
||||||
return 100.0
|
return Double(workoutSessionItems.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentExerciseIndex() -> Double {
|
func getCurrentExerciseIndex() -> Double {
|
||||||
return Double(currentExercise)
|
return Double(currentExercise)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentTodo() -> String {
|
|
||||||
return getCurrentExerciseMetric() + " " + getCurrentExerciseName()
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCurrentExerciseName() -> String {
|
func getCurrentExerciseName() -> String {
|
||||||
return "Hello"
|
return workoutSessionItems[currentExercise].name
|
||||||
}
|
|
||||||
|
|
||||||
func getCurrentExerciseMetric() -> String {
|
|
||||||
return "Hello"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,15 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
|||||||
|
|
||||||
var plannedReps: Int // 8 times | 1 time
|
var plannedReps: Int // 8 times | 1 time
|
||||||
var plannedValue: Double // With 10 | 42,187
|
var plannedValue: Double // With 10 | 42,187
|
||||||
var unit: ExerciseUnit
|
var unit: ExerciseUnit?
|
||||||
var metric: ExerciseMetric? // kg (weight) | km (distance)
|
var metric: ExerciseType? // kg (weight) | km (distance)
|
||||||
|
|
||||||
var actualReps: Int?
|
var actualReps: Int?
|
||||||
var actualValue: Double?
|
var actualValue: Double?
|
||||||
|
|
||||||
var startDate: Date?
|
var startDate: Date?
|
||||||
var stopDate: Date?
|
var stopDate: Date?
|
||||||
|
func isCompleted() -> Bool { stopDate != nil }
|
||||||
|
|
||||||
init(workoutSession: WorkoutSession, planned: WorkoutItem) {
|
init(workoutSession: WorkoutSession, planned: WorkoutItem) {
|
||||||
self.workoutSession = workoutSession
|
self.workoutSession = workoutSession
|
||||||
@@ -33,8 +34,6 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
|||||||
self.position = planned.position
|
self.position = planned.position
|
||||||
self.plannedReps = planned.plannedReps
|
self.plannedReps = planned.plannedReps
|
||||||
self.plannedValue = planned.plannedValue
|
self.plannedValue = planned.plannedValue
|
||||||
self.unit = planned.unit
|
|
||||||
self.metric = planned.metric
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() { startDate = .now }
|
func start() { startDate = .now }
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ extension WorkoutsPlusApp {
|
|||||||
static let swiftDataSchema = Schema([
|
static let swiftDataSchema = Schema([
|
||||||
Exercise.self,
|
Exercise.self,
|
||||||
ExerciseUnit.self,
|
ExerciseUnit.self,
|
||||||
|
ExerciseType.self,
|
||||||
Equipment.self,
|
Equipment.self,
|
||||||
Workout.self,
|
Workout.self,
|
||||||
WorkoutItem.self,
|
WorkoutItem.self,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ erDiagram
|
|||||||
Workout 1 .. 0+ WorkoutItem : collects
|
Workout 1 .. 0+ WorkoutItem : collects
|
||||||
Workout 1 .. 0+ WorkoutSession : "starts"
|
Workout 1 .. 0+ WorkoutSession : "starts"
|
||||||
WorkoutItem 1 -- 1 WorkoutSessionItem : "provides data for"
|
WorkoutItem 1 -- 1 WorkoutSessionItem : "provides data for"
|
||||||
|
WorkoutItem 1 -- 0+ WorkoutItem : "collects"
|
||||||
WorkoutSession 1 -- 1+ WorkoutSessionItem : collects
|
WorkoutSession 1 -- 1+ WorkoutSessionItem : collects
|
||||||
ContentView 1 -- 1 WorkoutSession : "holds onto"
|
ContentView 1 -- 1 WorkoutSession : "holds onto"
|
||||||
|
|
||||||
@@ -14,18 +15,20 @@ erDiagram
|
|||||||
}
|
}
|
||||||
Workout {
|
Workout {
|
||||||
string name
|
string name
|
||||||
|
WorkoutItem[] workoutItems
|
||||||
}
|
}
|
||||||
WorkoutSession {
|
WorkoutSession {
|
||||||
Workout workout
|
Workout workout
|
||||||
time workoutSessionDuration
|
time workoutSessionDuration
|
||||||
}
|
}
|
||||||
WorkoutItem {
|
WorkoutItem {
|
||||||
Exercise exerciseData
|
Exercise exercise
|
||||||
|
WorkoutItem[] workoutItems
|
||||||
int plannedReps
|
int plannedReps
|
||||||
double plannedValue
|
double plannedValue
|
||||||
}
|
}
|
||||||
WorkoutSessionItem {
|
WorkoutSessionItem {
|
||||||
WorkoutItem exerciseData
|
WorkoutItem exercise
|
||||||
int actualReps
|
int actualReps
|
||||||
double actualValue
|
double actualValue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user