diff --git a/Werkout_ios/APIModels/Exercise.swift b/Werkout_ios/APIModels/Exercise.swift index 459e2e7..aab61e5 100644 --- a/Werkout_ios/APIModels/Exercise.swift +++ b/Werkout_ios/APIModels/Exercise.swift @@ -7,7 +7,7 @@ import Foundation -struct ExerciseElement: Codable { +struct ExerciseElement: Codable, Equatable { let workout: Int let exercise: ExerciseExercise let weight: Int? diff --git a/Werkout_ios/APIModels/Workout.swift b/Werkout_ios/APIModels/Workout.swift index 0459e2b..a1c59e2 100644 --- a/Werkout_ios/APIModels/Workout.swift +++ b/Werkout_ios/APIModels/Workout.swift @@ -7,7 +7,11 @@ import Foundation -struct Workout: Codable, Identifiable { +struct Workout: Codable, Identifiable, Equatable { + static func == (lhs: Workout, rhs: Workout) -> Bool { + lhs.id == rhs.id + } + let id: Int let name: String let description: String? diff --git a/Werkout_ios/Views/AddExercise/AddExerciseView.swift b/Werkout_ios/Views/AddExercise/AddExerciseView.swift index e8788c2..ff43cfd 100644 --- a/Werkout_ios/Views/AddExercise/AddExerciseView.swift +++ b/Werkout_ios/Views/AddExercise/AddExerciseView.swift @@ -34,7 +34,8 @@ struct AddExerciseView: View { TextField("Filter", text: $searchString) .padding() - + .background(Color(uiColor: .systemBackground)) + HStack { muscleView() .frame(maxWidth: .infinity) @@ -47,6 +48,7 @@ struct AddExerciseView: View { .padding(.top) .frame(height: 44) } + .background(Color(uiColor: UIColor.secondarySystemBackground)) .onAppear{ if #function.hasPrefix("__preview") { DataStore.shared.setupFakeData() diff --git a/Werkout_ios/Views/ExternalWorkoutDetailView.swift b/Werkout_ios/Views/ExternalWorkoutDetailView.swift index 56df9b2..a62f2c3 100644 --- a/Werkout_ios/Views/ExternalWorkoutDetailView.swift +++ b/Werkout_ios/Views/ExternalWorkoutDetailView.swift @@ -10,22 +10,22 @@ import AVKit struct ExternalWorkoutDetailView: View { @StateObject var bridgeModule = BridgeModule.shared - + let videoPlayer = VideoPlayerView(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/Isometric_Bear_Crawl_with_Shoulder_Taps.mp4")!) var body: some View { ZStack { if let workout = bridgeModule.currentWorkout { GeometryReader { metrics in VStack { HStack { - if let currentExercise = bridgeModule.currentExercise, - let url = URL(string: BaseURLs.dev.rawValue + currentExercise.exercise.videoURL) { - VideoPlayerView(url: url) + if let currentExercise = bridgeModule.currentExercise { + videoPlayer .frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8) } ExtExerciseList(workout: workout, currentExerciseIdx: bridgeModule.currentExerciseIdx) .frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.8) + } ExtCountdownView() @@ -38,6 +38,12 @@ struct ExternalWorkoutDetailView: View { Text("nothing here bro") } } + .onChange(of: bridgeModule.currentExercise, perform: { newValue in + if let newValue = newValue, + let _videoURL = URL(string: BaseURLs.dev.rawValue + newValue.exercise.videoURL) { + videoPlayer.updateVideoURL(url: _videoURL) + } + }) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.background) } diff --git a/Werkout_ios/Views/VideoPlayerView.swift b/Werkout_ios/Views/VideoPlayerView.swift index 240d0fd..8e74f36 100644 --- a/Werkout_ios/Views/VideoPlayerView.swift +++ b/Werkout_ios/Views/VideoPlayerView.swift @@ -10,8 +10,7 @@ import AVKit import SafariServices struct VideoPlayerView: View { - let url: URL - @State var player: AVPlayer? + @State var url: URL @Environment(\.dismiss) var dismiss var body: some View { @@ -25,14 +24,18 @@ struct VideoPlayerView: View { .frame(maxWidth: .infinity) .background(Color(uiColor: UIColor(red: 0.11, green: 0.11, blue: 0.12, alpha: 1))) - SafariWebView(url: url) + SafariWebView(url: $url) } .background(.black) } + + func updateVideoURL(url: URL) { + self.url = url + } } struct SafariWebView: UIViewControllerRepresentable { - let url: URL + @Binding var url: URL func makeUIViewController(context: Context) -> SFSafariViewController { return SFSafariViewController(url: url)