This commit is contained in:
Trey t
2023-07-07 14:22:49 -05:00
parent 1f1e8cecdd
commit 76e8111777
10 changed files with 432 additions and 347 deletions

View File

@@ -0,0 +1,101 @@
//
// ActionsView.swift
// Werkout_ios
//
// Created by Trey Tartt on 7/7/23.
//
import SwiftUI
struct ActionsView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var completedWorkout: (() -> Void)?
var planWorkout: ((Workout) -> Void)?
var workout: Workout
@Environment(\.dismiss) var dismiss
var showAddToCalendar: Bool
var body: some View {
HStack {
if bridgeModule.isInWorkout == false {
Button(action: {
bridgeModule.resetCurrentWorkout()
dismiss()
}, label: {
Image(systemName: "xmark.octagon.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.red)
.foregroundColor(.white)
if showAddToCalendar {
Button(action: {
planWorkout?(workout)
}, label: {
Image(systemName: "calendar.badge.plus")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.blue)
.foregroundColor(.white)
}
Button(action: {
startWorkout()
}, label: {
Image(systemName: "arrowtriangle.forward.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green)
.foregroundColor(.white)
} else {
Button(action: {
nextExercise()
}, label: {
Image(systemName: "arrow.forward")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green)
.foregroundColor(.white)
Button(action: {
bridgeModule.pauseWorkout()
}, label: {
Image(systemName: "pause.circle.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.yellow)
.foregroundColor(.white)
Button(action: {
completedWorkout?()
}, label: {
Image(systemName: "checkmark")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.blue)
.foregroundColor(.white)
}
}
}
func nextExercise() {
bridgeModule.nextExercise()
}
func startWorkout() {
bridgeModule.start(workout: workout)
}
}

View File

@@ -0,0 +1,25 @@
//
// CountdownView.swift
// Werkout_ios
//
// Created by Trey Tartt on 7/7/23.
//
import SwiftUI
struct CountdownView: View {
@StateObject var bridgeModule = BridgeModule.shared
var body: some View {
if let duration = bridgeModule.currentExercise?.duration,
duration > 0 {
HStack {
if bridgeModule.currentExerciseTimeLeft >= 0 && duration > bridgeModule.currentExerciseTimeLeft {
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
Text("\(bridgeModule.currentExerciseTimeLeft)")
.font(.body)
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
//
// CurrentWorkoutElapsedTimeView.swift
// Werkout_ios
//
// Created by Trey Tartt on 7/7/23.
//
import SwiftUI
struct CurrentWorkoutElapsedTimeView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var body: some View {
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
Text("\(Double(bridgeModule.currentWorkoutRunTimeInSeconds).asString(style: .positional))")
.font(.title2)
}
}
}

View File

@@ -0,0 +1,104 @@
//
// 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()
}
}
}
}

View File

@@ -0,0 +1,30 @@
//
// InfoView.swift
// Werkout_ios
//
// Created by Trey Tartt on 7/7/23.
//
import SwiftUI
struct InfoView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var workout: Workout
var body: some View {
VStack {
if bridgeModule.isInWorkout == false {
Text(workout.name)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.title3)
.padding()
if let desc = workout.description {
Text(desc)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.body)
.padding([.leading, .trailing])
}
}
}
}
}

View File

@@ -150,244 +150,6 @@ struct WorkoutDetailView: View {
}
}
struct InfoView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var workout: Workout
var body: some View {
VStack {
if bridgeModule.isInWorkout == false {
Text(workout.name)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.title3)
.padding()
if let desc = workout.description {
Text(desc)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.body)
.padding([.leading, .trailing])
}
}
}
}
}
struct ActionsView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var completedWorkout: (() -> Void)?
var planWorkout: ((Workout) -> Void)?
var workout: Workout
@Environment(\.dismiss) var dismiss
var showAddToCalendar: Bool
var body: some View {
HStack {
if bridgeModule.isInWorkout == false {
Button(action: {
bridgeModule.resetCurrentWorkout()
dismiss()
}, label: {
Image(systemName: "xmark.octagon.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.red)
.foregroundColor(.white)
if showAddToCalendar {
Button(action: {
planWorkout?(workout)
}, label: {
Image(systemName: "calendar.badge.plus")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.blue)
.foregroundColor(.white)
}
Button(action: {
startWorkout()
}, label: {
Image(systemName: "arrowtriangle.forward.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green)
.foregroundColor(.white)
} else {
Button(action: {
nextExercise()
}, label: {
Image(systemName: "arrow.forward")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green)
.foregroundColor(.white)
Button(action: {
bridgeModule.pauseWorkout()
}, label: {
Image(systemName: "pause.circle.fill")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.yellow)
.foregroundColor(.white)
Button(action: {
completedWorkout?()
}, label: {
Image(systemName: "checkmark")
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.blue)
.foregroundColor(.white)
}
}
}
func nextExercise() {
bridgeModule.nextExercise()
}
func startWorkout() {
bridgeModule.start(workout: workout)
}
}
struct CurrentWorkoutElapsedTimeView: View {
@ObservedObject var bridgeModule = BridgeModule.shared
var body: some View {
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
Text("\(Double(bridgeModule.currentWorkoutRunTimeInSeconds).asString(style: .positional))")
.font(.title2)
}
}
}
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()
}
}
}
}
struct CountdownView: View {
@StateObject var bridgeModule = BridgeModule.shared
var body: some View {
if let duration = bridgeModule.currentExercise?.duration,
duration > 0 {
HStack {
if bridgeModule.currentExerciseTimeLeft >= 0 && duration > bridgeModule.currentExerciseTimeLeft {
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
Text("\(bridgeModule.currentExerciseTimeLeft)")
.font(.body)
}
}
}
}
}
struct WorkoutDetailView_Previews: PreviewProvider {
static let workoutDetail = PreviewData.workout()
static var previews: some View {