Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Use the progressed time in routines and save the real time of a hold finished early
InlitXab2645eff3e2
diff --git a/lib/state/workout_state.dart b/lib/state/workout_state.dartindex 518e1e4..87ec2cf 100644--- a/lib/state/workout_state.dart+++ b/lib/state/workout_state.dart@@ -233,6 +233,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStfinal warmWeight = fromDisplayWeight(_roundTo(toDisplayWeight(first.weight * 0.5), plateStep));final out = <SessionSet>[];var w = 0;+ final hold = nextHoldSeconds(id);for (final p in planned) {final warm = p.kind == SetKind.warmup;final b = warm || base.isEmpty ? first : base[(w++).clamp(0, base.length - 1)];@@ -242,7 +243,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStown ? b.weight : p.weightKg ?? (warm ? warmWeight : b.weight),false,kind: p.kind,- sec: p.sec ?? b.sec,+ sec: !warm && hold != null ? hold : p.sec ?? b.sec,km: p.km ?? b.km,goal: own || warm || p.repsMax == null ? null : p.repsLabel,));@@ -303,14 +304,14 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStif (step <= 0) return null;final secs = [for (final l in lastSetsFor(id)) if (l.counts && (l.sec ?? 0) > 0) l.sec!];if (secs.isEmpty) return null;- final aim = secs.first;+ final aim = secs.reduce(math.max);return secs.every((s) => s >= aim) ? aim + step : aim;}bool holdGoesUp(String id) {final next = nextHoldSeconds(id);final last = [for (final l in lastSetsFor(id)) if (l.counts && (l.sec ?? 0) > 0) l.sec!];- return next != null && last.isNotEmpty && next > last.first;+ return next != null && last.isNotEmpty && next > last.reduce(math.max);}List<SessionSet> _modeOpeners(String mode, List<LoggedSet> last, [String? id]) {@@ -1399,7 +1400,11 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStif (s != null && holdEx >= 0 && holdEx < s.exercises.length && holdLead == 0) {final ex = s.exercises[holdEx];final ran = holdTotal - (holdRemaining ?? 0);- if (modeOf(ex.id) == 'cardio' && ran > 0 && holdSet < ex.sets.length) ex.sets[holdSet].sec = ran;+ final mode = modeOf(ex.id);+ final short = mode == 'cardio' ? ran < holdTotal : ran < holdTotal - 2;+ if ((mode == 'cardio' || mode == 'time') && ran > 0 && short && holdSet < ex.sets.length) {+ ex.sets[holdSet].sec = ran;+ }}_finishHold();}diff --git a/test/timed_and_cardio_test.dart b/test/timed_and_cardio_test.dartindex 4c7de50..5024047 100644--- a/test/timed_and_cardio_test.dart+++ b/test/timed_and_cardio_test.dart@@ -105,19 +105,34 @@ void main() {expect(set.sec, inInclusiveRange(299, 301));});- test('un aguante terminado antes sigue guardando lo planeado', () {+ test('un aguante terminado antes guarda lo aguantado (#404)', () {final plank = fit.matchExerciseByName('Plank')!.id;fit.startRoutine(routineOf([plank]));fit.endCountdown();fit.setExerciseMode(plank, 'time');- final planned = fit.session!.exercises.first.sets.first.sec;+ fit.session!.exercises.first.sets.first.sec = 30;fit.startHold(0, 0);- final start = DateTime.now().subtract(const Duration(seconds: 10));+ final start = DateTime.now().subtract(const Duration(seconds: 19));fit.holdStartsAt = start;fit.holdEndsAt = start.add(Duration(seconds: fit.holdTotal));fit.toggleHoldPause();fit.completeHold();- expect(fit.session!.exercises.first.sets.first.sec, planned);+ expect(fit.session!.exercises.first.sets.first.sec, inInclusiveRange(18, 20));+ });++ test('a un segundo del final cuenta como completo', () {+ final plank = fit.matchExerciseByName('Plank')!.id;+ fit.startRoutine(routineOf([plank]));+ fit.endCountdown();+ fit.setExerciseMode(plank, 'time');+ fit.session!.exercises.first.sets.first.sec = 30;+ fit.startHold(0, 0);+ final start = DateTime.now().subtract(const Duration(seconds: 29));+ fit.holdStartsAt = start;+ fit.holdEndsAt = start.add(Duration(seconds: fit.holdTotal));+ fit.toggleHoldPause();+ fit.completeHold();+ expect(fit.session!.exercises.first.sets.first.sec, 30);});});@@ -527,6 +542,22 @@ void main() {held([45, 40, 45]);expect(fit.nextHoldSeconds(plank()), 45);expect(fit.holdGoesUp(plank()), isFalse);+ fit.sessions.clear();+ held([19, 30, 30]);+ expect(fit.nextHoldSeconds(plank()), 30);+ expect(fit.holdGoesUp(plank()), isFalse);+ });++ test('una rutina con segundos propios abre con los de la progresión (#404)', () {+ held([30, 30, 30]);+ fit.cycleHoldStep(plank(), 1);+ fit.cycleHoldStep(plank(), 1);+ final r = fit.createRoutine('Core');+ fit.toggleRoutineExercise(r, plank());+ fit.setPlannedSets(r, plank(), const [PlannedSet(sec: 30), PlannedSet(sec: 30), PlannedSet(sec: 30)]);+ fit.startRoutine(fit.routines.firstWhere((x) => x.id == r));+ expect(fit.session!.exercises.single.sets.map((s) => s.sec), everyElement(40));+ expect(fit.nextTargetLabel(plank()), contains('40'));});test('la sesión abre con los segundos nuevos y el ajuste se guarda', () {