From 1a06a1dc957598d16b61f70d9dfe32818cacff52 Mon Sep 17 00:00:00 2001 From: Trey t Date: Tue, 27 Jun 2023 23:47:55 -0500 Subject: [PATCH] WIP --- Werkout_ios.xcodeproj/project.pbxproj | 24 +++++++-- Werkout_ios/Network/Fetchables.swift | 18 +++---- Werkout_ios/Network/Network.swift | 2 +- .../Views/AddExercise/AddExerciseView.swift | 18 +++++-- .../Views/AllWorkouts/AllWorkoutsView.swift | 8 ++- .../Views/ExternalWorkoutDetailView.swift | 26 ++-------- Werkout_ios/Views/VideoPlayerView.swift | 50 +++++++++++++++++++ Werkout_ios/Werkout_iosApp.swift | 2 +- 8 files changed, 105 insertions(+), 43 deletions(-) create mode 100644 Werkout_ios/Views/VideoPlayerView.swift diff --git a/Werkout_ios.xcodeproj/project.pbxproj b/Werkout_ios.xcodeproj/project.pbxproj index 0d614da..9c8cf84 100644 --- a/Werkout_ios.xcodeproj/project.pbxproj +++ b/Werkout_ios.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 1C485C8A2A492BB400A6F896 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C485C892A492BB400A6F896 /* LoginView.swift */; }; 1C485C8C2A49D65600A6F896 /* WorkoutHistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C485C8B2A49D65600A6F896 /* WorkoutHistoryView.swift */; }; 1C485C8D2A49D95700A6F896 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A822A42347D0042FFBD /* Extensions.swift */; }; + 1C6D0A372A4BE9A500D98B06 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6D0A362A4BE9A500D98B06 /* VideoPlayerView.swift */; }; 1CF65A262A3972840042FFBD /* Werkout_iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A252A3972840042FFBD /* Werkout_iosApp.swift */; }; 1CF65A282A3972840042FFBD /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A272A3972840042FFBD /* Persistence.swift */; }; 1CF65A2B2A3972840042FFBD /* Werkout_ios.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A292A3972840042FFBD /* Werkout_ios.xcdatamodeld */; }; @@ -102,6 +103,10 @@ 1C485C862A4915C400A6F896 /* CreateWorkoutItemPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateWorkoutItemPickerView.swift; sourceTree = ""; }; 1C485C892A492BB400A6F896 /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; 1C485C8B2A49D65600A6F896 /* WorkoutHistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkoutHistoryView.swift; sourceTree = ""; }; + 1C6D0A362A4BE9A500D98B06 /* VideoPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayerView.swift; sourceTree = ""; }; + 1C6D0A3C2A4BEC9700D98B06 /* AVKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVKit.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.4.sdk/System/Library/Frameworks/AVKit.framework; sourceTree = DEVELOPER_DIR; }; + 1C6D0A3D2A4BEC9700D98B06 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.4.sdk/System/Library/Frameworks/AVFoundation.framework; sourceTree = DEVELOPER_DIR; }; + 1C6D0A402A4BECA400D98B06 /* AVKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/System/Library/Frameworks/AVKit.framework; sourceTree = DEVELOPER_DIR; }; 1CF65A222A3972840042FFBD /* Werkout_ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Werkout_ios.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1CF65A252A3972840042FFBD /* Werkout_iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Werkout_iosApp.swift; sourceTree = ""; }; 1CF65A272A3972840042FFBD /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; @@ -180,12 +185,23 @@ path = Login; sourceTree = ""; }; + 1C6D0A3B2A4BEC9600D98B06 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1C6D0A402A4BECA400D98B06 /* AVKit.framework */, + 1C6D0A3D2A4BEC9700D98B06 /* AVFoundation.framework */, + 1C6D0A3C2A4BEC9700D98B06 /* AVKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; 1CF65A192A3972840042FFBD = { isa = PBXGroup; children = ( 1CF65A242A3972840042FFBD /* Werkout_ios */, 1CF65A942A452D270042FFBD /* Werkout_watch Watch App */, 1CF65A232A3972840042FFBD /* Products */, + 1C6D0A3B2A4BEC9600D98B06 /* Frameworks */, ); sourceTree = ""; }; @@ -257,16 +273,17 @@ 1CF65A3F2A3973840042FFBD /* Views */ = { isa = PBXGroup; children = ( - 1C485C882A492BAA00A6F896 /* Login */, - 1CF65A2C2A3972840042FFBD /* MainView.swift */, 1CF65A3B2A3972CE0042FFBD /* ExternalWorkoutDetailView.swift */, + 1CF65A2C2A3972840042FFBD /* MainView.swift */, + 1C6D0A362A4BE9A500D98B06 /* VideoPlayerView.swift */, + 1C485C8B2A49D65600A6F896 /* WorkoutHistoryView.swift */, 1CF65A8B2A44B7590042FFBD /* AccountView */, 1CF65A8A2A44B74D0042FFBD /* AddExercise */, 1CF65A892A44B7390042FFBD /* AllWorkouts */, 1CF65A8C2A44B7680042FFBD /* CompletedWorkout */, 1CF65A6C2A3F60100042FFBD /* CreateWorkout */, + 1C485C882A492BAA00A6F896 /* Login */, 1CF65A882A44B7290042FFBD /* WorkoutDetail */, - 1C485C8B2A49D65600A6F896 /* WorkoutHistoryView.swift */, ); path = Views; sourceTree = ""; @@ -490,6 +507,7 @@ 1CF65A522A3A90A00042FFBD /* PreviewData.swift in Sources */, 1CF65A852A43E8060042FFBD /* CompletedWorkout.swift in Sources */, 1CF65A6E2A3F60480042FFBD /* CreateViewModels.swift in Sources */, + 1C6D0A372A4BE9A500D98B06 /* VideoPlayerView.swift in Sources */, 1CF65A4C2A39FDA20042FFBD /* WorkoutDetailView.swift in Sources */, 1CF65A8E2A44B78B0042FFBD /* CompletedWorkoutView.swift in Sources */, 1CF65A432A39FB410042FFBD /* Workout.swift in Sources */, diff --git a/Werkout_ios/Network/Fetchables.swift b/Werkout_ios/Network/Fetchables.swift index 315738f..a0c991b 100644 --- a/Werkout_ios/Network/Fetchables.swift +++ b/Werkout_ios/Network/Fetchables.swift @@ -9,7 +9,7 @@ import Foundation class AllWorkoutFetchable: Fetchable { typealias Response = [Workout] - var endPoint: String = "workout/all/" + var endPoint: String = "/workout/all/" } class WorkoutDetailFetchable: Fetchable { @@ -17,28 +17,28 @@ class WorkoutDetailFetchable: Fetchable { var endPoint: String init(workoutID: Int) { - self.endPoint = "workout/"+String(workoutID)+"/details/" + self.endPoint = "/workout/"+String(workoutID)+"/details/" } } class AllMusclesFetchable: Fetchable { typealias Response = [Muscle] - var endPoint: String = "muscle/all/" + var endPoint: String = "/muscle/all/" } class AllEquipmentFetchable: Fetchable { typealias Response = [Equipment] - var endPoint: String = "equipment/all/" + var endPoint: String = "/equipment/all/" } class AllExerciseFetchable: Fetchable { typealias Response = [ExerciseExercise] - var endPoint: String = "exercise/all/" + var endPoint: String = "/exercise/all/" } class CompletedWorkoutFetchable: Fetchable { typealias Response = [CompletedWorkout] - var endPoint: String = "workout/completed/" + var endPoint: String = "/workout/completed/" } class CreateWorkoutFetchable: Postable { @@ -46,7 +46,7 @@ class CreateWorkoutFetchable: Postable { var successStatus = 201 typealias Response = Workout - var endPoint: String = "workout/create/" + var endPoint: String = "/workout/create/" init(postData: [String: Any]) { self.postableData = postData @@ -58,7 +58,7 @@ class CompleteWorkoutFetchable: Postable { var successStatus = 201 typealias Response = CompletedWorkout - var endPoint: String = "workout/complete/" + var endPoint: String = "/workout/complete/" init(postData: [String: Any]) { self.postableData = postData @@ -70,7 +70,7 @@ class LoginFetchable: Postable { var successStatus = 200 typealias Response = RegisteredUser - var endPoint: String = "registered_user/login/" + var endPoint: String = "/registered_user/login/" var attachToken: Bool { return false diff --git a/Werkout_ios/Network/Network.swift b/Werkout_ios/Network/Network.swift index f0f8ae2..1a35b07 100644 --- a/Werkout_ios/Network/Network.swift +++ b/Werkout_ios/Network/Network.swift @@ -37,7 +37,7 @@ protocol Postable: Fetchable { extension Fetchable { var baseURL: String { - BaseURLs.local.rawValue + BaseURLs.dev.rawValue } var attachToken: Bool { diff --git a/Werkout_ios/Views/AddExercise/AddExerciseView.swift b/Werkout_ios/Views/AddExercise/AddExerciseView.swift index 2788305..fbc7637 100644 --- a/Werkout_ios/Views/AddExercise/AddExerciseView.swift +++ b/Werkout_ios/Views/AddExercise/AddExerciseView.swift @@ -61,7 +61,9 @@ struct AddExerciseView: View { filteredExercises = exercises } .sheet(item: $videoExercise) { exercise in - VideoPlayerView(currentExercise: exercise) + if let url = URL(string: BaseURLs.dev.rawValue + exercise.videoURL) { + VideoPlayerView(url: url) + } } .sheet(item: $createWorkoutItemPickerViewModel) { item in CreateWorkoutItemPickerView(viewModel: item, completed: { selectedids in @@ -223,12 +225,20 @@ struct AddExerciseView: View { Button(action: { videoExercise = exercise }) { - Image(systemName: "video.fill") + ZStack { + Circle() + .fill(.blue) + .frame(width: 44, height: 44) + Image(systemName: "video.fill") + .frame(width: 44, height: 44) + .foregroundColor(.white) + } } - .frame(width: 22, height: 22) + .frame(width: 44, height: 44) .background(.clear) - .foregroundColor(.blue) + .cornerRadius(10) + } } } diff --git a/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift b/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift index 6d2952f..61f68c8 100644 --- a/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift +++ b/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift @@ -27,7 +27,10 @@ struct AllWorkoutsView: View { var body: some View { ZStack { - if let workouts = workouts { + if let workouts = workouts, + let _ = DataStore.shared.allExercise, + let _ = DataStore.shared.allMuscles, + let _ = DataStore.shared.allEquipment { List { ForEach(workouts, id:\.name) { workout in VStack { @@ -44,7 +47,8 @@ struct AllWorkoutsView: View { } } } else { - Text("no workouts") + ProgressView() + .progressViewStyle(.circular) } }.onAppear{ maybeUpdateShit() diff --git a/Werkout_ios/Views/ExternalWorkoutDetailView.swift b/Werkout_ios/Views/ExternalWorkoutDetailView.swift index 49c5358..56df9b2 100644 --- a/Werkout_ios/Views/ExternalWorkoutDetailView.swift +++ b/Werkout_ios/Views/ExternalWorkoutDetailView.swift @@ -17,8 +17,9 @@ struct ExternalWorkoutDetailView: View { GeometryReader { metrics in VStack { HStack { - if let currentExercise = bridgeModule.currentExercise { - VideoPlayerView(currentExercise: currentExercise.exercise) + if let currentExercise = bridgeModule.currentExercise, + let url = URL(string: BaseURLs.dev.rawValue + currentExercise.exercise.videoURL) { + VideoPlayerView(url: url) .frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8) } @@ -123,27 +124,6 @@ struct ExtCountdownView: View { } } -struct VideoPlayerView: View { - var currentExercise: ExerciseExercise - @State var player = AVPlayer() - - var body: some View { - VideoPlayer(player: player) - .onAppear{ - let url = URL(string: BaseURLs.dev.rawValue + currentExercise.videoURL)! - player = AVPlayer(url: url) - } - .onAppear{ - player.play() - - NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: .main) { _ in - player.seek(to: .zero) - player.play() - } - } - } -} - struct ExternalWorkoutDetailView_Previews: PreviewProvider { static var bridge = BridgeModule.shared diff --git a/Werkout_ios/Views/VideoPlayerView.swift b/Werkout_ios/Views/VideoPlayerView.swift new file mode 100644 index 0000000..6bafe5d --- /dev/null +++ b/Werkout_ios/Views/VideoPlayerView.swift @@ -0,0 +1,50 @@ +// +// VideoPlayerView.swift +// Werkout_ios +// +// Created by Trey Tartt on 6/27/23. +// + +import SwiftUI +import AVKit +import SafariServices + +struct VideoPlayerView: View { + let url: URL + @State var player: AVPlayer? + @Environment(\.dismiss) var dismiss + + var body: some View { + VStack { + Button(action: { + dismiss() + }, label: { + Text("Done") + }) + .padding() + + SafariWebView(url: url) + } + } +} + +struct SafariWebView: UIViewControllerRepresentable { + let url: URL + + func makeUIViewController(context: Context) -> SFSafariViewController { + return SFSafariViewController(url: url) + } + + func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) { + + } +} + + +struct VideoPlayerView_Previews: PreviewProvider { + static let exercise = PreviewData.parseExercises().first! + + static var previews: some View { + VideoPlayerView(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!) + } +} diff --git a/Werkout_ios/Werkout_iosApp.swift b/Werkout_ios/Werkout_iosApp.swift index 46688d2..53693ae 100644 --- a/Werkout_ios/Werkout_iosApp.swift +++ b/Werkout_ios/Werkout_iosApp.swift @@ -62,7 +62,7 @@ struct Werkout_iosApp: App { .tag(3) } .onAppear{ - +// UserStore.shared.logout() } .onReceive(pub) { (output) in self.tabSelection = 1