From 173f39cc5f1f6eb17f45c6bd9a6706b2490a1277 Mon Sep 17 00:00:00 2001 From: Trey t Date: Sat, 29 Jul 2023 12:03:40 -0500 Subject: [PATCH] WIP --- Werkout_ios.xcodeproj/project.pbxproj | 4 ++++ Werkout_ios/APIModels/NSFWVideo.swift | 17 +++++++++++++++++ Werkout_ios/APIModels/Workout.swift | 7 ------- Werkout_ios/BaseURLs.swift | 2 +- Werkout_ios/DataStore.swift | 20 +++++++++++++++++++- Werkout_ios/Network/Fetchables.swift | 5 +++++ Werkout_ios/Views/PlayerUIView.swift | 6 +++--- 7 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 Werkout_ios/APIModels/NSFWVideo.swift diff --git a/Werkout_ios.xcodeproj/project.pbxproj b/Werkout_ios.xcodeproj/project.pbxproj index fae7c1a..024bde7 100644 --- a/Werkout_ios.xcodeproj/project.pbxproj +++ b/Werkout_ios.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 1C4AFF192A65CD6F0027710B /* Superset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4AFF172A65CD290027710B /* Superset.swift */; }; 1C4AFF1B2A65FB190027710B /* CurrentWorkoutInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4AFF1A2A65FB190027710B /* CurrentWorkoutInfo.swift */; }; 1C4AFF1C2A65FB2B0027710B /* CurrentWorkoutInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4AFF1A2A65FB190027710B /* CurrentWorkoutInfo.swift */; }; + 1C4AFF1E2A7579410027710B /* NSFWVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4AFF1D2A7579410027710B /* NSFWVideo.swift */; }; 1C5190C22A57CA5F00885849 /* OvalTextFieldStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5190C12A57CA5F00885849 /* OvalTextFieldStyle.swift */; }; 1C5190C42A589CAC00885849 /* InfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5190C32A589CAC00885849 /* InfoView.swift */; }; 1C5190C62A589CC100885849 /* ActionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5190C52A589CC100885849 /* ActionsView.swift */; }; @@ -135,6 +136,7 @@ 1C4AFF142A60F25E0027710B /* ThotStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThotStyle.swift; sourceTree = ""; }; 1C4AFF172A65CD290027710B /* Superset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Superset.swift; sourceTree = ""; }; 1C4AFF1A2A65FB190027710B /* CurrentWorkoutInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentWorkoutInfo.swift; sourceTree = ""; }; + 1C4AFF1D2A7579410027710B /* NSFWVideo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSFWVideo.swift; sourceTree = ""; }; 1C5190C12A57CA5F00885849 /* OvalTextFieldStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OvalTextFieldStyle.swift; sourceTree = ""; }; 1C5190C32A589CAC00885849 /* InfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoView.swift; sourceTree = ""; }; 1C5190C52A589CC100885849 /* ActionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionsView.swift; sourceTree = ""; }; @@ -322,6 +324,7 @@ 1CF65A462A39FB6C0042FFBD /* RegisteredUser.swift */, 1CF65A422A39FB410042FFBD /* Workout.swift */, 1C4AFF172A65CD290027710B /* Superset.swift */, + 1C4AFF1D2A7579410027710B /* NSFWVideo.swift */, ); path = APIModels; sourceTree = ""; @@ -596,6 +599,7 @@ 1CF65A432A39FB410042FFBD /* Workout.swift in Sources */, 1CF65A502A3A1EA90042FFBD /* BridgeModule.swift in Sources */, 1CF65A592A3BF4B60042FFBD /* Muscle.swift in Sources */, + 1C4AFF1E2A7579410027710B /* NSFWVideo.swift in Sources */, 1C5190D02A589D5F00885849 /* AllWorkoutsListView.swift in Sources */, 1C5190CA2A589CEC00885849 /* ExerciseListView.swift in Sources */, 1CAF4D8A2A5132F900B00E50 /* PlannedWorkout.swift in Sources */, diff --git a/Werkout_ios/APIModels/NSFWVideo.swift b/Werkout_ios/APIModels/NSFWVideo.swift new file mode 100644 index 0000000..9d647c9 --- /dev/null +++ b/Werkout_ios/APIModels/NSFWVideo.swift @@ -0,0 +1,17 @@ +// +// NSFWVideo.swift +// Werkout_ios +// +// Created by Trey Tartt on 7/29/23. +// + +import Foundation + +struct NSFWVideo: Codable { + let videoFile, genderValue: String + + enum CodingKeys: String, CodingKey { + case videoFile = "video_file" + case genderValue = "gender_value" + } +} diff --git a/Werkout_ios/APIModels/Workout.swift b/Werkout_ios/APIModels/Workout.swift index 7621521..54894e2 100644 --- a/Werkout_ios/APIModels/Workout.swift +++ b/Werkout_ios/APIModels/Workout.swift @@ -17,7 +17,6 @@ struct Workout: Codable, Identifiable, Equatable { let description: String? let supersets: [Superset]? let registeredUser: RegisteredUser? - let femaleVideos, maleVideos, bothVideos: [String]? let muscles: [String]? let equipment: [String]? let exercise_count: Int? @@ -28,9 +27,6 @@ struct Workout: Codable, Identifiable, Equatable { enum CodingKeys: String, CodingKey { case id, name, description, supersets, exercise_count, muscles, equipment case registeredUser = "registered_user" - case maleVideos = "male_videos" - case femaleVideos = "female_videos" - case bothVideos = "both_videos" case createdAt = "created_at" case estimatedTime = "estimated_time" case allSupersetExecercise = "all_superset_exercise" @@ -43,9 +39,6 @@ struct Workout: Codable, Identifiable, Equatable { self.description = try container.decodeIfPresent(String.self, forKey: .description) self.registeredUser = try container.decodeIfPresent(RegisteredUser.self, forKey: .registeredUser) self.id = try container.decode(Int.self, forKey: .id) - self.femaleVideos = try container.decodeIfPresent([String].self, forKey: .femaleVideos) - self.maleVideos = try container.decodeIfPresent([String].self, forKey: .maleVideos) - self.bothVideos = try container.decodeIfPresent([String].self, forKey: .bothVideos) self.supersets = try container.decodeIfPresent([Superset].self, forKey: .supersets) self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment) diff --git a/Werkout_ios/BaseURLs.swift b/Werkout_ios/BaseURLs.swift index 537f209..c43c8e6 100644 --- a/Werkout_ios/BaseURLs.swift +++ b/Werkout_ios/BaseURLs.swift @@ -12,6 +12,6 @@ enum BaseURLs: String { case dev = "https://dev.werkout.fitness" static var currentBaseURL: String { - return BaseURLs.local.rawValue + return BaseURLs.dev.rawValue } } diff --git a/Werkout_ios/DataStore.swift b/Werkout_ios/DataStore.swift index 07e5979..8064aae 100644 --- a/Werkout_ios/DataStore.swift +++ b/Werkout_ios/DataStore.swift @@ -20,11 +20,18 @@ class DataStore: ObservableObject { public private(set) var allMuscles: [Muscle]? public private(set) var allEquipment: [Equipment]? public private(set) var allExercise: [Exercise]? + public private(set) var allNSFWVideos: [NSFWVideo]? @Published public private(set) var status = DataStoreStatus.idle private let fetchAllDataQueue = DispatchGroup() + public func randomVideoFor(gender: String) -> String? { + return allNSFWVideos?.filter({ + $0.genderValue == gender + }).randomElement()?.videoFile ?? nil + } + public var workoutsUniqueUsers: [RegisteredUser]? { guard let workouts = allWorkouts else { return nil @@ -41,6 +48,7 @@ class DataStore: ObservableObject { fetchAllDataQueue.enter() fetchAllDataQueue.enter() fetchAllDataQueue.enter() + fetchAllDataQueue.enter() fetchAllDataQueue.notify(queue: .main) { self.status = .idle @@ -73,7 +81,7 @@ class DataStore: ObservableObject { switch result { case .success(let model): self.allEquipment = model.sorted(by: { - $0.name ?? "a" < $1.name ?? "a" + $0.name < $1.name }) case .failure(let error): print(error) @@ -92,6 +100,16 @@ class DataStore: ObservableObject { } self.fetchAllDataQueue.leave() }) + + AllNSFWVideosFetchable().fetch(completion: { result in + switch result { + case .success(let model): + self.allNSFWVideos = model + case .failure(let error): + print(error) + } + self.fetchAllDataQueue.leave() + }) } diff --git a/Werkout_ios/Network/Fetchables.swift b/Werkout_ios/Network/Fetchables.swift index 93249a7..3733d37 100644 --- a/Werkout_ios/Network/Fetchables.swift +++ b/Werkout_ios/Network/Fetchables.swift @@ -97,3 +97,8 @@ class PlanWorkoutFetchable: Postable { self.postableData = postData } } + +class AllNSFWVideosFetchable: Fetchable { + typealias Response = [NSFWVideo] + var endPoint: String = "/videos/nsfw_videos/" +} diff --git a/Werkout_ios/Views/PlayerUIView.swift b/Werkout_ios/Views/PlayerUIView.swift index b00f58e..fe453ab 100644 --- a/Werkout_ios/Views/PlayerUIView.swift +++ b/Werkout_ios/Views/PlayerUIView.swift @@ -95,18 +95,18 @@ class VideoURLCreator { switch thotStyle { case .always: - urlString = workout?.femaleVideos?.randomElement() + urlString = DataStore.shared.randomVideoFor(gender: "female") case .never: urlString = defaultVideoURLStr case .recovery: if exerciseName?.lowercased() == "recover" { - urlString = workout?.femaleVideos?.randomElement() + urlString = DataStore.shared.randomVideoFor(gender: "female") } else { urlString = defaultVideoURLStr } case .random: if Bool.random() { - urlString = workout?.femaleVideos?.randomElement() + urlString = DataStore.shared.randomVideoFor(gender: "female") } else { urlString = defaultVideoURLStr }