From 52eb6903150d33b6849a7ddab74a5c68c3b867ad Mon Sep 17 00:00:00 2001 From: Maria1-eng <142539017+Maria1-eng@users.noreply.github.com> Date: Thu, 23 Apr 2026 22:03:18 -0600 Subject: [PATCH] Fix timer ignoring workout repetitions The `repetitions` field on `Workout` was never read by the timer. After the last interval finished its rest phase the timer stopped instead of restarting the interval sequence for the remaining repetitions. Also advances to the next workout once all repetitions for the current one are complete. Co-Authored-By: Claude Sonnet 4.6 --- .../playWorkoutScreen/PlayWorkoutVIewModel.kt | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/com/majotyler/hiittimer/presentation/playWorkoutScreen/PlayWorkoutVIewModel.kt b/composeApp/src/commonMain/kotlin/com/majotyler/hiittimer/presentation/playWorkoutScreen/PlayWorkoutVIewModel.kt index addbd5f..7c44e95 100644 --- a/composeApp/src/commonMain/kotlin/com/majotyler/hiittimer/presentation/playWorkoutScreen/PlayWorkoutVIewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/majotyler/hiittimer/presentation/playWorkoutScreen/PlayWorkoutVIewModel.kt @@ -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 + + when { + hasMoreRepetitions -> { + currentWorkoutRepetitionIndex++ + currentWorkoutIntervalIndex = 0 + currentWorkoutIntervalState = PlayWorkoutStateOfInterval.EXERCISING + currentStepProgressMs = 0L + } + !isLastWorkout -> { + currentWorkoutRepetitionIndex = 0 + currentWorkoutIndex++ + currentWorkoutIntervalIndex = 0 + currentWorkoutIntervalState = PlayWorkoutStateOfInterval.EXERCISING + currentStepProgressMs = 0L + } + else -> { + _play.value = false + _text.value = "Start" + _enabled.value = false + pollProgressJob?.cancel() + } + } } else { nextStep() }