WIP
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="launch_icon" translatesAutoresizingMaskIntoConstraints="NO" id="TO7-SX-zZe">
|
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon" translatesAutoresizingMaskIntoConstraints="NO" id="TO7-SX-zZe">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||||
</imageView>
|
</imageView>
|
||||||
</subviews>
|
</subviews>
|
||||||
@@ -44,6 +44,6 @@
|
|||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
<resources>
|
<resources>
|
||||||
<image name="launch_icon" width="341.33334350585938" height="341.33334350585938"/>
|
<image name="icon" width="246" height="246"/>
|
||||||
</resources>
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
|
|||||||
@@ -25,52 +25,6 @@ struct ExerciseElement: Codable, Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ExerciseElement {
|
|
||||||
func videoURL(thotStyle: ThotStyle) -> URL? {
|
|
||||||
var urlString: String?
|
|
||||||
|
|
||||||
switch thotStyle {
|
|
||||||
case .always:
|
|
||||||
urlString = exercise.nsfwVideoURL
|
|
||||||
case .never:
|
|
||||||
urlString = exercise.videoURL
|
|
||||||
case .recovery:
|
|
||||||
if self.exercise.name.lowercased() == "recover" {
|
|
||||||
urlString = exercise.nsfwVideoURL
|
|
||||||
} else {
|
|
||||||
urlString = exercise.videoURL
|
|
||||||
}
|
|
||||||
case .random:
|
|
||||||
if Bool.random() {
|
|
||||||
urlString = exercise.nsfwVideoURL
|
|
||||||
} else {
|
|
||||||
urlString = exercise.videoURL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let urlString = urlString,
|
|
||||||
let url = URL(string: BaseURLs.currentBaseURL + urlString) {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func returnOtherVideoURL(currentURL: URL) -> URL? {
|
|
||||||
var urlString: String?
|
|
||||||
if currentURL.absoluteString.lowercased().contains(exercise.nsfwVideoURL.lowercased()) {
|
|
||||||
urlString = exercise.videoURL
|
|
||||||
} else {
|
|
||||||
urlString = exercise.nsfwVideoURL
|
|
||||||
}
|
|
||||||
|
|
||||||
if let urlString = urlString,
|
|
||||||
let url = URL(string: BaseURLs.currentBaseURL + urlString) {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExerciseExercise: Codable, Hashable, Identifiable {
|
struct ExerciseExercise: Codable, Hashable, Identifiable {
|
||||||
static func == (lhs: ExerciseExercise, rhs: ExerciseExercise) -> Bool {
|
static func == (lhs: ExerciseExercise, rhs: ExerciseExercise) -> Bool {
|
||||||
lhs.id == rhs.id
|
lhs.id == rhs.id
|
||||||
@@ -79,7 +33,7 @@ struct ExerciseExercise: Codable, Hashable, Identifiable {
|
|||||||
let id: Int
|
let id: Int
|
||||||
let muscles: [ExerciseMuscle]
|
let muscles: [ExerciseMuscle]
|
||||||
let equipment: [ExerciseEquipment]
|
let equipment: [ExerciseEquipment]
|
||||||
let audioURL, videoURL, createdAt, updatedAt, nsfwVideoURL: String
|
let audioURL, videoURL, createdAt, updatedAt: String
|
||||||
let name, description, side: String
|
let name, description, side: String
|
||||||
let isTwoDumbbells, isTrackableDistance, isAlternating, isWeight: Bool
|
let isTwoDumbbells, isTrackableDistance, isAlternating, isWeight: Bool
|
||||||
let isDistance, isDuration, isReps: Bool
|
let isDistance, isDuration, isReps: Bool
|
||||||
@@ -105,52 +59,5 @@ struct ExerciseExercise: Codable, Hashable, Identifiable {
|
|||||||
case equipmentRequired = "equipment_required"
|
case equipmentRequired = "equipment_required"
|
||||||
case muscleGroups = "muscle_groups"
|
case muscleGroups = "muscle_groups"
|
||||||
case synonyms
|
case synonyms
|
||||||
case nsfwVideoURL = "nsfw_video_url"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension ExerciseExercise {
|
|
||||||
func videoURL(thotStyle: ThotStyle) -> URL? {
|
|
||||||
var urlString: String?
|
|
||||||
|
|
||||||
switch thotStyle {
|
|
||||||
case .always:
|
|
||||||
urlString = nsfwVideoURL
|
|
||||||
case .never:
|
|
||||||
urlString = videoURL
|
|
||||||
case .recovery:
|
|
||||||
if self.name.lowercased() == "recovery" {
|
|
||||||
urlString = nsfwVideoURL
|
|
||||||
} else {
|
|
||||||
urlString = videoURL
|
|
||||||
}
|
|
||||||
case .random:
|
|
||||||
if Bool.random() {
|
|
||||||
urlString = nsfwVideoURL
|
|
||||||
} else {
|
|
||||||
urlString = videoURL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let urlString = urlString,
|
|
||||||
let url = URL(string: BaseURLs.currentBaseURL + urlString) {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func returnOtherVideoURL(currentURL: URL) -> URL? {
|
|
||||||
var urlString: String?
|
|
||||||
if currentURL.absoluteString.lowercased().contains(nsfwVideoURL.lowercased()) {
|
|
||||||
urlString = videoURL
|
|
||||||
} else {
|
|
||||||
urlString = nsfwVideoURL
|
|
||||||
}
|
|
||||||
|
|
||||||
if let urlString = urlString,
|
|
||||||
let url = URL(string: BaseURLs.currentBaseURL + urlString) {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,16 @@ struct Workout: Codable, Identifiable, Equatable {
|
|||||||
let muscles: [String]?
|
let muscles: [String]?
|
||||||
let equipment: [String]?
|
let equipment: [String]?
|
||||||
let exercise_count: Int?
|
let exercise_count: Int?
|
||||||
|
let maleVideos: [String]?
|
||||||
|
let femaleVideos: [String]?
|
||||||
|
let bothVideos: [String]?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case name, description, exercises, id, muscles, equipment, exercise_count
|
case name, description, exercises, id, muscles, equipment, exercise_count
|
||||||
case registeredUser = "registered_user"
|
case registeredUser = "registered_user"
|
||||||
|
case maleVideos = "male_videos"
|
||||||
|
case femaleVideos = "female_videos"
|
||||||
|
case bothVideos = "both_videos"
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
@@ -41,6 +47,9 @@ struct Workout: Codable, Identifiable, Equatable {
|
|||||||
self.muscles = try container.decodeIfPresent([String].self, forKey: .muscles)
|
self.muscles = try container.decodeIfPresent([String].self, forKey: .muscles)
|
||||||
self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment)
|
self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment)
|
||||||
self.exercise_count = try container.decodeIfPresent(Int.self, forKey: .exercise_count)
|
self.exercise_count = try container.decodeIfPresent(Int.self, forKey: .exercise_count)
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
var exercisesSortedByCreated_at: [ExerciseElement] {
|
var exercisesSortedByCreated_at: [ExerciseElement] {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -67,6 +67,7 @@ struct CreateWorkoutItemPickerView: View {
|
|||||||
TextField("Filter", text: $searchString)
|
TextField("Filter", text: $searchString)
|
||||||
.padding()
|
.padding()
|
||||||
|
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
viewModel.toggleAll()
|
viewModel.toggleAll()
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||||
if let videoURL = newValue?.videoURL(thotStyle: thotStyle) {
|
if let videoURL = VideoURLCreator.videoURL(
|
||||||
|
thotStyle: thotStyle,
|
||||||
|
defaultVideoURLStr: bridgeModule.currentExercise?.exercise.videoURL,
|
||||||
|
exerciseName: bridgeModule.currentExercise?.exercise.name,
|
||||||
|
workout: bridgeModule.currentWorkout) {
|
||||||
avPlayer = AVPlayer(url: videoURL)
|
avPlayer = AVPlayer(url: videoURL)
|
||||||
avPlayer.play()
|
avPlayer.play()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,3 +80,34 @@ struct PlayerView: UIViewRepresentable {
|
|||||||
uiView.setObserver()
|
uiView.setObserver()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VideoURLCreator {
|
||||||
|
class func videoURL(thotStyle: ThotStyle, defaultVideoURLStr: String?, exerciseName: String?, workout: Workout?) -> URL? {
|
||||||
|
var urlString: String?
|
||||||
|
|
||||||
|
switch thotStyle {
|
||||||
|
case .always:
|
||||||
|
urlString = workout?.femaleVideos?.randomElement()
|
||||||
|
case .never:
|
||||||
|
urlString = defaultVideoURLStr
|
||||||
|
case .recovery:
|
||||||
|
if exerciseName?.lowercased() == "recover" {
|
||||||
|
urlString = workout?.femaleVideos?.randomElement()
|
||||||
|
} else {
|
||||||
|
urlString = defaultVideoURLStr
|
||||||
|
}
|
||||||
|
case .random:
|
||||||
|
if Bool.random() {
|
||||||
|
urlString = workout?.femaleVideos?.randomElement()
|
||||||
|
} else {
|
||||||
|
urlString = defaultVideoURLStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let urlString = urlString,
|
||||||
|
let url = URL(string: BaseURLs.currentBaseURL + "/media/" + urlString) {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,11 @@ struct ExerciseListView: View {
|
|||||||
|
|
||||||
@State var videoExercise: ExerciseExercise? {
|
@State var videoExercise: ExerciseExercise? {
|
||||||
didSet {
|
didSet {
|
||||||
if let videoURL = self.videoExercise?.videoURL(thotStyle: thotStyle) {
|
if let videoURL = VideoURLCreator.videoURL(
|
||||||
|
thotStyle: thotStyle,
|
||||||
|
defaultVideoURLStr: self.videoExercise?.videoURL,
|
||||||
|
exerciseName: self.videoExercise?.name,
|
||||||
|
workout: bridgeModule.currentWorkout) {
|
||||||
avPlayer = AVPlayer(url: videoURL)
|
avPlayer = AVPlayer(url: videoURL)
|
||||||
avPlayer.play()
|
avPlayer.play()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,14 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button(action: {
|
Button(action: {
|
||||||
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url,
|
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url {
|
||||||
let videoURL = bridgeModule.currentExercise?.returnOtherVideoURL(currentURL: assetURL) {
|
if assetURL.absoluteString.lowercased().contains("exercise_videos") {
|
||||||
avPlayer = AVPlayer(url: videoURL)
|
|
||||||
avPlayer.play()
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
// avPlayer = AVPlayer(url: videoURL)
|
||||||
|
// avPlayer.play()
|
||||||
}
|
}
|
||||||
}, label: {
|
}, label: {
|
||||||
Text("Toggle THOT")
|
Text("Toggle THOT")
|
||||||
@@ -98,16 +102,25 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||||
if let videoURL = newValue?.videoURL(thotStyle: thotStyle) {
|
if let videoURL = VideoURLCreator.videoURL(
|
||||||
|
thotStyle: thotStyle,
|
||||||
|
defaultVideoURLStr: newValue?.exercise.videoURL,
|
||||||
|
exerciseName: newValue?.exercise.name,
|
||||||
|
workout: bridgeModule.currentWorkout) {
|
||||||
avPlayer = AVPlayer(url: videoURL)
|
avPlayer = AVPlayer(url: videoURL)
|
||||||
avPlayer.play()
|
avPlayer.play()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.onAppear{
|
.onAppear{
|
||||||
if let videoURL = bridgeModule.currentExercise?.videoURL(thotStyle: thotStyle) {
|
if let videoURL = VideoURLCreator.videoURL(
|
||||||
|
thotStyle: thotStyle,
|
||||||
|
defaultVideoURLStr: bridgeModule.currentExercise?.exercise.videoURL,
|
||||||
|
exerciseName: bridgeModule.currentExercise?.exercise.name,
|
||||||
|
workout: bridgeModule.currentWorkout) {
|
||||||
avPlayer = AVPlayer(url: videoURL)
|
avPlayer = AVPlayer(url: videoURL)
|
||||||
avPlayer.play()
|
avPlayer.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
bridgeModule.completedWorkout = {
|
bridgeModule.completedWorkout = {
|
||||||
if let workoutData = createWorkoutData() {
|
if let workoutData = createWorkoutData() {
|
||||||
presentedSheet = .completedWorkout(workoutData)
|
presentedSheet = .completedWorkout(workoutData)
|
||||||
|
|||||||
Reference in New Issue
Block a user