This commit is contained in:
Trey t
2023-07-14 15:29:24 -05:00
parent d57afc1527
commit 593cc496cd
9 changed files with 150 additions and 2991 deletions

View File

@@ -67,6 +67,7 @@ struct CreateWorkoutItemPickerView: View {
TextField("Filter", text: $searchString)
.padding()
HStack {
Button(action: {
viewModel.toggleAll()

View File

@@ -54,7 +54,11 @@ struct ExternalWorkoutDetailView: View {
}
}
.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.play()
}

View File

@@ -80,3 +80,34 @@ struct PlayerView: UIViewRepresentable {
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
}
}

View File

@@ -16,7 +16,11 @@ struct ExerciseListView: View {
@State var videoExercise: ExerciseExercise? {
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.play()
}

View File

@@ -49,10 +49,14 @@ struct WorkoutDetailView: View {
}
Button(action: {
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url,
let videoURL = bridgeModule.currentExercise?.returnOtherVideoURL(currentURL: assetURL) {
avPlayer = AVPlayer(url: videoURL)
avPlayer.play()
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url {
if assetURL.absoluteString.lowercased().contains("exercise_videos") {
} else {
}
// avPlayer = AVPlayer(url: videoURL)
// avPlayer.play()
}
}, label: {
Text("Toggle THOT")
@@ -98,16 +102,25 @@ struct WorkoutDetailView: View {
}
}
.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.play()
}
})
.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.play()
}
bridgeModule.completedWorkout = {
if let workoutData = createWorkoutData() {
presentedSheet = .completedWorkout(workoutData)