initial pre-viable version of watch app
This commit is contained in:
@ -27,7 +27,6 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
|
||||
// Reports Tab
|
||||
NavigationStack {
|
||||
Text("Reports Placeholder")
|
||||
.navigationTitle("Reports")
|
||||
@ -36,6 +35,14 @@ struct ContentView: View {
|
||||
Label("Reports", systemImage: "chart.bar")
|
||||
}
|
||||
|
||||
NavigationStack {
|
||||
Text("Achivements")
|
||||
.navigationTitle("Achievements")
|
||||
}
|
||||
.tabItem {
|
||||
Label("Achivements", systemImage: "star.fill")
|
||||
}
|
||||
|
||||
// SettingsView()
|
||||
// .tabItem {
|
||||
// Label("Settings", systemImage: "gear")
|
||||
|
@ -8,16 +8,19 @@ final class Exercise {
|
||||
var sets: Int = 0
|
||||
var reps: Int = 0
|
||||
var weight: Int = 0
|
||||
var weightLastUpdated: Date = Date()
|
||||
var weightReminderTimeIntervalWeeks: Int = 2
|
||||
|
||||
@Relationship(deleteRule: .nullify)
|
||||
var split: Split?
|
||||
|
||||
init(split: Split, exerciseName: String, order: Int, sets: Int, reps: Int, weight: Int) {
|
||||
init(split: Split, exerciseName: String, order: Int, sets: Int, reps: Int, weight: Int, weightReminderTimeIntervalWeeks: Int = 2) {
|
||||
self.split = split
|
||||
self.name = exerciseName
|
||||
self.order = order
|
||||
self.sets = sets
|
||||
self.reps = reps
|
||||
self.weight = weight
|
||||
self.weightReminderTimeIntervalWeeks = weightReminderTimeIntervalWeeks
|
||||
}
|
||||
}
|
||||
|
@ -31,29 +31,6 @@ final class Split {
|
||||
static let unnamed = "Unnamed Split"
|
||||
}
|
||||
|
||||
// MARK: - EditableEntity Conformance
|
||||
|
||||
extension Split: EditableEntity {
|
||||
var count: Int? {
|
||||
return self.exercises?.count
|
||||
}
|
||||
|
||||
static func createNew() -> Split {
|
||||
return Split(name: "")
|
||||
}
|
||||
|
||||
static var navigationTitle: String {
|
||||
return "Splits"
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
static func formView(for model: Split) -> some View {
|
||||
EntityAddEditView(model: model) { $model in
|
||||
SplitFormView(model: $model)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Identifiable Conformance
|
||||
|
||||
extension Split: Identifiable {
|
||||
@ -64,58 +41,58 @@ extension Split: Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private Form View
|
||||
|
||||
fileprivate struct SplitFormView: View {
|
||||
@Binding var model: Split
|
||||
|
||||
// Available colors for splits
|
||||
private let availableColors = ["red", "orange", "yellow", "green", "mint", "teal", "cyan", "blue", "indigo", "purple", "pink", "brown"]
|
||||
|
||||
// Available system images for splits
|
||||
private let availableIcons = ["dumbbell.fill", "figure.strengthtraining.traditional", "figure.run", "figure.hiking", "figure.cooldown", "figure.boxing", "figure.wrestling", "figure.gymnastics", "figure.handball", "figure.core.training", "heart.fill", "bolt.fill"]
|
||||
|
||||
var body: some View {
|
||||
Section(header: Text("Name")) {
|
||||
TextField("Name", text: $model.name)
|
||||
.bold()
|
||||
}
|
||||
|
||||
Section(header: Text("Appearance")) {
|
||||
Picker("Color", selection: $model.color) {
|
||||
ForEach(availableColors, id: \.self) { colorName in
|
||||
let tempSplit = Split(name: "", color: colorName)
|
||||
HStack {
|
||||
Circle()
|
||||
.fill(tempSplit.getColor())
|
||||
.frame(width: 20, height: 20)
|
||||
Text(colorName.capitalized)
|
||||
}
|
||||
.tag(colorName)
|
||||
}
|
||||
}
|
||||
|
||||
Picker("Icon", selection: $model.systemImage) {
|
||||
ForEach(availableIcons, id: \.self) { iconName in
|
||||
HStack {
|
||||
Image(systemName: iconName)
|
||||
.frame(width: 24, height: 24)
|
||||
Text(iconName.replacingOccurrences(of: ".fill", with: "").replacingOccurrences(of: "figure.", with: "").capitalized)
|
||||
}
|
||||
.tag(iconName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: Text("Exercises")) {
|
||||
NavigationLink {
|
||||
ExerciseListView(split: model)
|
||||
} label: {
|
||||
ListItem(
|
||||
text: "Exercises",
|
||||
count: model.exercises?.count ?? 0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//// MARK: - Private Form View
|
||||
//
|
||||
//fileprivate struct SplitFormView: View {
|
||||
// @Binding var model: Split
|
||||
//
|
||||
// // Available colors for splits
|
||||
// private let availableColors = ["red", "orange", "yellow", "green", "mint", "teal", "cyan", "blue", "indigo", "purple", "pink", "brown"]
|
||||
//
|
||||
// // Available system images for splits
|
||||
// private let availableIcons = ["dumbbell.fill", "figure.strengthtraining.traditional", "figure.run", "figure.hiking", "figure.cooldown", "figure.boxing", "figure.wrestling", "figure.gymnastics", "figure.handball", "figure.core.training", "heart.fill", "bolt.fill"]
|
||||
//
|
||||
// var body: some View {
|
||||
// Section(header: Text("Name")) {
|
||||
// TextField("Name", text: $model.name)
|
||||
// .bold()
|
||||
// }
|
||||
//
|
||||
// Section(header: Text("Appearance")) {
|
||||
// Picker("Color", selection: $model.color) {
|
||||
// ForEach(availableColors, id: \.self) { colorName in
|
||||
// let tempSplit = Split(name: "", color: colorName)
|
||||
// HStack {
|
||||
// Circle()
|
||||
// .fill(tempSplit.getColor())
|
||||
// .frame(width: 20, height: 20)
|
||||
// Text(colorName.capitalized)
|
||||
// }
|
||||
// .tag(colorName)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Picker("Icon", selection: $model.systemImage) {
|
||||
// ForEach(availableIcons, id: \.self) { iconName in
|
||||
// HStack {
|
||||
// Image(systemName: iconName)
|
||||
// .frame(width: 24, height: 24)
|
||||
// Text(iconName.replacingOccurrences(of: ".fill", with: "").replacingOccurrences(of: "figure.", with: "").capitalized)
|
||||
// }
|
||||
// .tag(iconName)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Section(header: Text("Exercises")) {
|
||||
// NavigationLink {
|
||||
// ExerciseListView(split: model)
|
||||
// } label: {
|
||||
// ListItem(
|
||||
// text: "Exercises",
|
||||
// count: model.exercises?.count ?? 0
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
9
Workouts/Utils/Date+formatDate.swift
Normal file
9
Workouts/Utils/Date+formatDate.swift
Normal file
@ -0,0 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
func formatDate() -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
return formatter.string(from: self)
|
||||
}
|
||||
}
|
9
Workouts/Utils/Date+formatedDate.swift
Normal file
9
Workouts/Utils/Date+formatedDate.swift
Normal file
@ -0,0 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
func formattedDate() -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
return formatter.string(from: self)
|
||||
}
|
||||
}
|
@ -9,30 +9,6 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum CheckboxStatus {
|
||||
case checked
|
||||
case unchecked
|
||||
case intermediate
|
||||
case cancelled
|
||||
|
||||
var color: Color {
|
||||
switch (self) {
|
||||
case .checked: .green
|
||||
case .unchecked: .gray
|
||||
case .intermediate: .yellow
|
||||
case .cancelled: .red
|
||||
}
|
||||
}
|
||||
|
||||
var systemName: String {
|
||||
switch (self) {
|
||||
case .checked: "checkmark.circle.fill"
|
||||
case .unchecked: "circle"
|
||||
case .intermediate: "ellipsis.circle"
|
||||
case .cancelled: "cross.circle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CheckboxListItem: View {
|
||||
var status: CheckboxStatus
|
||||
|
35
Workouts/Views/Common/CheckboxStatus.swift
Normal file
35
Workouts/Views/Common/CheckboxStatus.swift
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// CheckboxStatus.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/20/25 at 11:07 AM.
|
||||
//
|
||||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
import SwiftUICore
|
||||
|
||||
enum CheckboxStatus {
|
||||
case checked
|
||||
case unchecked
|
||||
case intermediate
|
||||
case cancelled
|
||||
|
||||
var color: Color {
|
||||
switch (self) {
|
||||
case .checked: .green
|
||||
case .unchecked: .gray
|
||||
case .intermediate: .yellow
|
||||
case .cancelled: .red
|
||||
}
|
||||
}
|
||||
|
||||
var systemName: String {
|
||||
switch (self) {
|
||||
case .checked: "checkmark.circle.fill"
|
||||
case .unchecked: "circle"
|
||||
case .intermediate: "ellipsis.circle"
|
||||
case .cancelled: "cross.circle"
|
||||
}
|
||||
}
|
||||
}
|
@ -16,19 +16,26 @@ struct ExerciseAddEditView: View {
|
||||
|
||||
@State var model: Exercise
|
||||
|
||||
@State var originalWeight: Int? = nil
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section(header: Text("Exercise")) {
|
||||
Button(action: {
|
||||
showingExercisePicker = true
|
||||
}) {
|
||||
HStack {
|
||||
Text(model.name.isEmpty ? "Select Exercise" : model.name)
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.foregroundColor(.gray)
|
||||
let exerciseName = model.name
|
||||
if exerciseName.isEmpty {
|
||||
Button(action: {
|
||||
showingExercisePicker = true
|
||||
}) {
|
||||
HStack {
|
||||
Text(model.name.isEmpty ? "Select Exercise" : model.name)
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ListItem(title: exerciseName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +59,20 @@ struct ExerciseAddEditView: View {
|
||||
.frame(width: 130)
|
||||
}
|
||||
}
|
||||
|
||||
Section (header: Text("Weight Increase")) {
|
||||
HStack {
|
||||
Text("Remind every \(model.weightReminderTimeIntervalWeeks) weeks")
|
||||
Spacer()
|
||||
Stepper("", value: $model.weightReminderTimeIntervalWeeks, in: 0...366)
|
||||
}
|
||||
HStack {
|
||||
Text("Last weight change \(Date().humanTimeInterval(to: model.weightLastUpdated)) ago")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
originalWeight = model.weight
|
||||
}
|
||||
.sheet(isPresented: $showingExercisePicker) {
|
||||
ExercisePickerView { exerciseNames in
|
||||
@ -68,6 +89,11 @@ struct ExerciseAddEditView: View {
|
||||
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Save") {
|
||||
if let originalWeight = originalWeight {
|
||||
if originalWeight != model.weight {
|
||||
model.weightLastUpdated = Date()
|
||||
}
|
||||
}
|
||||
try? modelContext.save()
|
||||
dismiss()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
import Charts
|
||||
|
||||
struct ExerciseView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@ -98,6 +99,10 @@ struct ExerciseView: View {
|
||||
}
|
||||
.font(.title)
|
||||
}
|
||||
|
||||
Section(header: Text("Progress Tracking")) {
|
||||
WeightProgressionChartView(exerciseName: workoutLog.exerciseName)
|
||||
}
|
||||
}
|
||||
.navigationTitle("\(workoutLog.exerciseName)")
|
||||
.navigationDestination(item: $navigateTo) { nextLog in
|
||||
|
142
Workouts/Views/Exercises/WeightProgressionChartView.swift
Normal file
142
Workouts/Views/Exercises/WeightProgressionChartView.swift
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// WeightProgressionChartView.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created on 7/20/25.
|
||||
//
|
||||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Charts
|
||||
import SwiftData
|
||||
|
||||
struct WeightProgressionChartView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
let exerciseName: String
|
||||
@State private var weightData: [WeightDataPoint] = []
|
||||
@State private var isLoading: Bool = true
|
||||
@State private var motivationalMessage: String = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
if isLoading {
|
||||
ProgressView("Loading data...")
|
||||
} else if weightData.isEmpty {
|
||||
Text("No weight history available yet.")
|
||||
.foregroundColor(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding()
|
||||
} else {
|
||||
Text("Weight Progression")
|
||||
.font(.headline)
|
||||
.padding(.bottom, 4)
|
||||
|
||||
Chart {
|
||||
ForEach(weightData) { dataPoint in
|
||||
LineMark(
|
||||
x: .value("Date", dataPoint.date),
|
||||
y: .value("Weight", dataPoint.weight)
|
||||
)
|
||||
.foregroundStyle(Color.blue.gradient)
|
||||
.interpolationMethod(.catmullRom)
|
||||
|
||||
PointMark(
|
||||
x: .value("Date", dataPoint.date),
|
||||
y: .value("Weight", dataPoint.weight)
|
||||
)
|
||||
.foregroundStyle(Color.blue)
|
||||
}
|
||||
}
|
||||
.chartYScale(domain: .automatic(includesZero: false))
|
||||
.chartXAxis {
|
||||
AxisMarks(values: .automatic) { value in
|
||||
AxisGridLine()
|
||||
AxisValueLabel(format: .dateTime.month().day())
|
||||
}
|
||||
}
|
||||
.frame(height: 200)
|
||||
.padding(.bottom, 8)
|
||||
|
||||
if !motivationalMessage.isEmpty {
|
||||
Text(motivationalMessage)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.primary)
|
||||
.padding()
|
||||
.background(Color.blue.opacity(0.1))
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.onAppear {
|
||||
loadWeightData()
|
||||
}
|
||||
}
|
||||
|
||||
private func loadWeightData() {
|
||||
isLoading = true
|
||||
|
||||
// Create a fetch descriptor to get workout logs for this exercise
|
||||
let descriptor = FetchDescriptor<WorkoutLog>(
|
||||
predicate: #Predicate<WorkoutLog> { log in
|
||||
log.exerciseName == exerciseName && log.completed == true
|
||||
},
|
||||
sortBy: [SortDescriptor(\WorkoutLog.date)]
|
||||
)
|
||||
|
||||
// Fetch the data
|
||||
if let logs = try? modelContext.fetch(descriptor) {
|
||||
// Convert to data points
|
||||
weightData = logs.map { log in
|
||||
WeightDataPoint(date: log.date, weight: log.weight)
|
||||
}
|
||||
|
||||
// Generate motivational message based on progress
|
||||
generateMotivationalMessage()
|
||||
}
|
||||
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
private func generateMotivationalMessage() {
|
||||
guard weightData.count >= 2 else {
|
||||
motivationalMessage = "Complete more workouts to track your progress!"
|
||||
return
|
||||
}
|
||||
|
||||
// Calculate progress metrics
|
||||
let firstWeight = weightData.first?.weight ?? 0
|
||||
let currentWeight = weightData.last?.weight ?? 0
|
||||
let weightDifference = currentWeight - firstWeight
|
||||
|
||||
// Generate appropriate message based on progress
|
||||
if weightDifference > 0 {
|
||||
let percentIncrease = Int((Double(weightDifference) / Double(firstWeight)) * 100)
|
||||
if percentIncrease >= 20 {
|
||||
motivationalMessage = "Amazing progress! You've increased your weight by \(weightDifference) lbs (\(percentIncrease)%)! 💪"
|
||||
} else if percentIncrease >= 10 {
|
||||
motivationalMessage = "Great job! You've increased your weight by \(weightDifference) lbs (\(percentIncrease)%)! 🎉"
|
||||
} else {
|
||||
motivationalMessage = "You're making progress! Weight increased by \(weightDifference) lbs. Keep it up! 👍"
|
||||
}
|
||||
} else if weightDifference == 0 {
|
||||
motivationalMessage = "You're maintaining consistent weight. Focus on form and consider increasing when ready!"
|
||||
} else {
|
||||
motivationalMessage = "Your current weight is lower than when you started. Adjust your training as needed and keep pushing!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Data structure for chart points
|
||||
struct WeightDataPoint: Identifiable {
|
||||
let id = UUID()
|
||||
let date: Date
|
||||
let weight: Int
|
||||
}
|
||||
|
||||
#Preview {
|
||||
WeightProgressionChartView(exerciseName: "Bench Press")
|
||||
.modelContainer(for: [WorkoutLog.self], inMemory: true)
|
||||
}
|
24
Workouts/Views/Settings/SettingsView.swift
Normal file
24
Workouts/Views/Settings/SettingsView.swift
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// SettingsView.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/20/25 at 8:14 AM.
|
||||
//
|
||||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section (header: Text("Options")) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ struct WorkoutListView: View {
|
||||
|
||||
@Query(sort: [SortDescriptor(\Workout.start, order: .reverse)]) var workouts: [Workout]
|
||||
|
||||
@State private var showingSplitPicker = false
|
||||
// @State private var showingSplitPicker = false
|
||||
|
||||
@State private var itemToDelete: Workout? = nil
|
||||
@State private var itemToEdit: Workout? = nil
|
||||
@ -86,61 +86,61 @@ struct WorkoutListView: View {
|
||||
} message: {
|
||||
Text("Are you sure you want to delete this workout?")
|
||||
}
|
||||
.sheet(isPresented: $showingSplitPicker) {
|
||||
SplitPickerView { split in
|
||||
let workout = Workout(start: Date(), end: Date(), split: split)
|
||||
modelContext.insert(workout)
|
||||
if let exercises = split.exercises {
|
||||
for exercise in exercises {
|
||||
let workoutLog = WorkoutLog(
|
||||
workout: workout,
|
||||
exerciseName: exercise.name,
|
||||
date: Date(),
|
||||
order: exercise.order,
|
||||
sets: exercise.sets,
|
||||
reps: exercise.reps,
|
||||
weight: exercise.weight
|
||||
)
|
||||
modelContext.insert(workoutLog)
|
||||
}
|
||||
}
|
||||
try? modelContext.save()
|
||||
}
|
||||
}
|
||||
// .sheet(isPresented: $showingSplitPicker) {
|
||||
// SplitPickerView { split in
|
||||
// let workout = Workout(start: Date(), end: Date(), split: split)
|
||||
// modelContext.insert(workout)
|
||||
// if let exercises = split.exercises {
|
||||
// for exercise in exercises {
|
||||
// let workoutLog = WorkoutLog(
|
||||
// workout: workout,
|
||||
// exerciseName: exercise.name,
|
||||
// date: Date(),
|
||||
// order: exercise.order,
|
||||
// sets: exercise.sets,
|
||||
// reps: exercise.reps,
|
||||
// weight: exercise.weight
|
||||
// )
|
||||
// modelContext.insert(workoutLog)
|
||||
// }
|
||||
// }
|
||||
// try? modelContext.save()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Date {
|
||||
func formattedDate() -> String {
|
||||
let calendar = Calendar.current
|
||||
let now = Date()
|
||||
|
||||
let timeFormatter = DateFormatter()
|
||||
timeFormatter.dateFormat = "h:mm a"
|
||||
|
||||
let dateFormatter = DateFormatter()
|
||||
|
||||
let date = self
|
||||
|
||||
if calendar.isDateInToday(date) {
|
||||
return "Today @ \(timeFormatter.string(from: date))"
|
||||
} else if calendar.isDateInYesterday(date) {
|
||||
return "Yesterday @ \(timeFormatter.string(from: date))"
|
||||
} else {
|
||||
let dateComponents = calendar.dateComponents([.year], from: date)
|
||||
let currentYearComponents = calendar.dateComponents([.year], from: now)
|
||||
|
||||
if dateComponents.year == currentYearComponents.year {
|
||||
dateFormatter.dateFormat = "M/d"
|
||||
} else {
|
||||
dateFormatter.dateFormat = "M/d/yyyy"
|
||||
}
|
||||
|
||||
let dateString = dateFormatter.string(from: date)
|
||||
let timeString = timeFormatter.string(from: date)
|
||||
return "\(dateString) @ \(timeString)"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//extension Date {
|
||||
// func formattedDate() -> String {
|
||||
// let calendar = Calendar.current
|
||||
// let now = Date()
|
||||
//
|
||||
// let timeFormatter = DateFormatter()
|
||||
// timeFormatter.dateFormat = "h:mm a"
|
||||
//
|
||||
// let dateFormatter = DateFormatter()
|
||||
//
|
||||
// let date = self
|
||||
//
|
||||
// if calendar.isDateInToday(date) {
|
||||
// return "Today @ \(timeFormatter.string(from: date))"
|
||||
// } else if calendar.isDateInYesterday(date) {
|
||||
// return "Yesterday @ \(timeFormatter.string(from: date))"
|
||||
// } else {
|
||||
// let dateComponents = calendar.dateComponents([.year], from: date)
|
||||
// let currentYearComponents = calendar.dateComponents([.year], from: now)
|
||||
//
|
||||
// if dateComponents.year == currentYearComponents.year {
|
||||
// dateFormatter.dateFormat = "M/d"
|
||||
// } else {
|
||||
// dateFormatter.dateFormat = "M/d/yyyy"
|
||||
// }
|
||||
//
|
||||
// let dateString = dateFormatter.string(from: date)
|
||||
// let timeString = timeFormatter.string(from: date)
|
||||
// return "\(dateString) @ \(timeString)"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
55
Workouts/_ATTIC_/ContentView_backup.swift
Normal file
55
Workouts/_ATTIC_/ContentView_backup.swift
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/15/25 at 7:09 PM.
|
||||
//
|
||||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
//import SwiftUI
|
||||
//import SwiftData
|
||||
//
|
||||
//struct ContentView: View {
|
||||
// @Environment(\.modelContext) private var modelContext
|
||||
//
|
||||
// let completedStatus = WorkoutStatus.completed
|
||||
//
|
||||
// @Query(filter: #Predicate<Workout> { workout in
|
||||
// workout.status?.rawValue != WorkoutStatus.completed.rawValue
|
||||
// }, sort: \Workout.start, order: .reverse) var activeWorkouts: [Workout]
|
||||
//
|
||||
// var body: some View {
|
||||
// NavigationStack {
|
||||
// if activeWorkouts.isEmpty {
|
||||
// NoActiveWorkoutView()
|
||||
// } else if let currentWorkout = activeWorkouts.first {
|
||||
// WorkoutLogListView(workout: currentWorkout)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//struct NoActiveWorkoutView: View {
|
||||
// var body: some View {
|
||||
// VStack(spacing: 16) {
|
||||
// Image(systemName: "dumbbell.fill")
|
||||
// .font(.system(size: 40))
|
||||
// .foregroundStyle(.gray)
|
||||
//
|
||||
// Text("No Active Workout")
|
||||
// .font(.headline)
|
||||
//
|
||||
// Text("Start a workout in the main app")
|
||||
// .font(.caption)
|
||||
// .foregroundStyle(.gray)
|
||||
// .multilineTextAlignment(.center)
|
||||
// }
|
||||
// .padding()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////#Preview {
|
||||
//// ContentView()
|
||||
//// .modelContainer(AppContainer.preview)
|
||||
////}
|
317
Workouts/_ATTIC_/ExerciseProgressView_backup.swift
Normal file
317
Workouts/_ATTIC_/ExerciseProgressView_backup.swift
Normal file
@ -0,0 +1,317 @@
|
||||
//import SwiftUI
|
||||
//import SwiftData
|
||||
//import WatchKit
|
||||
//
|
||||
//// Enum to track the current phase of the exercise
|
||||
//enum ExercisePhase {
|
||||
// case notStarted
|
||||
// case exercising(setNumber: Int)
|
||||
// case resting(setNumber: Int, elapsedSeconds: Int)
|
||||
// case completed
|
||||
//}
|
||||
//
|
||||
//struct ExerciseProgressView: View {
|
||||
// @Environment(\.modelContext) private var modelContext
|
||||
// @Environment(\.dismiss) private var dismiss
|
||||
//
|
||||
// let log: WorkoutLog
|
||||
//
|
||||
// @State private var phase: ExercisePhase = .notStarted
|
||||
// @State private var currentSetNumber: Int = 0
|
||||
// @State private var restingSeconds: Int = 0
|
||||
// @State private var timer: Timer?
|
||||
// @State private var hapticTimer: Timer?
|
||||
// @State private var hapticSeconds: Int = 0
|
||||
//
|
||||
// var body: some View {
|
||||
// ScrollView {
|
||||
// VStack(spacing: 16) {
|
||||
// Text(log.exerciseName)
|
||||
// .font(.headline)
|
||||
// .multilineTextAlignment(.center)
|
||||
//
|
||||
// switch phase {
|
||||
// case .notStarted:
|
||||
// startView
|
||||
// case .exercising(let setNumber):
|
||||
// exercisingView(setNumber: setNumber)
|
||||
// case .resting(let setNumber, let elapsedSeconds):
|
||||
// restingView(setNumber: setNumber, elapsedSeconds: elapsedSeconds)
|
||||
// case .completed:
|
||||
// completedView
|
||||
// }
|
||||
// }
|
||||
// .padding()
|
||||
// }
|
||||
// .navigationTitle("Progress")
|
||||
// .navigationBarTitleDisplayMode(.inline)
|
||||
// .onDisappear {
|
||||
// stopTimers()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private var startView: some View {
|
||||
// VStack(spacing: 16) {
|
||||
// Text("Ready to start")
|
||||
// .font(.title3)
|
||||
//
|
||||
// Text("\(log.sets) sets × \(log.reps) reps × \(log.weight) lbs")
|
||||
// .font(.subheadline)
|
||||
// .foregroundStyle(.secondary)
|
||||
//
|
||||
// Button(action: startExercise) {
|
||||
// Text("Start First Set")
|
||||
// .font(.headline)
|
||||
// .foregroundStyle(.white)
|
||||
// .frame(maxWidth: .infinity)
|
||||
// .padding(.vertical, 8)
|
||||
// .background(Color.blue)
|
||||
// .cornerRadius(8)
|
||||
// }
|
||||
// .buttonStyle(PlainButtonStyle())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func exercisingView(setNumber: Int) -> some View {
|
||||
// VStack(spacing: 16) {
|
||||
// Text("Set \(setNumber) of \(log.sets)")
|
||||
// .font(.title3)
|
||||
//
|
||||
// Text("\(log.reps) reps × \(log.weight) lbs")
|
||||
// .font(.subheadline)
|
||||
// .foregroundStyle(.secondary)
|
||||
//
|
||||
// Text("In progress: \(hapticSeconds)s")
|
||||
// .font(.body)
|
||||
// .monospacedDigit()
|
||||
//
|
||||
// HStack {
|
||||
// Button(action: completeSet) {
|
||||
// Text("Complete")
|
||||
// .font(.headline)
|
||||
// .foregroundStyle(.white)
|
||||
// .frame(maxWidth: .infinity)
|
||||
// .padding(.vertical, 8)
|
||||
// .background(Color.green)
|
||||
// .cornerRadius(8)
|
||||
// }
|
||||
// .buttonStyle(PlainButtonStyle())
|
||||
//
|
||||
// Button(action: cancelSet) {
|
||||
// Text("Cancel")
|
||||
// .font(.headline)
|
||||
// .foregroundStyle(.white)
|
||||
// .frame(maxWidth: .infinity)
|
||||
// .padding(.vertical, 8)
|
||||
// .background(Color.red)
|
||||
// .cornerRadius(8)
|
||||
// }
|
||||
// .buttonStyle(PlainButtonStyle())
|
||||
// }
|
||||
// }
|
||||
// .gesture(
|
||||
// DragGesture(minimumDistance: 20)
|
||||
// .onEnded { gesture in
|
||||
// if gesture.translation.width < 0 {
|
||||
// // Swipe left to complete
|
||||
// completeSet()
|
||||
// } else if gesture.translation.width > 0 {
|
||||
// // Swipe right to cancel
|
||||
// cancelSet()
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// private func restingView(setNumber: Int, elapsedSeconds: Int) -> some View {
|
||||
// VStack(spacing: 16) {
|
||||
// Text("Rest")
|
||||
// .font(.title3)
|
||||
//
|
||||
// Text("After Set \(setNumber) of \(log.sets)")
|
||||
// .font(.subheadline)
|
||||
// .foregroundStyle(.secondary)
|
||||
//
|
||||
// Text("Resting: \(elapsedSeconds)s")
|
||||
// .font(.body)
|
||||
// .monospacedDigit()
|
||||
//
|
||||
// Button(action: {
|
||||
// if setNumber < log.sets {
|
||||
// startNextSet()
|
||||
// } else {
|
||||
// completeExercise()
|
||||
// }
|
||||
// }) {
|
||||
// Text(setNumber < log.sets ? "Start Next Set" : "Complete Exercise")
|
||||
// .font(.headline)
|
||||
// .foregroundStyle(.white)
|
||||
// .frame(maxWidth: .infinity)
|
||||
// .padding(.vertical, 8)
|
||||
// .background(Color.blue)
|
||||
// .cornerRadius(8)
|
||||
// }
|
||||
// .buttonStyle(PlainButtonStyle())
|
||||
// }
|
||||
// .gesture(
|
||||
// DragGesture(minimumDistance: 20)
|
||||
// .onEnded { gesture in
|
||||
// if gesture.translation.width < 0 {
|
||||
// // Swipe left to start next set or complete
|
||||
// if setNumber < log.sets {
|
||||
// startNextSet()
|
||||
// } else {
|
||||
// completeExercise()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// private var completedView: some View {
|
||||
// VStack(spacing: 16) {
|
||||
// Image(systemName: "checkmark.circle.fill")
|
||||
// .font(.system(size: 50))
|
||||
// .foregroundStyle(.green)
|
||||
//
|
||||
// Text("Exercise Completed!")
|
||||
// .font(.title3)
|
||||
//
|
||||
// Button(action: {
|
||||
// dismiss()
|
||||
// }) {
|
||||
// Text("Return to Workout")
|
||||
// .font(.headline)
|
||||
// .foregroundStyle(.white)
|
||||
// .frame(maxWidth: .infinity)
|
||||
// .padding(.vertical, 8)
|
||||
// .background(Color.blue)
|
||||
// .cornerRadius(8)
|
||||
// }
|
||||
// .buttonStyle(PlainButtonStyle())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // MARK: - Actions
|
||||
//
|
||||
// private func startExercise() {
|
||||
// currentSetNumber = 1
|
||||
// phase = .exercising(setNumber: currentSetNumber)
|
||||
//
|
||||
// // Update workout log status
|
||||
// log.status = .inProgress
|
||||
// try? modelContext.save()
|
||||
//
|
||||
// // Start haptic timer
|
||||
// startHapticTimer()
|
||||
// }
|
||||
//
|
||||
// private func completeSet() {
|
||||
// stopHapticTimer()
|
||||
//
|
||||
// // Start rest phase
|
||||
// restingSeconds = 0
|
||||
// phase = .resting(setNumber: currentSetNumber, elapsedSeconds: restingSeconds)
|
||||
//
|
||||
// // Start rest timer
|
||||
// timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
||||
// restingSeconds += 1
|
||||
// phase = .resting(setNumber: currentSetNumber, elapsedSeconds: restingSeconds)
|
||||
// }
|
||||
//
|
||||
// // Start haptic timer for rest phase
|
||||
// startHapticTimer()
|
||||
//
|
||||
// // Play completion haptic
|
||||
// WKInterfaceDevice.current().play(.success)
|
||||
// }
|
||||
//
|
||||
// private func cancelSet() {
|
||||
// // Just go back to the previous state
|
||||
// if currentSetNumber > 1 {
|
||||
// currentSetNumber -= 1
|
||||
// phase = .resting(setNumber: currentSetNumber, elapsedSeconds: 0)
|
||||
// } else {
|
||||
// phase = .notStarted
|
||||
// }
|
||||
//
|
||||
// stopHapticTimer()
|
||||
// stopTimers()
|
||||
// }
|
||||
//
|
||||
// private func startNextSet() {
|
||||
// stopTimers()
|
||||
//
|
||||
// currentSetNumber += 1
|
||||
// phase = .exercising(setNumber: currentSetNumber)
|
||||
//
|
||||
// // Start haptic timer for next set
|
||||
// startHapticTimer()
|
||||
// }
|
||||
//
|
||||
// private func completeExercise() {
|
||||
// stopTimers()
|
||||
//
|
||||
// // Update workout log
|
||||
// log.completed = true
|
||||
// log.status = .completed
|
||||
// try? modelContext.save()
|
||||
//
|
||||
// // Show completion screen
|
||||
// phase = .completed
|
||||
//
|
||||
// // Play completion haptic
|
||||
// WKInterfaceDevice.current().play(.success)
|
||||
// }
|
||||
//
|
||||
// // MARK: - Timer Management
|
||||
//
|
||||
// private func startHapticTimer() {
|
||||
// hapticSeconds = 0
|
||||
// hapticTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
||||
// hapticSeconds += 1
|
||||
//
|
||||
// // Provide haptic feedback based on time intervals
|
||||
// if hapticSeconds % 60 == 0 {
|
||||
// // Triple tap every 60 seconds
|
||||
// WKInterfaceDevice.current().play(.notification)
|
||||
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||
// WKInterfaceDevice.current().play(.notification)
|
||||
// }
|
||||
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
|
||||
// WKInterfaceDevice.current().play(.notification)
|
||||
// }
|
||||
// } else if hapticSeconds % 30 == 0 {
|
||||
// // Double tap every 30 seconds
|
||||
// WKInterfaceDevice.current().play(.click)
|
||||
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||
// WKInterfaceDevice.current().play(.click)
|
||||
// }
|
||||
// } else if hapticSeconds % 10 == 0 {
|
||||
// // Light tap every 10 seconds
|
||||
// WKInterfaceDevice.current().play(.click)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func stopHapticTimer() {
|
||||
// hapticTimer?.invalidate()
|
||||
// hapticTimer = nil
|
||||
// hapticSeconds = 0
|
||||
// }
|
||||
//
|
||||
// private func stopTimers() {
|
||||
// timer?.invalidate()
|
||||
// timer = nil
|
||||
// stopHapticTimer()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//#Preview {
|
||||
// let container = AppContainer.preview
|
||||
// let workout = Workout(start: Date(), end: Date(), split: nil)
|
||||
// let log = WorkoutLog(workout: workout, exerciseName: "Bench Press", date: Date(), sets: 3, reps: 10, weight: 135)
|
||||
//
|
||||
// return ExerciseProgressView(log: log)
|
||||
// .modelContainer(container)
|
||||
//}
|
Reference in New Issue
Block a user