Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Let routine groups collapse and move up or down
InlitX14ee41814b46
diff --git a/lib/screens/routines_screen.dart b/lib/screens/routines_screen.dartindex edbb50c..f66dd5e 100644--- a/lib/screens/routines_screen.dart+++ b/lib/screens/routines_screen.dart@@ -152,10 +152,10 @@ class RoutinesScreen extends StatelessWidget {)else ...[for (final group in fit.routineGroups) ...[- _groupHeader(context, gc, group, fit.routinesInGroup(group).length),- _folders(context, fit.routinesInGroup(group)),- const SizedBox(height: 10),+ _groupBlock(context, gc, group),+ const SizedBox(height: 12),],+ if (fit.routineGroups.isNotEmpty && fit.routinesInGroup('').isNotEmpty) const SizedBox(height: 6),_folders(context, fit.routinesInGroup('')),],if (fit.archivedRoutines.isNotEmpty) ...[@@ -978,32 +978,80 @@ class RoutinesScreen extends StatelessWidget {);}- Widget _groupHeader(BuildContext context, GymColors gc, String name, int count) {- return Semantics(- button: true,- label: name,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => _groupMenu(context, name, count),- child: Padding(- padding: const EdgeInsets.only(bottom: 8, left: 4, top: 4),- child: Row(- children: [- Icon(PhosphorIconsRegular.folderSimple, size: 15, color: gc.brass),- const SizedBox(width: 8),- Expanded(- child: Text(name,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: AppTheme.f(13, weight: FontWeight.w700, color: gc.text, letterSpacing: 1)),+ Widget _groupBlock(BuildContext context, GymColors gc, String name) {+ final list = fit.routinesInGroup(name);+ final open = !fit.collapsedGroups.contains(name);+ return SoftCard(+ color: Colors.transparent,+ radius: 26,+ padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ _groupHeader(context, gc, name, list.length, open),+ AnimatedSize(+ duration: const Duration(milliseconds: 340),+ curve: Curves.easeOutCubic,+ alignment: Alignment.topCenter,+ child: open+ ? Padding(padding: const EdgeInsets.only(top: 2), child: _folders(context, list))+ : const SizedBox(width: double.infinity),+ ),+ ],+ ),+ );+ }++ Widget _groupHeader(BuildContext context, GymColors gc, String name, int count, bool open) {+ return Row(+ children: [+ Expanded(+ child: Semantics(+ button: true,+ expanded: open,+ label: name,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => fit.toggleGroupCollapsed(name),+ child: Padding(+ padding: const EdgeInsets.fromLTRB(4, 14, 0, 14),+ child: Row(+ children: [+ Icon(PhosphorIconsRegular.folderSimple, size: 15, color: gc.brass),+ const SizedBox(width: 8),+ Flexible(+ child: Text(name,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(13, weight: FontWeight.w700, color: gc.text, letterSpacing: 1)),+ ),+ const SizedBox(width: 8),+ Text('$count', style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary)),+ const SizedBox(width: 6),+ AnimatedRotation(+ turns: open ? 0.5 : 0,+ duration: const Duration(milliseconds: 200),+ child: Icon(PhosphorIconsBold.caretDown, size: 13, color: gc.textTertiary),+ ),+ ],+ ),),- Text('$count', style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary)),- const SizedBox(width: 6),- Icon(PhosphorIconsBold.dotsThree, size: 18, color: gc.textTertiary),- ],+ ),),),- ),+ Semantics(+ button: true,+ label: t.moreOptions,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => _groupMenu(context, name, count),+ child: Padding(+ padding: const EdgeInsets.fromLTRB(12, 14, 6, 14),+ child: Icon(PhosphorIconsBold.dotsThree, size: 18, color: gc.textTertiary),+ ),+ ),+ ),+ ],);}@@ -1024,6 +1072,16 @@ class RoutinesScreen extends StatelessWidget {SheetTitle(name, subtitle: t.routineCount(count)),const SizedBox(height: 14),OptionGroup([+ if (fit.routineGroups.indexOf(name) > 0)+ OptionItem(t.groupMoveUp, icon: PhosphorIconsRegular.arrowUp, onTap: () {+ Navigator.pop(sheet);+ fit.moveGroup(name, -1);+ }),+ if (fit.routineGroups.indexOf(name) < fit.routineGroups.length - 1)+ OptionItem(t.groupMoveDown, icon: PhosphorIconsRegular.arrowDown, onTap: () {+ Navigator.pop(sheet);+ fit.moveGroup(name, 1);+ }),OptionItem(t.groupRename, icon: PhosphorIconsRegular.pencilSimple, onTap: () async {Navigator.pop(sheet);final next = await askText(context, title: t.groupRename, initial: name, hint: t.groupNameHint);diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dartindex 4690a65..98ae930 100644--- a/lib/state/fit_state.dart+++ b/lib/state/fit_state.dart@@ -419,6 +419,9 @@ class FitState extends FitCore}void _loadExerciseUnits(Map<String, dynamic> data) {+ collapsedGroups+ ..clear()+ ..addAll(((data['collapsedGroups'] as List?) ?? const []).whereType<String>());exerciseUnits.clear();((data['exUnits'] as Map?) ?? const {}).forEach((k, v) {if (k is String && (v == 'kg' || v == 'lb')) exerciseUnits[k] = v as String;@@ -621,6 +624,7 @@ class FitState extends FitCore'media': exerciseMedia,'exRest': exerciseRest,if (exerciseUnits.isNotEmpty) 'exUnits': exerciseUnits,+ if (collapsedGroups.isNotEmpty) 'collapsedGroups': collapsedGroups.toList(),'progress': progressStep,if (holdStep.isNotEmpty) 'holdStep': holdStep,if (progressRules.isNotEmpty)@@ -737,6 +741,7 @@ class FitState extends FitCoreassistedOff.clear();exerciseRest.clear();exerciseUnits.clear();+ collapsedGroups.clear();progressStep.clear();holdStep.clear();progressRules.clear();diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dartindex 8be68c2..c9da293 100644--- a/lib/state/routines_state.dart+++ b/lib/state/routines_state.dart@@ -131,6 +131,32 @@ mixin RoutinesState on FitCore, LibraryState {bool showArchivedRoutines = false;+ final Set<String> collapsedGroups = {};++ void toggleGroupCollapsed(String group) {+ if (!collapsedGroups.remove(group)) collapsedGroups.add(group);+ _persist();+ notifyListeners();+ }++ void moveGroup(String group, int by) {+ final order = routineGroups;+ final from = order.indexOf(group);+ final to = from + by;+ if (from < 0 || to < 0 || to >= order.length) return;+ order.insert(to, order.removeAt(from));+ final rank = {for (var i = 0; i < order.length; i++) order[i]: i};+ final grouped = [for (final r in routines) if (rank.containsKey(r.group)) r]+ ..sort((a, b) => rank[a.group]!.compareTo(rank[b.group]!));+ final rest = [for (final r in routines) if (!rank.containsKey(r.group)) r];+ routines+ ..clear()+ ..addAll(grouped)+ ..addAll(rest);+ _persist();+ notifyListeners();+ }+void toggleArchivedRoutines() {showArchivedRoutines = !showArchivedRoutines;notifyListeners();@@ -561,6 +587,7 @@ mixin RoutinesState on FitCore, LibraryState {for (final r in routines) {if (r.group == from) r.group = name;}+ if (collapsedGroups.remove(from) && name.isNotEmpty) collapsedGroups.add(name);_persist();notifyListeners();}diff --git a/test/routine_groups_test.dart b/test/routine_groups_test.dartindex 908ee0d..039c7c7 100644--- a/test/routine_groups_test.dart+++ b/test/routine_groups_test.dart@@ -36,6 +36,31 @@ void main() {expect(fit.routines.length, 2);});+ test('subir y bajar un grupo cambia el orden y deja las sueltas al final', () {+ routineIn('A', '5x5');+ final loose = fit.createRoutine('Suelta');+ routineIn('C', 'PPL');+ routineIn('D', 'Upper');+ fit.moveGroup('Upper', -1);+ expect(fit.routineGroups, ['5x5', 'Upper', 'PPL']);+ fit.moveGroup('5x5', 1);+ expect(fit.routineGroups, ['Upper', '5x5', 'PPL']);+ fit.moveGroup('PPL', 1);+ expect(fit.routineGroups, ['Upper', '5x5', 'PPL']);+ expect(fit.routines.last.id, loose);+ });++ test('plegar un grupo se guarda, sobrevive al cambio de nombre y va en la copia', () {+ routineIn('A', '5x5');+ fit.toggleGroupCollapsed('5x5');+ expect(fit.collapsedGroups, {'5x5'});+ fit.renameGroup('5x5', 'Fuerza');+ expect(fit.collapsedGroups, {'Fuerza'});+ expect(fit.toJson()['collapsedGroups'], ['Fuerza']);+ fit.toggleGroupCollapsed('Fuerza');+ expect(fit.toJson().containsKey('collapsedGroups'), isFalse);+ });+test('borrar el grupo borra sus rutinas, su plan y nada más', () {final a = routineIn('A', '5x5');routineIn('B', '5x5');