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 { if currentExerciseTimeLeft > 1 {
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: { if let audioQueue = audioQueues.first(where: {
$0.playAt == currentExerciseTimeLeft $0.playAt == currentExerciseTimeLeft
}) { }) {

View File

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

View File

@@ -21,7 +21,7 @@ extension BridgeModule {
} }
func nextExercise() { func nextExercise() {
if let nextSupersetExercise = currentExerciseInfo.goToNextExercise { if let nextSupersetExercise = currentWorkoutInfo.goToNextExercise {
updateCurrent(exercise: nextSupersetExercise) updateCurrent(exercise: nextSupersetExercise)
} else { } else {
completeWorkout() completeWorkout()
@@ -29,7 +29,7 @@ extension BridgeModule {
} }
func previousExercise() { func previousExercise() {
if let nextSupersetExercise = currentExerciseInfo.previousExercise { if let nextSupersetExercise = currentWorkoutInfo.previousExercise {
updateCurrent(exercise: nextSupersetExercise) updateCurrent(exercise: nextSupersetExercise)
} else { } else {
completeWorkout() completeWorkout()
@@ -37,7 +37,7 @@ extension BridgeModule {
} }
func restartExercise() { func restartExercise() {
if let currentExercise = currentExerciseInfo.currentExercise { if let currentExercise = currentWorkoutInfo.currentExercise {
updateCurrent(exercise: currentExercise) updateCurrent(exercise: currentExercise)
} }
} }
@@ -67,17 +67,17 @@ extension BridgeModule {
} }
func start(workout: Workout) { func start(workout: Workout) {
currentExerciseInfo.complete = { currentWorkoutInfo.complete = {
self.completeWorkout() self.completeWorkout()
} }
currentExerciseInfo.start(workout: workout) currentWorkoutInfo.start(workout: workout)
currentWorkoutRunTimeInSeconds = 0 currentWorkoutRunTimeInSeconds = 0
currentWorkoutRunTimer?.invalidate() currentWorkoutRunTimer?.invalidate()
currentWorkoutRunTimer = nil currentWorkoutRunTimer = nil
isPaused = false isPaused = false
if let superetExercise = currentExerciseInfo.currentExercise { if let superetExercise = currentWorkoutInfo.currentExercise {
updateCurrent(exercise: superetExercise) updateCurrent(exercise: superetExercise)
startWorkoutTimer() startWorkoutTimer()
workoutStartDate = Date() 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? { var nextExerciseObject: SupersetExercise? {
currentExerciseInfo.goToNextExercise currentWorkoutInfo.goToNextExercise
} }
func resetCurrentWorkout() { func resetCurrentWorkout() {
@@ -115,7 +108,7 @@ extension BridgeModule {
self.currentExerciseTimer = nil self.currentExerciseTimer = nil
self.currentWorkoutRunTimeInSeconds = -1 self.currentWorkoutRunTimeInSeconds = -1
self.currentExerciseInfo.reset() self.currentWorkoutInfo.reset()
self.isInWorkout = false self.isInWorkout = false
self.workoutStartDate = nil self.workoutStartDate = nil

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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