fix naming on variable
fix tapping on exercise not updating external correctly
This commit is contained in:
Trey t
2024-08-28 08:55:41 -05:00
parent bfb373c8af
commit 2d5d55c272
14 changed files with 51 additions and 55 deletions

View File

@@ -36,7 +36,7 @@ extension BridgeModule {
if currentExerciseTimeLeft > 1 {
currentExerciseTimeLeft -= 1
if let currentExercise = currentExerciseInfo.allSupersetExecercise, let audioQueues = currentExercise.audioQueues {
if let currentExercise = currentWorkoutInfo.allSupersetExecercise, let audioQueues = currentExercise.audioQueues {
if let audioQueue = audioQueues.first(where: {
$0.playAt == currentExerciseTimeLeft
}) {

View File

@@ -33,7 +33,7 @@ extension BridgeModule: WCSessionDelegate {
}
func sendCurrentExerciseToWatch() {
if let currentExercise = currentExerciseInfo.currentExercise,
if let currentExercise = currentWorkoutInfo.currentExercise,
let duration = currentExercise.duration ,
duration > 0 {
let watchModel = WatchPackageModel(currentExerciseName: currentExercise.exercise.name,
@@ -44,7 +44,7 @@ extension BridgeModule: WCSessionDelegate {
let data = try! JSONEncoder().encode(model)
send(data)
} else {
if let currentExercise = currentExerciseInfo.currentExercise,
if let currentExercise = currentWorkoutInfo.currentExercise,
let reps = currentExercise.reps,
reps > 0 {

View File

@@ -21,7 +21,7 @@ extension BridgeModule {
}
func nextExercise() {
if let nextSupersetExercise = currentExerciseInfo.goToNextExercise {
if let nextSupersetExercise = currentWorkoutInfo.goToNextExercise {
updateCurrent(exercise: nextSupersetExercise)
} else {
completeWorkout()
@@ -29,7 +29,7 @@ extension BridgeModule {
}
func previousExercise() {
if let nextSupersetExercise = currentExerciseInfo.previousExercise {
if let nextSupersetExercise = currentWorkoutInfo.previousExercise {
updateCurrent(exercise: nextSupersetExercise)
} else {
completeWorkout()
@@ -37,7 +37,7 @@ extension BridgeModule {
}
func restartExercise() {
if let currentExercise = currentExerciseInfo.currentExercise {
if let currentExercise = currentWorkoutInfo.currentExercise {
updateCurrent(exercise: currentExercise)
}
}
@@ -67,17 +67,17 @@ extension BridgeModule {
}
func start(workout: Workout) {
currentExerciseInfo.complete = {
currentWorkoutInfo.complete = {
self.completeWorkout()
}
currentExerciseInfo.start(workout: workout)
currentWorkoutInfo.start(workout: workout)
currentWorkoutRunTimeInSeconds = 0
currentWorkoutRunTimer?.invalidate()
currentWorkoutRunTimer = nil
isPaused = false
if let superetExercise = currentExerciseInfo.currentExercise {
if let superetExercise = currentWorkoutInfo.currentExercise {
updateCurrent(exercise: superetExercise)
startWorkoutTimer()
workoutStartDate = Date()
@@ -91,15 +91,8 @@ extension BridgeModule {
}
}
func goToExerciseAt(section: Int, row: Int) {
if let superetExercise = currentExerciseInfo.goToWorkoutAt(supersetIndex: section,
exerciseIndex: row) {
updateCurrent(exercise: superetExercise)
}
}
var nextExerciseObject: SupersetExercise? {
currentExerciseInfo.goToNextExercise
currentWorkoutInfo.goToNextExercise
}
func resetCurrentWorkout() {
@@ -115,7 +108,7 @@ extension BridgeModule {
self.currentExerciseTimer = nil
self.currentWorkoutRunTimeInSeconds = -1
self.currentExerciseInfo.reset()
self.currentWorkoutInfo.reset()
self.isInWorkout = false
self.workoutStartDate = nil

View File

@@ -41,7 +41,7 @@ class BridgeModule: NSObject, ObservableObject {
public var currentExerciseTimer: Timer?
@Published public private(set) var currentExerciseInfo = CurrentWorkoutInfo()
@Published public private(set) var currentWorkoutInfo = CurrentWorkoutInfo()
@Published var previewWorkout: Workout?
@Published var currentExerciseTimeLeft: Int = 0

View File

@@ -140,7 +140,8 @@ class CurrentWorkoutInfo {
self.workout = nil
}
func goToWorkoutAt(supersetIndex: Int, exerciseIndex: Int) -> SupersetExercise? {
@discardableResult
func goToExerciseAt(supersetIndex: Int, exerciseIndex: Int) -> SupersetExercise? {
self.supersetIndex = supersetIndex
self.exerciseIndex = exerciseIndex
self.currentRound = 1

View File

@@ -39,7 +39,6 @@ class HealthKitHelper {
limit: HKObjectQueryNoLimit,
sortDescriptors: nil)
{ (sampleQuery, results, error ) -> Void in
if let queryError = error {
self.shitReturned()
self.shitReturned()

View File

@@ -37,13 +37,13 @@ struct AllWorkoutsView: View {
@State private var showWorkoutDetail = false
@State private var selectedWorkout: Workout? {
didSet {
bridgeModule.currentExerciseInfo.workout = selectedWorkout
bridgeModule.currentWorkoutInfo.workout = selectedWorkout
}
}
@State private var selectedPlannedWorkout: Workout? {
didSet {
bridgeModule.currentExerciseInfo.workout = selectedPlannedWorkout
bridgeModule.currentWorkoutInfo.workout = selectedPlannedWorkout
}
}
@@ -60,7 +60,7 @@ struct AllWorkoutsView: View {
AllWorkoutPickerView(mainViews: MainViewTypes.allCases,
selectedSegment: $selectedSegment,
showCurrentWorkout: {
selectedWorkout = bridgeModule.currentExerciseInfo.workout
selectedWorkout = bridgeModule.currentWorkoutInfo.workout
})
@@ -94,7 +94,7 @@ struct AllWorkoutsView: View {
maybeUpdateShit()
}
.sheet(item: $selectedWorkout) { item in
let isPreview = item.id == bridgeModule.currentExerciseInfo.workout?.id
let isPreview = item.id == bridgeModule.currentWorkoutInfo.workout?.id
let viewModel = WorkoutDetailViewModel(workout: item, isPreview: isPreview)
WorkoutDetailView(viewModel: viewModel)
}

View File

@@ -18,7 +18,7 @@ struct ExternalWorkoutDetailView: View {
var body: some View {
ZStack {
if let workout = bridgeModule.currentExerciseInfo.workout {
if let workout = bridgeModule.currentWorkoutInfo.workout {
GeometryReader { metrics in
VStack {
HStack {
@@ -32,7 +32,7 @@ struct ExternalWorkoutDetailView: View {
VStack {
ExtExerciseList(workout: workout,
allSupersetExecerciseIndex: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex)
allSupersetExecerciseIndex: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex)
}
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.8)
.padding([.top, .bottom], 20)
@@ -93,11 +93,11 @@ struct ExternalWorkoutDetailView: View {
.onChange(of: bridgeModule.isInWorkout, perform: { _ in
playVideos()
})
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { _ in
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { _ in
playVideos()
})
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(bridgeModule.currentExerciseInfo.workout == nil ? Color(red: 157/255, green: 138/255, blue: 255/255) : Color(uiColor: .systemBackground))
.background(bridgeModule.currentWorkoutInfo.workout == nil ? Color(red: 157/255, green: 138/255, blue: 255/255) : Color(uiColor: .systemBackground))
.onReceive(NotificationCenter.default.publisher(
for: UIScene.willEnterForegroundNotification)) { _ in
avPlayer.play()
@@ -106,13 +106,13 @@ struct ExternalWorkoutDetailView: View {
}
func playVideos() {
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL(
thotStyle: extThotStyle,
gender: thotGenderOption,
defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) {
workout: bridgeModule.currentWorkoutInfo.workout) {
avPlayer = AVPlayer(url: videoURL)
avPlayer.play()
}
@@ -120,9 +120,9 @@ struct ExternalWorkoutDetailView: View {
if let smallVideoURL = VideoURLCreator.videoURL(
thotStyle: .never,
gender: thotGenderOption,
defaultVideoURLStr: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.videoURL,
exerciseName: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout),
defaultVideoURLStr: BridgeModule.shared.currentWorkoutInfo.nextExerciseInfo?.exercise.videoURL,
exerciseName: BridgeModule.shared.currentWorkoutInfo.nextExerciseInfo?.exercise.name,
workout: bridgeModule.currentWorkoutInfo.workout),
extShowNextVideo {
smallAVPlayer = AVPlayer(url: smallVideoURL)
smallAVPlayer.play()

View File

@@ -23,7 +23,7 @@ struct ExerciseListView: View {
gender: thotGenderOption,
defaultVideoURLStr: self.videoExercise?.videoURL,
exerciseName: self.videoExercise?.name,
workout: bridgeModule.currentExerciseInfo.workout) {
workout: bridgeModule.currentWorkoutInfo.workout) {
avPlayer = AVPlayer(url: videoURL)
avPlayer.play()
}
@@ -42,8 +42,8 @@ struct ExerciseListView: View {
VStack {
HStack {
if bridgeModule.isInWorkout &&
supersetIndex == bridgeModule.currentExerciseInfo.supersetIndex &&
exerciseIndex == bridgeModule.currentExerciseInfo.exerciseIndex {
supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex &&
exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex {
Image(systemName: "figure.run")
.foregroundColor(Color("appColor"))
}
@@ -92,15 +92,17 @@ struct ExerciseListView: View {
.contentShape(Rectangle())
.onTapGesture {
if bridgeModule.isInWorkout {
bridgeModule.goToExerciseAt(section: supersetIndex, row: exerciseIndex)
bridgeModule.currentWorkoutInfo.goToExerciseAt(
supersetIndex: supersetIndex,
exerciseIndex: exerciseIndex)
} else {
videoExercise = supersetExecercise.exercise
}
}
if bridgeModule.isInWorkout &&
supersetIndex == bridgeModule.currentExerciseInfo.supersetIndex &&
exerciseIndex == bridgeModule.currentExerciseInfo.exerciseIndex &&
supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex &&
exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex &&
showExecersizeInfo {
detailView(forExercise: supersetExecercise)
}
@@ -125,8 +127,8 @@ struct ExerciseListView: View {
})
}
}
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { newValue in
if let newCurrentExercise = bridgeModule.currentExerciseInfo.currentExercise {
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { newValue in
if let newCurrentExercise = bridgeModule.currentWorkoutInfo.currentExercise {
withAnimation {
proxy.scrollTo(newCurrentExercise.id, anchor: .top)
}

View File

@@ -51,13 +51,13 @@ struct WorkoutDetailView: View {
Button(action: {
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url,
let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise,
let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise,
let otherVideoURL = VideoURLCreator.videoURL(
thotStyle: VideoURLCreator.otherVideoType(forVideoURL: assetURL),
gender: thotGenderOption,
defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) {
workout: bridgeModule.currentWorkoutInfo.workout) {
avPlayer = AVPlayer(url: otherVideoURL)
avPlayer.play()
}
@@ -98,7 +98,7 @@ struct WorkoutDetailView: View {
Divider()
.background(Color(uiColor: .secondaryLabel))
HStack {
Text("\(bridgeModule.currentExerciseInfo.currentRound) of \(bridgeModule.currentExerciseInfo.numberOfRoundsInCurrentSuperSet)")
Text("\(bridgeModule.currentWorkoutInfo.currentRound) of \(bridgeModule.currentWorkoutInfo.numberOfRoundsInCurrentSuperSet)")
.font(.title3)
.bold()
.frame(maxWidth: .infinity, alignment: .leading)
@@ -107,7 +107,7 @@ struct WorkoutDetailView: View {
CurrentWorkoutElapsedTimeView()
.frame(maxWidth: .infinity, alignment: .center)
Text("\(bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex+1)/\(bridgeModule.currentExerciseInfo.workout?.allSupersetExecercise?.count ?? -99)")
Text("\(bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex+1)/\(bridgeModule.currentWorkoutInfo.workout?.allSupersetExecercise?.count ?? -99)")
.font(.title3)
.bold()
.frame(maxWidth: .infinity, alignment: .trailing)
@@ -154,20 +154,20 @@ struct WorkoutDetailView: View {
}
}
}
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { _ in
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { _ in
playVideos()
})
.onChange(of: bridgeModule.isInWorkout, perform: { _ in
playVideos()
})
.onAppear{
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL(
thotStyle: phoneThotStyle,
gender: thotGenderOption,
defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) {
workout: bridgeModule.currentWorkoutInfo.workout) {
avPlayer = AVPlayer(url: videoURL)
avPlayer.play()
}
@@ -186,13 +186,13 @@ struct WorkoutDetailView: View {
}
func playVideos() {
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL(
thotStyle: phoneThotStyle,
gender: thotGenderOption,
defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) {
workout: bridgeModule.currentWorkoutInfo.workout) {
avPlayer = AVPlayer(url: videoURL)
avPlayer.play()
}
@@ -204,7 +204,7 @@ struct WorkoutDetailView: View {
}
func createWorkoutData() -> [String:Any]? {
guard let workoutid = bridgeModule.currentExerciseInfo.workout?.id,
guard let workoutid = bridgeModule.currentWorkoutInfo.workout?.id,
let startTime = bridgeModule.workoutStartDate?.timeFormatForUpload,
let endTime = bridgeModule.workoutEndDate?.timeFormatForUpload else {
return nil

View File

@@ -11,7 +11,7 @@ struct CountdownView: View {
@StateObject var bridgeModule = BridgeModule.shared
var body: some View {
if let duration = bridgeModule.currentExerciseInfo.currentExercise?.duration,
if let duration = bridgeModule.currentWorkoutInfo.currentExercise?.duration,
duration > 0 {
HStack {
if bridgeModule.currentExerciseTimeLeft >= 0 && duration > bridgeModule.currentExerciseTimeLeft {

View File

@@ -13,7 +13,7 @@ struct ExtCountdownView: View {
var body: some View {
GeometryReader { metrics in
VStack {
if let currenExercise = bridgeModule.currentExerciseInfo.currentExercise {
if let currenExercise = bridgeModule.currentWorkoutInfo.currentExercise {
HStack {
Text(currenExercise.exercise.extName)
.font(.system(size: 200))

View File

@@ -45,6 +45,7 @@ class PlayerUIView: UIView {
private func playerSetup(player: AVPlayer) {
playerLayer.player = player
player.actionAtItemEnd = .none
player.isMuted = true
layer.addSublayer(playerLayer)
self.setObserver()

View File

@@ -12,7 +12,7 @@ struct TitleView: View {
var body: some View {
HStack {
if let workout = bridgeModule.currentExerciseInfo.workout {
if let workout = bridgeModule.currentWorkoutInfo.workout {
Text(workout.name)
.font(Font.system(size: 100))
.frame(maxWidth: .infinity, alignment: .leading)