initial pre-viable version of watch app

This commit is contained in:
2025-07-20 19:44:53 -04:00
parent 33b88cb8f0
commit 68d90160c6
35 changed files with 2108 additions and 179 deletions

View File

@ -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

View File

@ -0,0 +1,35 @@
//
// CheckboxStatus.swift
// Workouts
//
// Created by rzen on 7/20/25 at 11:07AM.
//
// 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"
}
}
}

View File

@ -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()
}

View File

@ -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

View 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)
}

View File

@ -0,0 +1,24 @@
//
// SettingsView.swift
// Workouts
//
// Created by rzen on 7/20/25 at 8:14AM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
struct SettingsView: View {
var body: some View {
NavigationStack {
Form {
Section (header: Text("Options")) {
}
}
}
}
}

View File

@ -1,81 +0,0 @@
//
// SplitPickerView.swift
// Workouts
//
// Created by rzen on 7/13/25 at 7:17PM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
import SwiftData
struct SplitPickerView: View {
@Environment(\.modelContext) private var modelContext
@Environment(\.dismiss) private var dismiss
@Query(sort: [SortDescriptor(\Split.name)]) private var splits: [Split]
var onSplitSelected: (Split) -> Void
var body: some View {
NavigationStack {
ScrollView {
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 16) {
ForEach(splits) { split in
Button(action: {
onSplitSelected(split)
dismiss()
}) {
VStack {
ZStack(alignment: .bottom) {
// Golden ratio rectangle (1:1.618)
RoundedRectangle(cornerRadius: 12)
.fill(
LinearGradient(
gradient: Gradient(colors: [split.getColor(), split.getColor().darker(by: 0.2)]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.aspectRatio(1.618, contentMode: .fit)
.shadow(radius: 2)
VStack {
// Icon in the center
Image(systemName: split.systemImage)
.font(.system(size: 40, weight: .medium))
.foregroundColor(.white)
.offset(y: -15)
// Name at the bottom inside the rectangle
Text(split.name)
.font(.headline)
.foregroundColor(.white)
.lineLimit(1)
.padding(.horizontal, 8)
.padding(.bottom, 8)
}
}
// Exercise count below the rectangle
Text("\(split.exercises?.count ?? 0) exercises")
.font(.caption)
.foregroundColor(.secondary)
}
}
.buttonStyle(PlainButtonStyle())
}
}
.padding()
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
dismiss()
}
}
}
}
}
}

View File

@ -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)"
// }
// }
//
//}