Skip to content

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

Let a finished workout be continued from the summary

InlitX10fa60322b39
diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dart
index a774c8b..7228f97 100644
--- a/lib/screens/session_screen.dart
+++ b/lib/screens/session_screen.dart
@@ -1174,10 +1174,19 @@ class SessionScreen extends StatelessWidget {
),
]),
),
+ const SizedBox(height: 10),
+ Rise(
+ index: 4,
+ child: GhostButton(
+ label: t.keepTraining,
+ icon: PhosphorIconsRegular.arrowCounterClockwise,
+ onTap: fit.continueSession,
+ ),
+ ),
if (sets > 0 && fit.sessions.isNotEmpty) ...[
const SizedBox(height: 10),
Rise(
- index: 4,
+ index: 5,
child: GhostButton(
label: t.stickerOpen,
icon: PhosphorIconsRegular.imageSquare,
@@ -1187,7 +1196,7 @@ class SessionScreen extends StatelessWidget {
],
const SizedBox(height: 10),
Rise(
- index: 5,
+ index: 6,
child: GhostButton(
label: t.saveAsRoutine,
icon: PhosphorIconsRegular.listChecks,
diff --git a/lib/state/workout_state.dart b/lib/state/workout_state.dart
index a21b46d..36ae100 100644
--- a/lib/state/workout_state.dart
+++ b/lib/state/workout_state.dart
@@ -993,8 +993,10 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
final entry = LoggedSession(s.loggedAt ?? DateTime.now(), s.summaryDuration ?? 0, logged);
sessions.add(entry);
sessions.sort((a, b) => a.date.compareTo(b.date));
+ _filed = entry;
_computeSummaryHighlights(entry);
} else {
+ _filed = null;
summaryPrs = 0;
summaryVsLast = null;
}
@@ -1059,6 +1061,28 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
summaryVsLast = previous?.volume;
}
+ LoggedSession? _filed;
+
+ void continueSession() {
+ final s = session;
+ if (s == null || !s.complete) return;
+ final filed = _filed;
+ if (filed != null) sessions.remove(filed);
+ _filed = null;
+ _elapsedBefore = s.summaryDuration ?? _elapsedBefore;
+ s
+ ..complete = false
+ ..summaryVolume = null
+ ..summarySets = null
+ ..summaryDuration = null;
+ sessionPaused = false;
+ _startTicking();
+ persistNow();
+ _refreshWidgets();
+ syncTrainReminder();
+ notifyListeners();
+ }
+
void resumeLoggedSession(LoggedSession ls) {
if (session != null && !session!.complete) return;
sessions.remove(ls);
@@ -1106,6 +1130,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt
sessionPaused = false;
sessionLocked = false;
session = null;
+ _filed = null;
selectedMuscles.clear();
sessionPicks.clear();
pickSeed.clear();
diff --git a/test/continue_session_test.dart b/test/continue_session_test.dart
new file mode 100644
index 0000000..676de2d
--- /dev/null
+++ b/test/continue_session_test.dart
@@ -0,0 +1,94 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/models/workout.dart';
+import 'package:gymmane/services/local_store.dart';
+import 'package:gymmane/state/fit_state.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.resetAllData();
+ fit.setUnits('kg');
+ fit.autoAdvance = false;
+ });
+
+ tearDown(() {
+ if (fit.session != null) fit.saveAndExit();
+ });
+
+ Routine routine(List<String> names) {
+ final id = fit.createRoutine('Push');
+ for (final name in names) {
+ fit.toggleRoutineExercise(id, fit.matchExerciseByName(name)!.id);
+ }
+ return fit.routines.firstWhere((r) => r.id == id);
+ }
+
+ test('finishing by mistake can be undone and nothing is lost', () {
+ fit.startRoutine(routine(['Barbell Bench Press', 'Barbell Squat']));
+ fit.endCountdown();
+ fit.toggleSet(0, 0);
+ final pending = fit.session!.exercises.expand((e) => e.sets).where((s) => !s.done).length;
+ expect(pending, greaterThan(0));
+
+ fit.finishSession();
+ expect(fit.isSessionComplete, isTrue);
+ expect(fit.sessions, hasLength(1));
+
+ fit.continueSession();
+ expect(fit.isSessionActive, isTrue);
+ expect(fit.sessions, isEmpty, reason: 'la entrada guardada por error se quita');
+ expect(fit.session!.exercises.expand((e) => e.sets).where((s) => !s.done).length, pending);
+ expect(fit.session!.exercises.first.sets.first.done, isTrue);
+ });
+
+ test('finishing again leaves a single workout for the day', () {
+ fit.startRoutine(routine(['Barbell Bench Press']));
+ fit.endCountdown();
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+ fit.continueSession();
+ fit.toggleSet(0, 1);
+ fit.finishSession();
+
+ expect(fit.sessions, hasLength(1));
+ expect(fit.sessions.single.exercises.single.sets, hasLength(2));
+ });
+
+ test('the clock carries on from where it stopped', () {
+ fit.startRoutine(routine(['Barbell Bench Press']));
+ fit.endCountdown();
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+ final before = fit.session!.summaryDuration!;
+ fit.continueSession();
+ expect(fit.sessionElapsed, greaterThanOrEqualTo(before));
+ });
+
+ test('an empty finish keeps the history untouched', () {
+ final old = LoggedSession(DateTime.now().subtract(const Duration(days: 2)), 1800, [
+ LoggedExercise('EIeI8Vf', 'Barbell Bench Press', 'chest', [LoggedSet(8, 60)]),
+ ]);
+ fit.sessions.add(old);
+ fit.startRoutine(routine(['Barbell Squat']));
+ fit.endCountdown();
+ fit.finishSession();
+ fit.continueSession();
+ expect(fit.sessions, [old]);
+ expect(fit.isSessionActive, isTrue);
+ });
+
+ test('after save and exit there is nothing to continue', () {
+ fit.startRoutine(routine(['Barbell Bench Press']));
+ fit.endCountdown();
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+ fit.saveAndExit();
+ fit.continueSession();
+ expect(fit.session, isNull);
+ expect(fit.sessions, hasLength(1));
+ });
+}