WIP
This commit is contained in:
@@ -6,11 +6,15 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AVKit
|
||||
|
||||
struct WorkoutDetailView: View {
|
||||
@StateObject var viewModel: WorkoutDetailViewModel
|
||||
var bridgeModule = BridgeModule.shared
|
||||
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
|
||||
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@AppStorage("showNSFWVideos") private var showNSFWVideos = false
|
||||
|
||||
enum Sheet: Identifiable {
|
||||
case completedWorkout([String: Any])
|
||||
@@ -28,11 +32,21 @@ struct WorkoutDetailView: View {
|
||||
Text("Loading")
|
||||
case .showWorkout(let workout):
|
||||
VStack {
|
||||
if bridgeModule.isInWorkout {
|
||||
HStack {
|
||||
CurrentWorkoutElapsedTimeView()
|
||||
CountdownView()
|
||||
}
|
||||
.padding()
|
||||
|
||||
GeometryReader { metrics in
|
||||
WorkoutDetailVideoPlayerView(avPlayer: $avPlayer)
|
||||
.frame(width: metrics.size.width * 1, height: metrics.size.height * 1)
|
||||
}
|
||||
}
|
||||
InfoView(workout: workout)
|
||||
Divider()
|
||||
CurrentWorkoutElapsedTimeView()
|
||||
.padding(.top)
|
||||
CountdownView()
|
||||
.padding([.leading, .trailing])
|
||||
ExerciseListView(workout: workout)
|
||||
ActionsView(completedWorkout: {
|
||||
bridgeModule.completeWorkout()
|
||||
@@ -60,6 +74,19 @@ struct WorkoutDetailView: View {
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||
if showNSFWVideos {
|
||||
if let viddd = newValue?.exercise.nsfwVideoURL,
|
||||
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
||||
avPlayer = AVPlayer(url: url)
|
||||
}
|
||||
} else {
|
||||
if let viddd = newValue?.exercise.videoURL,
|
||||
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
||||
avPlayer = AVPlayer(url: url)
|
||||
}
|
||||
}
|
||||
})
|
||||
.onAppear{
|
||||
bridgeModule.completedWorkout = {
|
||||
if let workoutData = createWorkoutData() {
|
||||
@@ -68,6 +95,7 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func createWorkoutData() -> [String:Any]? {
|
||||
@@ -90,6 +118,15 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct WorkoutDetailVideoPlayerView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
@Binding var avPlayer: AVPlayer
|
||||
|
||||
var body: some View {
|
||||
VideoPlayerView(avPlayer: $avPlayer, showDoneButton: false)
|
||||
}
|
||||
}
|
||||
|
||||
struct InfoView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
var workout: Workout
|
||||
@@ -209,43 +246,44 @@ struct ExerciseListView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
var workout: Workout
|
||||
|
||||
|
||||
var body: some View {
|
||||
List() {
|
||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
let obj = workout.exercisesSortedByCreated_at[i]
|
||||
VStack {
|
||||
HStack {
|
||||
if i == bridgeModule.currentExerciseIdx {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.green)
|
||||
}
|
||||
|
||||
Text(obj.exercise.name)
|
||||
.onTapGesture {
|
||||
bridgeModule.goToExerciseAt(index: i)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
if i == bridgeModule.currentExerciseIdx {
|
||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
let obj = workout.exercisesSortedByCreated_at[i]
|
||||
VStack {
|
||||
HStack {
|
||||
if obj.exercise.isReps {
|
||||
Text("is reps")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
if i == bridgeModule.currentExerciseIdx {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.green)
|
||||
}
|
||||
if obj.exercise.isWeight {
|
||||
Text("is weight")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
if obj.exercise.isDuration {
|
||||
Text("is duration")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
|
||||
Text(obj.exercise.name)
|
||||
.onTapGesture {
|
||||
bridgeModule.goToExerciseAt(index: i)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
if i == bridgeModule.currentExerciseIdx {
|
||||
HStack {
|
||||
if obj.exercise.isReps {
|
||||
Text("is reps")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
if obj.exercise.isWeight {
|
||||
Text("is weight")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
if obj.exercise.isDuration {
|
||||
Text("is duration")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,12 +291,11 @@ struct CountdownView: View {
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let duration = bridgeModule.currentExercise?.duration {
|
||||
HStack {
|
||||
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
||||
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
||||
}.padding(16)
|
||||
if let duration = bridgeModule.currentExercise?.duration {
|
||||
HStack {
|
||||
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
||||
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
||||
.font(.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user