Skip to content

Offline gym log for Android. No account, no ads, no internet.

Keep counting past the target on timed and cardio sets

InlitXc33ea3763287
diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dart
index 06fc208..98ad7f0 100644
--- a/lib/screens/session_screen.dart
+++ b/lib/screens/session_screen.dart
@@ -793,10 +793,13 @@ class SessionScreen extends StatelessWidget {
Widget _holdDock(GymColors gc) {
final lead = fit.holdLead;
- final left = lead > 0 ? lead : fit.holdRemaining ?? 0;
+ final over = fit.holdOvertime;
+ final left = over ? 0 : (lead > 0 ? lead : fit.holdRemaining ?? 0);
final total = lead > 0 ? WorkoutState.holdLeadIn : (fit.holdTotal <= 0 ? 1 : fit.holdTotal);
final ex = fit.session?.exercises[fit.holdEx];
- final label = lead > 0
+ final label = over
+ ? t.holdOvertime
+ : lead > 0
? (fit.switchingSides ? t.switchSides : t.getReady)
: fit.holdSides > 1
? t.sideOfTwo('${fit.holdSide + 1}')
@@ -817,7 +820,8 @@ class SessionScreen extends StatelessWidget {
FitText(
[label.toUpperCase(), if (ex != null) t.catalogName(ex.id, ex.name)].join(' · '),
style: AppTheme.f(9.5, weight: FontWeight.w800, color: gc.ember, letterSpacing: 1)),
- RollingText(clockLabel(left), style: AppTheme.f(24, weight: FontWeight.w800, color: gc.text, height: 1.1)),
+ RollingText(over ? '+${clockLabel(fit.holdExtra)}' : clockLabel(left),
+ style: AppTheme.f(24, weight: FontWeight.w800, color: gc.text, height: 1.1)),
]),
),
_dockButton(gc, fit.holdPaused ? t.finishHoldNow : t.stopLabel,
@@ -1992,16 +1996,20 @@ class SessionScreen extends StatelessWidget {
Widget _holdPanel(GymColors gc) {
final count = fit.sessionSetCount;
final lead = fit.holdLead;
+ final over = fit.holdOvertime;
return TimerPanel(
- label: lead > 0
+ label: over
+ ? t.holdOvertime
+ : lead > 0
? (fit.switchingSides ? t.switchSides : t.getReady)
: fit.modeOf(fit.session?.exercises[fit.holdEx].id ?? '') == 'cardio'
? t.kindCardio
: fit.holdSides > 1
? t.sideOfTwo('${fit.holdSide + 1}')
: t.holdLabel,
- remaining: lead > 0 ? lead : fit.holdRemaining ?? 0,
+ remaining: over ? fit.holdTotal : (lead > 0 ? lead : fit.holdRemaining ?? 0),
total: lead > 0 ? WorkoutState.holdLeadIn : fit.holdTotal,
+ clock: over ? '+${clockLabel(fit.holdExtra)}' : null,
elapsed: fit.elapsedLabel,
elapsedLabel: t.elapsedCaps,
sets: '${count.done}/${count.total}',
@@ -2066,7 +2074,9 @@ class SessionScreen extends StatelessWidget {
return _ticking(() => PrimaryButton(
label: fit.holdPaused
? t.finishHoldNow
- : '${t.stopLabel} · ${durationLabel(fit.holdRemaining ?? 0)}',
+ : fit.holdOvertime
+ ? '${t.stopLabel} · +${durationLabel(fit.holdExtra)}'
+ : '${t.stopLabel} · ${durationLabel(fit.holdRemaining ?? 0)}',
onTap: fit.holdPaused ? fit.completeHold : fit.stopHold,
height: 52,
));
diff --git a/lib/state/workout_state.dart b/lib/state/workout_state.dart
index b2ed0b9..518e1e4 100644
--- a/lib/state/workout_state.dart
+++ b/lib/state/workout_state.dart
@@ -142,8 +142,12 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
..sort((a, b) => rank(a).compareTo(rank(b)));
if (forMuscle.isNotEmpty) picks.add(forMuscle.first);
}
+ int aim(Exercise e) => muscles.contains(e.primary) ? 0 : 1;
final rest = pool.where((e) => !picks.contains(e)).toList()
- ..sort((a, b) => rank(a).compareTo(rank(b)));
+ ..sort((a, b) {
+ final byAim = aim(a).compareTo(aim(b));
+ return byAim != 0 ? byAim : rank(a).compareTo(rank(b));
+ });
for (final e in rest) {
if (picks.length >= _pickTarget) break;
picks.add(e);
@@ -894,8 +898,9 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
double get sessionVolumeKg {
var kg = 0.0;
for (final e in session?.exercises ?? const <SessionExercise>[]) {
+ final times = isPaired(e.id) ? 2 : 1;
for (final st in e.sets) {
- if (st.done && st.counts) kg += st.weakReps * st.weight;
+ if (st.done && st.counts) kg += st.weakReps * st.weight * times;
}
}
return kg;
@@ -1320,8 +1325,19 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
int holdSet = -1;
int holdSide = 0;
int holdSides = 1;
+ DateTime? holdOverFrom;
+ int _pausedOverMs = 0;
Timer? _holdTimer;
+ bool get holdOvertime => holdOverFrom != null;
+
+ int get holdExtra {
+ final from = holdOverFrom;
+ if (from == null) return 0;
+ if (holdPaused) return _pausedOverMs ~/ 1000;
+ return math.max(0, DateTime.now().difference(from).inSeconds);
+ }
+
static const holdLeadIn = 5;
static int _secondsUntil(DateTime? at) {
@@ -1346,6 +1362,20 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
final start = holdStartsAt, end = holdEndsAt;
if (start == null || end == null) return;
final now = DateTime.now();
+ final over = holdOverFrom;
+ if (over != null) {
+ if (holdPaused) {
+ holdOverFrom = now.subtract(Duration(milliseconds: _pausedOverMs));
+ holdPaused = false;
+ _runHold();
+ } else {
+ _pausedOverMs = math.max(0, now.difference(over).inMilliseconds);
+ _holdTimer?.cancel();
+ holdPaused = true;
+ }
+ notifyListeners();
+ return;
+ }
if (holdPaused) {
holdStartsAt = now.add(Duration(milliseconds: _pausedLeadMs));
holdEndsAt = now.add(Duration(milliseconds: _pausedEndMs));
@@ -1361,6 +1391,10 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
}
void completeHold() {
+ if (holdOvertime) {
+ _finishOvertime();
+ return;
+ }
final s = session;
if (s != null && holdEx >= 0 && holdEx < s.exercises.length && holdLead == 0) {
final ex = s.exercises[holdEx];
@@ -1400,6 +1434,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
holdSide = 0;
holdSides = isEachSide(s.exercises[exIdx].id) ? 2 : 1;
holdTotal = secs;
+ holdOverFrom = null;
final now = DateTime.now();
holdStartsAt = now.add(const Duration(seconds: holdLeadIn));
holdEndsAt = holdStartsAt!.add(Duration(seconds: secs));
@@ -1413,13 +1448,27 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
final sound = alarmStyle != 'vibrate';
var shownLead = holdLead;
var shown = holdRemaining;
+ var shownExtra = holdExtra;
_holdTimer = Timer.periodic(const Duration(milliseconds: 100), (_) {
+ if (holdOverFrom != null) {
+ final extra = holdExtra;
+ if (extra != shownExtra) {
+ shownExtra = extra;
+ clock.value++;
+ }
+ return;
+ }
final lead = holdLead;
final left = holdRemaining;
if (left == 0) {
Beeper.instance.go(sound: sound);
if (holdSide + 1 < holdSides) {
_nextSide();
+ } else if (_holdKeepsCounting) {
+ holdOverFrom = DateTime.now();
+ shownExtra = 0;
+ clock.value++;
+ notifyListeners();
} else {
_finishHold();
}
@@ -1454,7 +1503,30 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
notifyListeners();
}
+ bool get _holdKeepsCounting {
+ final s = session;
+ if (s == null || holdEx < 0 || holdEx >= s.exercises.length || holdSides > 1) return false;
+ return keepsCounting(s.exercises[holdEx].id);
+ }
+
+ void _finishOvertime() {
+ final s = session;
+ if (s != null && holdEx >= 0 && holdEx < s.exercises.length) {
+ final sets = s.exercises[holdEx].sets;
+ if (holdSet >= 0 && holdSet < sets.length) sets[holdSet].sec = (holdTotal + holdExtra).clamp(1, 18000);
+ }
+ _finishHold();
+ }
+
void stopHold() {
+ if (holdOvertime) {
+ _finishOvertime();
+ return;
+ }
+ _clearHold();
+ }
+
+ void _clearHold() {
_holdTimer?.cancel();
_holdTimer = null;
holdPaused = false;
@@ -1462,6 +1534,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
holdSides = 1;
holdEndsAt = null;
holdStartsAt = null;
+ holdOverFrom = null;
holdEx = -1;
holdSet = -1;
notifyListeners();
@@ -1469,7 +1542,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
void _finishHold() {
final exIdx = holdEx, setIdx = holdSet;
- stopHold();
+ _clearHold();
final s = session;
if (s == null || exIdx < 0 || exIdx >= s.exercises.length) return;
final sets = s.exercises[exIdx].sets;
@@ -1823,6 +1896,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
void finishSession() {
_holdTimer?.cancel();
holdEndsAt = null;
+ holdOverFrom = null;
_advanceTimer?.cancel();
_sessionTimer?.cancel();
_restTimer?.cancel();
@@ -2334,6 +2408,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
void saveAndExit() {
_holdTimer?.cancel();
holdEndsAt = null;
+ holdOverFrom = null;
holdEx = -1;
holdSet = -1;
_advanceTimer?.cancel();
diff --git a/lib/wear/wear_shell.dart b/lib/wear/wear_shell.dart
index 2fff317..ddbb9bc 100644
--- a/lib/wear/wear_shell.dart
+++ b/lib/wear/wear_shell.dart
@@ -1083,7 +1083,7 @@ class WearSession extends StatelessWidget {
? t.sideOfTwo('${fit.holdSide + 1}')
: t.timeCol),
style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary)),
- Text(lead > 0 ? '$lead' : durationLabel(left),
+ Text(lead > 0 ? '$lead' : (fit.holdOvertime ? '+${durationLabel(fit.holdExtra)}' : durationLabel(left)),
style: AppTheme.f(32, weight: FontWeight.w800, color: lead > 0 ? gc.accent : gc.text, height: 1.1)),
]),
);
diff --git a/lib/widgets/timer_panel.dart b/lib/widgets/timer_panel.dart
index 152d6f9..1ea8585 100644
--- a/lib/widgets/timer_panel.dart
+++ b/lib/widgets/timer_panel.dart
@@ -25,6 +25,7 @@ class TimerPanel extends StatelessWidget {
this.onMinus,
this.onPlus,
this.color,
+ this.clock,
});
final String label;
@@ -39,6 +40,7 @@ class TimerPanel extends StatelessWidget {
final VoidCallback? onMinus;
final VoidCallback? onPlus;
final Color? color;
+ final String? clock;
@override
Widget build(BuildContext context) {
@@ -47,7 +49,7 @@ class TimerPanel extends StatelessWidget {
final left = total <= 0 ? 0.0 : (remaining / total).clamp(0.0, 1.0);
return Semantics(
button: true,
- label: '$label ${clockLabel(remaining)}',
+ label: '$label ${clock ?? clockLabel(remaining)}',
hint: hint,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
@@ -100,8 +102,8 @@ class TimerPanel extends StatelessWidget {
const SizedBox(width: 10),
Column(
children: [
- RollingText(clockLabel(remaining),
- countsDown: true,
+ RollingText(clock ?? clockLabel(remaining),
+ countsDown: clock == null,
style: AppTheme.f(36, weight: FontWeight.w800, color: gc.text, height: 1.05)),
const SizedBox(height: 4),
ConstrainedBox(
diff --git a/test/timed_and_cardio_test.dart b/test/timed_and_cardio_test.dart
index def6de6..4c7de50 100644
--- a/test/timed_and_cardio_test.dart
+++ b/test/timed_and_cardio_test.dart
@@ -204,6 +204,48 @@ void main() {
fit.skipRest();
});
+ test('#390 seguir contando: suena, sigue y guarda el tiempo real al parar', () async {
+ fit.toggleKeepCounting('plank-hold');
+ fit.startRoutine(routineOf(['plank-hold']));
+ fit.endCountdown();
+ final set = fit.session!.exercises.first.sets.first;
+ final planned = fit.holdTotal;
+ fit.startHold(0, 0);
+ await endSide();
+ expect(fit.holding, isTrue);
+ expect(fit.holdOvertime, isTrue);
+ expect(set.done, isFalse);
+ fit.holdOverFrom = DateTime.now().subtract(const Duration(seconds: 40));
+ expect(fit.holdExtra, inInclusiveRange(39, 41));
+ fit.toggleHoldPause();
+ final paused = fit.holdExtra;
+ await Future<void>.delayed(const Duration(milliseconds: 1100));
+ expect(fit.holdExtra, paused, reason: 'en pausa no corre');
+ fit.toggleHoldPause();
+ fit.stopHold();
+ expect(fit.holding, isFalse);
+ expect(fit.holdOvertime, isFalse);
+ expect(set.done, isTrue);
+ expect(set.sec, inInclusiveRange(planned + 39, planned + 41));
+ fit.skipRest();
+ });
+
+ test('#390 sin el ajuste, o por lados, para al llegar como siempre', () async {
+ fit.toggleKeepCounting('side-plank-hold');
+ fit.startRoutine(routineOf(['plank-hold', 'side-plank-hold']));
+ fit.endCountdown();
+ fit.startHold(0, 0);
+ await endSide();
+ expect(fit.holding, isFalse);
+ fit.skipRest();
+ fit.startHold(1, 0);
+ await endSide();
+ await endSide();
+ expect(fit.holdOvertime, isFalse);
+ expect(fit.session!.exercises[1].sets.first.done, isTrue);
+ fit.skipRest();
+ });
+
test('pararlo deja todo como al principio', () {
fit.startRoutine(routineOf(['side-plank-hold']));
fit.endCountdown();