105 lines
4.0 KiB
Swift
105 lines
4.0 KiB
Swift
//
|
|
// ExerciseListView.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 7/7/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AVKit
|
|
|
|
struct ExerciseListView: View {
|
|
@AppStorage("showNSFWVideos") private var showNSFWVideos = false
|
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
var workout: Workout
|
|
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
|
|
@State var videoExercise: ExerciseExercise? {
|
|
didSet {
|
|
if showNSFWVideos {
|
|
if let viddd = self.videoExercise?.nsfwVideoURL,
|
|
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
|
avPlayer = AVPlayer(url: url)
|
|
}
|
|
} else {
|
|
if let viddd = self.videoExercise?.videoURL,
|
|
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
|
avPlayer = AVPlayer(url: url)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
ScrollViewReader { proxy in
|
|
List() {
|
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
|
let obj = workout.exercisesSortedByCreated_at[i]
|
|
HStack {
|
|
if i == bridgeModule.currentExerciseIdx {
|
|
Image(systemName: "checkmark")
|
|
.foregroundColor(.green)
|
|
}
|
|
|
|
Text(obj.exercise.name)
|
|
.id(i)
|
|
|
|
Spacer()
|
|
|
|
if let reps = obj.reps,
|
|
reps > 0 {
|
|
HStack {
|
|
Image(systemName: "number")
|
|
.foregroundColor(.white)
|
|
.frame(width: 20, alignment: .leading)
|
|
Text("\(reps)")
|
|
.foregroundColor(.white)
|
|
.frame(width: 30, alignment: .trailing)
|
|
|
|
}
|
|
.padding(5)
|
|
.background(.blue)
|
|
.cornerRadius(5, corners: [.topLeft, .bottomLeft])
|
|
.frame(alignment: .trailing)
|
|
}
|
|
|
|
if let duration = obj.duration,
|
|
duration > 0 {
|
|
HStack {
|
|
Image(systemName: "stopwatch")
|
|
.foregroundColor(.white)
|
|
.frame(width: 20, alignment: .leading)
|
|
Text("\(duration)")
|
|
.foregroundColor(.white)
|
|
.frame(width: 30, alignment: .trailing)
|
|
}
|
|
.padding(5)
|
|
.background(.green)
|
|
.cornerRadius(5, corners: [.topLeft, .bottomLeft])
|
|
}
|
|
}
|
|
.padding(.trailing, -20)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
if bridgeModule.isInWorkout {
|
|
bridgeModule.goToExerciseAt(index: i)
|
|
} else {
|
|
videoExercise = obj.exercise
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.onChange(of: bridgeModule.currentExerciseIdx, perform: { newValue in
|
|
withAnimation {
|
|
proxy.scrollTo(newValue, anchor: .top)
|
|
}
|
|
})
|
|
}
|
|
.sheet(item: $videoExercise) { exercise in
|
|
PlayerView(player: $avPlayer)
|
|
.onAppear{
|
|
avPlayer.play()
|
|
}
|
|
}
|
|
}
|
|
}
|