init
This commit is contained in:
105
Werkout_ios/Views/ExternalWorkoutDetailView.swift
Normal file
105
Werkout_ios/Views/ExternalWorkoutDetailView.swift
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// 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
|
||||
}() )
|
||||
}
|
||||
}
|
||||
49
Werkout_ios/Views/MainView.swift
Normal file
49
Werkout_ios/Views/MainView.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/13/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
|
||||
struct MainView: View {
|
||||
@State var workout: Workout?
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workout = workout {
|
||||
let vm = WorkoutDetailViewModel(workout: workout)
|
||||
WorkoutDetailView(viewModel: vm)
|
||||
} else {
|
||||
Text("no workout selected")
|
||||
}
|
||||
}.onAppear{
|
||||
testParse()
|
||||
}
|
||||
}
|
||||
|
||||
func testParse() {
|
||||
if let filepath = Bundle.main.path(forResource: "WorkoutOne", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let workout = try JSONDecoder().decode(Workout.self, from: data)
|
||||
bridgeModule.currentWorkout = workout
|
||||
self.workout = workout
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
}
|
||||
}
|
||||
63
Werkout_ios/Views/WorkoutDetailView.swift
Normal file
63
Werkout_ios/Views/WorkoutDetailView.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// MainView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/14/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WorkoutDetailView: View {
|
||||
@ObservedObject var viewModel: WorkoutDetailViewModel
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
|
||||
@State var selectedIdx = -1 {
|
||||
didSet {
|
||||
runItemAt(idx: selectedIdx)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List() {
|
||||
ForEach(viewModel.workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
let obj = viewModel.workout.exercisesSortedByCreated_at[i]
|
||||
Text(obj.exercise.name ?? "")
|
||||
.onTapGesture { selectedIdx = i }
|
||||
}
|
||||
}
|
||||
|
||||
if let duration = bridgeModule.currentExercise?.duration {
|
||||
HStack {
|
||||
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
||||
Text("\(bridgeModule.timeLeft)")
|
||||
}.padding(16)
|
||||
}
|
||||
}
|
||||
.onAppear{
|
||||
bridgeModule.timerCompleted = {
|
||||
selectedIdx += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runItemAt(idx: Int) {
|
||||
if idx < viewModel.workout.exercises.count {
|
||||
let exercise = viewModel.workout.exercises[idx]
|
||||
bridgeModule.updateCurrent(exercise: exercise)
|
||||
bridgeModule.currentExerciseIdx = idx
|
||||
} else {
|
||||
workoutComplete()
|
||||
}
|
||||
}
|
||||
|
||||
private func workoutComplete() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct WorkoutDetailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
WorkoutDetailView(viewModel: WorkoutDetailViewModel(workout: PreviewWorkout.workout()))
|
||||
}
|
||||
}
|
||||
17
Werkout_ios/Views/WorkoutDetailViewModel.swift
Normal file
17
Werkout_ios/Views/WorkoutDetailViewModel.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MainViewViewModel.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/14/23.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
class WorkoutDetailViewModel: ObservableObject {
|
||||
@Published var workout: Workout
|
||||
|
||||
init(workout: Workout) {
|
||||
self.workout = workout
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user