Skip to content

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

Show the weekly plan rest day on home

saimskywalker5bd687511917
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index f828660..65c63ad 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -232,12 +232,14 @@ class HomeScreen extends StatelessWidget {
}
Widget _hero(BuildContext context, GymColors gc) {
- final rest = fit.restingToday ? fit.rotationUpcoming : null;
+ final rest = fit.restUpcoming;
final routine = rest ?? fit.todayRoutine;
final focus = fit.suggestedFocus;
final isRoutine = routine != null && routine.exerciseIds.isNotEmpty;
final label = rest != null
- ? t.rotationTitle
+ ? fit.rotating
+ ? t.rotationTitle
+ : t.weeklyPlan
: isRoutine
? t.todaysRoutine
: t.todaysFocus;
@@ -251,7 +253,7 @@ class HomeScreen extends StatelessWidget {
final subtitle = rest != null
? [
t.rotationRestUpNext(fit.routineTitle(rest)),
- t.rotationPlace(fit.rotationStep + 1, fit.rotationSteps.length),
+ if (fit.rotating) t.rotationPlace(fit.rotationStep + 1, fit.rotationSteps.length),
].join(' · ')
: done
? t.routineDoneToday
diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dart
index d942471..66eecb9 100644
--- a/lib/state/routines_state.dart
+++ b/lib/state/routines_state.dart
@@ -230,6 +230,17 @@ mixin RoutinesState on FitCore, LibraryState {
bool get restingToday => rotationRestOn(DateTime.now());
+ Routine? get restUpcoming {
+ if (rotating) return restingToday ? rotationUpcoming : null;
+ final today = _dayKey(DateTime.now());
+ if (routinesOn(today).isNotEmpty || sessions.any((s) => _dayKey(s.day) == today)) return null;
+ for (var i = 1; i <= 7; i++) {
+ final next = routinesOn(shiftDays(today, i));
+ if (next.isNotEmpty) return next.first;
+ }
+ return null;
+ }
+
bool rotationRestOn(DateTime day) {
if (!rotating) return false;
final key = _dayKey(day);
diff --git a/test/weekly_plan_test.dart b/test/weekly_plan_test.dart
index a075a5c..5981f92 100644
--- a/test/weekly_plan_test.dart
+++ b/test/weekly_plan_test.dart
@@ -346,4 +346,68 @@ void main() {
expect(fit.planIdsOn(1), [b.id], reason: 'apagado se ignoran las extra');
});
});
+
+ group('#284 descanso del plan semanal en inicio', () {
+ setUp(() async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.resetAllData();
+ fit.onboarded = true;
+ });
+
+ Routine routine(String name) {
+ final id = fit.createRoutine(name);
+ fit.toggleRoutineExercise(id, fit.matchExerciseByName('Bench Press')!.id);
+ return fit.routines.firstWhere((r) => r.id == id);
+ }
+
+ DateTime day(int offset) {
+ final n = DateTime.now();
+ return DateTime(n.year, n.month, n.day + offset, 10);
+ }
+
+ test('hoy sin rutina es descanso y apunta a la siguiente del plan', () {
+ final a = routine('A'), b = routine('B');
+ fit.assignRoutineToDay(day(2).weekday, a.id);
+ fit.assignRoutineToDay(day(4).weekday, b.id);
+ expect(fit.todayRoutine, isNull);
+ expect(fit.restUpcoming, same(a));
+ });
+
+ test('con rutina hoy, entreno hecho o sin plan no hay descanso', () {
+ expect(fit.restUpcoming, isNull, reason: 'sin plan');
+ final a = routine('A');
+ fit.assignRoutineToDay(day(1).weekday, a.id);
+ expect(fit.restUpcoming, same(a));
+ fit.sessions.add(LoggedSession(DateTime.now(), 1800, const []));
+ expect(fit.restUpcoming, isNull, reason: 'ya entrenó hoy');
+ fit.sessions.clear();
+ fit.assignRoutineToDay(DateTime.now().weekday, a.id);
+ expect(fit.restUpcoming, isNull, reason: 'hoy toca');
+ });
+
+ test('mover la de hoy a otro día deja hoy de descanso', () {
+ final a = routine('A');
+ fit.assignRoutineToDay(DateTime.now().weekday, a.id);
+ fit.moveRoutineDay(a.id, DateTime.now(), day(2));
+ expect(fit.restUpcoming, same(a));
+ });
+
+ test('en rotación sigue usando su propio descanso', () {
+ final legs = routine('Legs'), push = routine('Push');
+ fit.setRotation(true);
+ fit.toggleRotationRoutine(legs.id);
+ fit.addRotationRest();
+ fit.toggleRotationRoutine(push.id);
+ expect(fit.restUpcoming, isNull, reason: 'hoy toca Legs');
+
+ fit.startRoutine(legs, on: day(-1));
+ fit.endCountdown();
+ fit.toggleSet(0, 0);
+ fit.finishSession();
+ fit.saveAndExit();
+ expect(fit.restingToday, isTrue);
+ expect(fit.restUpcoming, same(push));
+ });
+ });
}