Files
workouts/Workouts/_ATTIC_/ExerciseProgressView_backup.swift

318 lines
11 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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