117 lines
3.9 KiB
Swift
117 lines
3.9 KiB
Swift
//
|
|
// ExternalView.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 6/13/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AVKit
|
|
|
|
struct ExternalWorkoutDetailView: View {
|
|
@StateObject var bridgeModule = BridgeModule.shared
|
|
|
|
var body: some View {
|
|
if let workout = bridgeModule.currentWorkout {
|
|
GeometryReader { metrics in
|
|
VStack {
|
|
Text(workout.name)
|
|
.font(Font.system(size: 100))
|
|
.frame(width: metrics.size.width, height: metrics.size.height * 0.1)
|
|
|
|
HStack {
|
|
if let currentExercise = bridgeModule.currentExercise {
|
|
VideoPlayerView(currentExercise: currentExercise.exercise)
|
|
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.7)
|
|
}
|
|
|
|
ExtExerciseList(workout: workout,
|
|
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
|
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.7)
|
|
}
|
|
|
|
ExtCountdownView()
|
|
.frame(width: metrics.size.width-50, height: metrics.size.height * 0.2)
|
|
.padding([.leading, .trailing], 50)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ExtExerciseList: View {
|
|
var workout: Workout
|
|
var currentExerciseIdx: Int
|
|
|
|
var body: some View {
|
|
List() {
|
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
|
let obj = workout.exercisesSortedByCreated_at[i]
|
|
HStack {
|
|
if i == currentExerciseIdx {
|
|
Image(systemName: "checkmark")
|
|
.font(Font.system(size: 75))
|
|
.foregroundColor(.green)
|
|
}
|
|
|
|
Text(obj.exercise.name)
|
|
.font(Font.system(size: 75))
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ExtCountdownView: View {
|
|
@StateObject var bridgeModule = BridgeModule.shared
|
|
|
|
var body: some View {
|
|
VStack {
|
|
if let currenExercise = bridgeModule.currentExercise {
|
|
Text(currenExercise.exercise.name)
|
|
.font(Font.system(size: 100))
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
HStack {
|
|
if let duration = currenExercise.duration {
|
|
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
|
.scaleEffect(x: 1, y: 6, anchor: .center)
|
|
Text("\(bridgeModule.timeLeft)")
|
|
.font(Font.system(size: 75))
|
|
.padding(.leading)
|
|
} else if let reps = currenExercise.reps {
|
|
Text("\(reps)")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct VideoPlayerView: View {
|
|
var currentExercise: ExerciseExercise
|
|
@State var player = AVPlayer()
|
|
|
|
var body: some View {
|
|
VideoPlayer(player: player)
|
|
.onAppear{
|
|
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
|
player.play()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ExternalWorkoutDetailView_Previews: PreviewProvider {
|
|
static var bridge = BridgeModule.shared
|
|
|
|
static var previews: some View {
|
|
ExternalWorkoutDetailView().environmentObject({ () -> BridgeModule in
|
|
let envObj = BridgeModule.shared
|
|
envObj.currentWorkout = PreviewWorkout.workout()
|
|
bridge.currentExercise = PreviewWorkout.workout().exercisesSortedByCreated_at.first!
|
|
return envObj
|
|
}() )
|
|
}
|
|
}
|