split files up, fix complete workout screen not showing if remove workout details screen
This commit is contained in:
123
iphone/Werkout_ios/BridgeModule+WorkoutActions.swift
Normal file
123
iphone/Werkout_ios/BridgeModule+WorkoutActions.swift
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// BridgeModule+WorkoutActions.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/21/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import WatchConnectivity
|
||||
|
||||
extension BridgeModule {
|
||||
func pauseWorkout() {
|
||||
if let _ = currentExerciseTimer {
|
||||
currentExerciseTimer?.invalidate()
|
||||
currentExerciseTimer = nil
|
||||
isPaused = true
|
||||
} else {
|
||||
isPaused = false
|
||||
startExerciseTimerWith(duration: currentExerciseTimeLeft)
|
||||
}
|
||||
}
|
||||
|
||||
func nextExercise() {
|
||||
if let nextSupersetExercise = currentExerciseInfo.goToNextExercise {
|
||||
updateCurrent(exercise: nextSupersetExercise)
|
||||
} else {
|
||||
completeWorkout()
|
||||
}
|
||||
}
|
||||
|
||||
func previousExercise() {
|
||||
if let nextSupersetExercise = currentExerciseInfo.previousExercise {
|
||||
updateCurrent(exercise: nextSupersetExercise)
|
||||
} else {
|
||||
completeWorkout()
|
||||
}
|
||||
}
|
||||
|
||||
func restartExercise() {
|
||||
if let currentExercise = currentExerciseInfo.currentExercise {
|
||||
updateCurrent(exercise: currentExercise)
|
||||
}
|
||||
}
|
||||
|
||||
func updateCurrent(exercise: SupersetExercise) {
|
||||
DispatchQueue.main.async {
|
||||
self.currentExerciseTimer?.invalidate()
|
||||
self.currentExerciseTimer = nil
|
||||
|
||||
if let duration = exercise.duration, duration > 0 {
|
||||
self.startExerciseTimerWith(duration: duration)
|
||||
}
|
||||
self.sendCurrentExerciseToWatch()
|
||||
}
|
||||
}
|
||||
|
||||
func completeWorkout() {
|
||||
self.currentExerciseTimer?.invalidate()
|
||||
self.currentExerciseTimer = nil
|
||||
self.isInWorkout = false
|
||||
|
||||
workoutEndDate = Date()
|
||||
if let completedWorkout = completedWorkout {
|
||||
completedWorkout()
|
||||
self.completedWorkout = nil
|
||||
}
|
||||
}
|
||||
|
||||
func start(workout: Workout) {
|
||||
currentExerciseInfo.complete = {
|
||||
self.completeWorkout()
|
||||
}
|
||||
|
||||
currentExerciseInfo.start(workout: workout)
|
||||
currentWorkoutRunTimeInSeconds = 0
|
||||
currentWorkoutRunTimer?.invalidate()
|
||||
currentWorkoutRunTimer = nil
|
||||
isPaused = false
|
||||
|
||||
sendStartWorkoutToWatch()
|
||||
|
||||
if let superetExercise = currentExerciseInfo.currentExercise {
|
||||
updateCurrent(exercise: superetExercise)
|
||||
startWorkoutTimer()
|
||||
workoutStartDate = Date()
|
||||
isInWorkout = true
|
||||
|
||||
if WCSession.isSupported() {
|
||||
session.delegate = self
|
||||
session.activate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func goToExerciseAt(section: Int, row: Int) {
|
||||
if let superetExercise = currentExerciseInfo.goToWorkoutAt(supersetIndex: section,
|
||||
exerciseIndex: row) {
|
||||
updateCurrent(exercise: superetExercise)
|
||||
}
|
||||
}
|
||||
|
||||
var nextExerciseObject: SupersetExercise? {
|
||||
currentExerciseInfo.goToNextExercise
|
||||
}
|
||||
|
||||
func resetCurrentWorkout() {
|
||||
DispatchQueue.main.async {
|
||||
self.currentWorkoutRunTimeInSeconds = 0
|
||||
self.currentWorkoutRunTimer?.invalidate()
|
||||
self.currentWorkoutRunTimer = nil
|
||||
|
||||
self.currentExerciseTimer?.invalidate()
|
||||
self.currentExerciseTimer = nil
|
||||
|
||||
self.currentWorkoutRunTimeInSeconds = -1
|
||||
self.currentExerciseInfo.reset()
|
||||
|
||||
self.isInWorkout = false
|
||||
self.workoutStartDate = nil
|
||||
self.workoutEndDate = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user