162 lines
5.3 KiB
Swift
162 lines
5.3 KiB
Swift
//
|
|
// MainView.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 6/14/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WorkoutDetailView: View {
|
|
@StateObject var viewModel: WorkoutDetailViewModel
|
|
var bridgeModule = BridgeModule.shared
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
switch viewModel.status {
|
|
case .loading:
|
|
Text("Loading")
|
|
case .showWorkout(let workout):
|
|
VStack {
|
|
TopButtonsView(workout: workout)
|
|
.frame(height: 88)
|
|
|
|
Text(workout.name)
|
|
.font(.title3)
|
|
if let desc = workout.description {
|
|
Text(desc)
|
|
.font(.body)
|
|
}
|
|
CurrentWorkoutElapsedTimeView()
|
|
ExerciseListView(workout: workout)
|
|
CountdownView()
|
|
}
|
|
.interactiveDismissDisabled()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TopButtonsView: View {
|
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
var workout: Workout
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
var body: some View {
|
|
HStack {
|
|
if bridgeModule.currentWorkoutRunTimeInSeconds == -1 {
|
|
Button(action: {
|
|
bridgeModule.completeWorkout()
|
|
dismiss()
|
|
}, label: {
|
|
Image(systemName: "xmark.octagon.fill")
|
|
.font(.title)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
})
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(.red)
|
|
.foregroundColor(.white)
|
|
|
|
Button(action: {
|
|
bridgeModule.start(workout: workout)
|
|
}, label: {
|
|
Image(systemName: "arrowtriangle.forward.fill")
|
|
.font(.title)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
})
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(.green)
|
|
.foregroundColor(.white)
|
|
} else {
|
|
Button(action: {
|
|
bridgeModule.completeWorkout()
|
|
dismiss()
|
|
}, label: {
|
|
Image(systemName: "checkmark")
|
|
.font(.title)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
})
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(.blue)
|
|
.foregroundColor(.white)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CurrentWorkoutElapsedTimeView: View {
|
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
|
|
var body: some View {
|
|
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
|
|
Text("\(bridgeModule.currentWorkoutRunTimeInSeconds)")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ExerciseListView: View {
|
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
var workout: Workout
|
|
|
|
var body: some View {
|
|
List() {
|
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
|
let obj = workout.exercisesSortedByCreated_at[i]
|
|
VStack {
|
|
HStack {
|
|
if i == bridgeModule.currentExerciseIdx {
|
|
Image(systemName: "checkmark")
|
|
.foregroundColor(.green)
|
|
}
|
|
|
|
Text(obj.exercise.name)
|
|
.onTapGesture {
|
|
bridgeModule.start(workout: workout, atExerciseIndex: i)
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
if i == bridgeModule.currentExerciseIdx {
|
|
HStack {
|
|
if obj.exercise.isReps {
|
|
Text("is reps")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
if obj.exercise.isWeight {
|
|
Text("is weight")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
if obj.exercise.isDuration {
|
|
Text("is duration")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CountdownView: View {
|
|
@StateObject var bridgeModule = BridgeModule.shared
|
|
|
|
var body: some View {
|
|
VStack {
|
|
if let duration = bridgeModule.currentExercise?.duration {
|
|
HStack {
|
|
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
|
Text("\(bridgeModule.timeLeft)")
|
|
}.padding(16)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct WorkoutDetailView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
WorkoutDetailView(viewModel: WorkoutDetailViewModel(workout: PreviewWorkout.workout()))
|
|
}
|
|
}
|