Skip to content

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

Reorder routines, show when each was last done, scroll the group list

InlitXbbd85a4d5350
diff --git a/lib/screens/routine_edit_screen.dart b/lib/screens/routine_edit_screen.dart
index c22c781..19c700c 100644
--- a/lib/screens/routine_edit_screen.dart
+++ b/lib/screens/routine_edit_screen.dart
@@ -926,6 +926,10 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
const SizedBox(height: 8),
_progressRow(sheet, gc, ex),
],
+ if (mode.isEmpty || mode == 'time') ...[
+ const SizedBox(height: 8),
+ _sidesRow(gc, ex, mode),
+ ],
const SizedBox(height: 8),
_altsRow(sheet, gc, routine, ex),
if (fit.modeOf(ex.id).isEmpty) ...[
@@ -943,6 +947,35 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
);
}
+ Widget _sidesRow(GymColors gc, Exercise ex, String mode) {
+ final timed = mode == 'time';
+ final on = timed ? fit.isEachSide(ex.id) : fit.isSidedReps(ex.id);
+ return Pressable(
+ scale: 0.98,
+ onTap: () => timed ? fit.toggleEachSide(ex.id) : fit.toggleSidedReps(ex.id),
+ child: Container(
+ padding: const EdgeInsets.fromLTRB(16, 12, 12, 12),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(18)),
+ child: Row(children: [
+ Icon(PhosphorIconsRegular.arrowsLeftRight, size: 19, color: on ? gc.text : gc.textSecondary),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(t.eachSide, style: AppTheme.f(14, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(timed ? t.eachSideHint : t.eachSideRepsHint,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textSecondary, height: 1.3)),
+ ]),
+ ),
+ const SizedBox(width: 10),
+ TinySwitch(on: on),
+ ]),
+ ),
+ );
+ }
+
Widget _progressRow(BuildContext sheet, GymColors gc, Exercise ex) {
final kind = fit.progressRule(ex.id).kind;
final on = fit.hasProgress(ex.id);
@@ -1327,19 +1360,12 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
}
void _pickGroup(Routine routine) {
- final gc = context.gc;
showAppSheet<void>(
context: context,
+ isScrollControlled: true,
backgroundColor: Colors.transparent,
- builder: (sheet) => Container(
- padding: sheetPad(sheet),
- decoration: sheetDecoration(gc),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
+ builder: (sheet) => AppSheet(
children: [
- const SheetHandle(),
- const SizedBox(height: 16),
SheetTitle(t.routineGroup),
const SizedBox(height: 14),
OptionGroup([
@@ -1371,7 +1397,6 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
},
),
],
- ),
),
);
}
diff --git a/lib/screens/routines_screen.dart b/lib/screens/routines_screen.dart
index b37ffba..a48900b 100644
--- a/lib/screens/routines_screen.dart
+++ b/lib/screens/routines_screen.dart
@@ -1121,6 +1121,11 @@ class RoutinesScreen extends StatelessWidget {
Navigator.pop(sheet);
fit.moveGroup(name, 1);
}),
+ if (count > 1)
+ OptionItem(t.routinesOrder, icon: PhosphorIconsRegular.arrowsDownUp, onTap: () {
+ Navigator.pop(sheet);
+ showRoutineOrderSheet(context, name);
+ }),
OptionItem(t.groupRename, icon: PhosphorIconsRegular.pencilSimple, onTap: () async {
Navigator.pop(sheet);
final next = await askText(context, title: t.groupRename, initial: name, hint: t.groupNameHint);
@@ -1386,6 +1391,11 @@ void showRoutineMenu(BuildContext context, Routine r) {
Navigator.pop(sheet);
fit.duplicateRoutine(r.id);
}),
+ if (!r.archived && fit.routinesInGroup(r.group).length > 1)
+ OptionItem(t.routinesOrder, icon: PhosphorIconsRegular.arrowsDownUp, onTap: () {
+ Navigator.pop(sheet);
+ showRoutineOrderSheet(context, r.group);
+ }),
OptionItem(r.archived ? t.restoreExercise : t.archiveRoutine,
icon: r.archived ? PhosphorIconsRegular.arrowUUpLeft : PhosphorIconsRegular.archive, onTap: () {
Navigator.pop(sheet);
@@ -1418,3 +1428,58 @@ void showRoutineMenu(BuildContext context, Routine r) {
),
);
}
+
+void showRoutineOrderSheet(BuildContext context, String group) {
+ final gc = context.gc;
+ showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (sheet) => AnimatedBuilder(
+ animation: fit,
+ builder: (sheet, _) {
+ final list = fit.routinesInGroup(group);
+ return AppSheet(children: [
+ SheetTitle(t.routinesOrder, subtitle: t.routinesOrderHint),
+ const SizedBox(height: 16),
+ ReorderableListView(
+ shrinkWrap: true,
+ physics: const NeverScrollableScrollPhysics(),
+ buildDefaultDragHandles: false,
+ proxyDecorator: (child, _, _) => Material(color: Colors.transparent, child: child),
+ onReorder: (from, to) {
+ HapticFeedback.selectionClick();
+ fit.reorderRoutines(group, from, to > from ? to - 1 : to);
+ },
+ children: [
+ for (final (i, r) in list.indexed)
+ Container(
+ key: ValueKey(r.id),
+ margin: const EdgeInsets.only(bottom: 8),
+ constraints: const BoxConstraints(minHeight: 52),
+ padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 4, 8),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),
+ child: Row(children: [
+ Expanded(
+ child: Text(fit.routineTitle(r),
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),
+ ),
+ ReorderableDragStartListener(
+ index: i,
+ child: SizedBox(
+ width: 48,
+ height: 44,
+ child: Icon(PhosphorIconsRegular.dotsSixVertical, size: 18, color: gc.textTertiary),
+ ),
+ ),
+ ]),
+ ),
+ ],
+ ),
+ ]);
+ },
+ ),
+ );
+}
diff --git a/lib/screens/start_sheet.dart b/lib/screens/start_sheet.dart
index 2302bc6..a15100a 100644
--- a/lib/screens/start_sheet.dart
+++ b/lib/screens/start_sheet.dart
@@ -83,6 +83,11 @@ class StartSheet extends StatelessWidget {
);
}
+ String _detail(Routine r) {
+ final ago = fit.daysSinceDone(r.id);
+ return [t.exerciseCount(r.exerciseIds.length), if (ago != null) t.lastDoneAgo(ago)].join(' · ');
+ }
+
Widget _label(GymColors gc, String text) => Padding(
padding: const EdgeInsets.only(left: 4, bottom: 8),
child: Text(text.toUpperCase(),
@@ -113,7 +118,9 @@ class StartSheet extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: AppTheme.f(18, weight: FontWeight.w700, color: gc.text)),
const SizedBox(height: 2),
- Text(t.exerciseCount(r.exerciseIds.length),
+ Text(_detail(r),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
style: AppTheme.f(12.5, weight: FontWeight.w500, color: gc.textSecondary)),
],
),
@@ -147,7 +154,9 @@ class StartSheet extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text)),
const SizedBox(height: 2),
- Text(t.exerciseCount(r.exerciseIds.length),
+ Text(_detail(r),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary)),
],
),
diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dart
index c8f73b5..d63c125 100644
--- a/lib/state/routines_state.dart
+++ b/lib/state/routines_state.dart
@@ -125,6 +125,13 @@ mixin RoutinesState on FitCore, LibraryState {
return last;
}
+ int? daysSinceDone(String routineId) {
+ final last = lastDoneOf(routineId);
+ if (last == null) return null;
+ final now = DateTime.now();
+ return DateTime(now.year, now.month, now.day).difference(DateTime(last.year, last.month, last.day)).inDays;
+ }
+
List<Routine> get activeRoutines => [for (final r in routines) if (!r.archived) r];
List<Routine> get archivedRoutines => [for (final r in routines) if (r.archived) r];
@@ -615,6 +622,21 @@ mixin RoutinesState on FitCore, LibraryState {
return copy;
}
+ void reorderRoutines(String group, int from, int to) {
+ final slots = [
+ for (var i = 0; i < routines.length; i++)
+ if (routines[i].group == group && !routines[i].archived) i,
+ ];
+ if (from < 0 || from >= slots.length || to < 0 || to >= slots.length || from == to) return;
+ final items = [for (final i in slots) routines[i]];
+ items.insert(to, items.removeAt(from));
+ for (var k = 0; k < slots.length; k++) {
+ routines[slots[k]] = items[k];
+ }
+ _persist();
+ notifyListeners();
+ }
+
void renameGroup(String from, String to) {
final name = to.trim();
_syncGroupNames();
diff --git a/lib/widgets/routine_folder.dart b/lib/widgets/routine_folder.dart
index 4605e19..e01b17a 100644
--- a/lib/widgets/routine_folder.dart
+++ b/lib/widgets/routine_folder.dart
@@ -45,11 +45,7 @@ class RoutineFolder extends StatelessWidget {
final back = Color.lerp(hue, Colors.black, dark ? 0.42 : 0.18)!;
final front = Color.lerp(gc.bgRaised2, hue, dark ? 0.14 : 0.3)!;
final ink = Color.lerp(hue, Colors.black, 0.35)!;
- final last = lastDone ? fit.lastDoneOf(r.id) : null;
- final now = DateTime.now();
- final ago = last == null
- ? null
- : DateTime(now.year, now.month, now.day).difference(DateTime(last.year, last.month, last.day)).inDays;
+ final ago = lastDone ? fit.daysSinceDone(r.id) : null;
return Pressable(
onTap: () => fit.openRoutine(r.id),
diff --git a/test/routine_groups_test.dart b/test/routine_groups_test.dart
index bf49929..493344e 100644
--- a/test/routine_groups_test.dart
+++ b/test/routine_groups_test.dart
@@ -96,4 +96,20 @@ void main() {
expect(fit.weeklyPlan[3], c);
expect(fit.sessions.length, 1);
});
+
+ test('#401 ordenar rutinas solo mueve las de su grupo y deja las demás en su sitio', () {
+ routineIn('A', 'PPL');
+ routineIn('X', '');
+ routineIn('B', 'PPL');
+ routineIn('C', 'PPL');
+ routineIn('Y', '');
+ fit.reorderRoutines('PPL', 2, 0);
+ expect(fit.routinesInGroup('PPL').map((r) => r.name), ['C', 'A', 'B']);
+ expect(fit.routinesInGroup('').map((r) => r.name), ['X', 'Y']);
+ fit.reorderRoutines('', 0, 1);
+ expect(fit.routinesInGroup('').map((r) => r.name), ['Y', 'X']);
+ fit.reorderRoutines('PPL', 5, 0);
+ expect(fit.routinesInGroup('PPL').map((r) => r.name), ['C', 'A', 'B']);
+ expect(fit.routines.map((r) => r.name), ['C', 'Y', 'A', 'B', 'X']);
+ });
}