106 lines
4.6 KiB
Swift
106 lines
4.6 KiB
Swift
//
|
|
// ExternalView.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 6/13/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AVKit
|
|
|
|
struct ExternalWorkoutDetailView: View {
|
|
@EnvironmentObject var bridgeModule: BridgeModule
|
|
@State var player = AVPlayer()
|
|
|
|
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 {
|
|
VideoPlayer(player: player)
|
|
.onChange(of: bridgeModule.currentExerciseIdx, perform: { newValue in
|
|
updateVideo()
|
|
})
|
|
|
|
if let workout = bridgeModule.currentWorkout {
|
|
List() {
|
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
|
let obj = workout.exercisesSortedByCreated_at[i]
|
|
HStack {
|
|
if let _ = bridgeModule.currentExercise {
|
|
if i == bridgeModule.currentExerciseIdx {
|
|
Image(systemName: "checkmark")
|
|
.font(Font.system(size: 75))
|
|
.foregroundColor(.green)
|
|
}
|
|
}
|
|
|
|
Text(obj.exercise.name ?? "")
|
|
.font(Font.system(size: 75))
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
.frame(width: metrics.size.width * 0.4)
|
|
}
|
|
}
|
|
.frame(width: metrics.size.width, height: metrics.size.height * 0.7)
|
|
|
|
HStack {
|
|
if let currenExercise = bridgeModule.currentExercise {
|
|
VStack {
|
|
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)")
|
|
}
|
|
}
|
|
.padding([.leading, .trailing], 50)
|
|
}
|
|
}
|
|
}
|
|
.frame(width: metrics.size.width, height: metrics.size.height * 0.2)
|
|
.padding([.leading, .trailing])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func updateVideo() {
|
|
if let videoURL = bridgeModule.currentExercise?.exercise.videoURL {
|
|
// let completeURL = "http://127.0.0.1:8000" + videoURL
|
|
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
|
player.play()
|
|
// print(completeURL)
|
|
// player = AVPlayer(url: URL(string: completeURL)!)
|
|
// 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
|
|
}() )
|
|
}
|
|
}
|