-
Notifications
You must be signed in to change notification settings - Fork 0
Fix timer ignoring workout repetitions #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,9 @@ class PlayWorkoutVIewModel( | |
| private val currentWorkoutInterval: Interval? | ||
| get() = currentWorkout?.intervals?.getOrNull(index = currentWorkoutIntervalIndex) | ||
|
|
||
| /** Tracks how many times the current workout's intervals have been repeated (0-based). */ | ||
| private var currentWorkoutRepetitionIndex: Int = 0 | ||
|
|
||
| private var pollProgressJob: Job? = null | ||
| private var runningMark: TimeMark? = null | ||
|
|
||
|
|
@@ -164,14 +167,34 @@ class PlayWorkoutVIewModel( | |
| currentWorkoutIntervalState == PlayWorkoutStateOfInterval.RESTING | ||
| val currentIntervalIsLastInWorkout = | ||
| currentWorkoutIntervalIndex == lastIndexOfIntervalsInCurrentWorkout | ||
| val hasFinishedAllWorkouts = isResting && currentIntervalIsLastInWorkout | ||
|
|
||
| if (hasFinishedAllWorkouts) { | ||
| _play.value = false | ||
| _text.value = "Start" | ||
| _enabled.value = false | ||
| pollProgressJob?.cancel() | ||
|
|
||
| val hasFinishedCurrentWorkoutCycle = isResting && currentIntervalIsLastInWorkout | ||
|
|
||
| if (hasFinishedCurrentWorkoutCycle) { | ||
| val totalRepetitions = currentWorkout?.repetitions ?: 1 | ||
| val hasMoreRepetitions = currentWorkoutRepetitionIndex < totalRepetitions - 1 | ||
| val isLastWorkout = currentWorkoutIndex == workouts.lastIndex | ||
|
Comment on lines
+170
to
+175
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all these names make sense to you? It got rid of |
||
|
|
||
| when { | ||
| hasMoreRepetitions -> { | ||
| currentWorkoutRepetitionIndex++ | ||
| currentWorkoutIntervalIndex = 0 | ||
| currentWorkoutIntervalState = PlayWorkoutStateOfInterval.EXERCISING | ||
| currentStepProgressMs = 0L | ||
| } | ||
| !isLastWorkout -> { | ||
| currentWorkoutRepetitionIndex = 0 | ||
| currentWorkoutIndex++ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR actually does something besides fixing repetitions 😮 So you see that right? It noticed that we also were ignoring the fact that we only were iterating over just one That is why this PR has so many lines change, it also includes that. Could we rename this PR and commit something like
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were initially focusing on a single workout because each workout already contains multiple intervals and exercises. My intention was that users could select which workout they want to run, which is why I was considering adding a database to manage multiple workouts. What do you think?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we will make it so instead of incrementing workouts, you always just "play" one workout at a time, right? Never more than one workout at a time. Then, because in the future, you will save workouts in a database, it'll be really easy to finish one workout and start another? I think that makes a lot of sense, and I bet if you fed these instructions into Claude it could kind of put some things together. One thing is that this would kind of be a big refactor because it probably eliminates the need to have the whole "Build Workout" screen. That said, I think if you want to merge this as-is it is fine, or you could remove (or tell Claude to remove) the lines about incrementing the workout for now. |
||
| currentWorkoutIntervalIndex = 0 | ||
| currentWorkoutIntervalState = PlayWorkoutStateOfInterval.EXERCISING | ||
| currentStepProgressMs = 0L | ||
| } | ||
| else -> { | ||
| _play.value = false | ||
| _text.value = "Start" | ||
| _enabled.value = false | ||
| pollProgressJob?.cancel() | ||
| } | ||
| } | ||
| } else { | ||
| nextStep() | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a nit, but I would change the comment to be like this to be more in line with the others.