Skip to content

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

Improve plan sharing and PDF export

InlitX4691db677862
diff --git a/lib/services/plan_pdf.dart b/lib/services/plan_pdf.dart
index 57aa01a..7cb77d7 100644
--- a/lib/services/plan_pdf.dart
+++ b/lib/services/plan_pdf.dart
@@ -446,7 +446,7 @@ class _PlanDoc {
else if (timed && p.sec != null)
durationLabel(p.sec!)
else if (p.reps != null)
- '${p.reps}',
+ p.repsLabel!,
]);
final kgs = [for (final p in planned) if (p.weightKg != null && p.weightKg! > 0) p.weightKg!];
String weight;
diff --git a/lib/services/plan_share.dart b/lib/services/plan_share.dart
index dc5b56f..72d9983 100644
--- a/lib/services/plan_share.dart
+++ b/lib/services/plan_share.dart
@@ -1,8 +1,9 @@
import 'dart:convert';
class PlanSet {
- const PlanSet({this.reps, this.weightKg, this.kind = 0, this.sec, this.km});
+ const PlanSet({this.reps, this.repsMax, this.weightKg, this.kind = 0, this.sec, this.km});
final int? reps;
+ final int? repsMax;
final double? weightKg;
final int kind;
final int? sec;
@@ -15,6 +16,7 @@ class PlanItem {
this.sets, {
this.id,
this.reps,
+ this.repsMax,
this.weightKg,
this.restSec,
this.superset = false,
@@ -33,6 +35,7 @@ class PlanItem {
final int? sets;
final String? id;
final int? reps;
+ final int? repsMax;
final double? weightKg;
final int? restSec;
final bool superset;
@@ -64,6 +67,7 @@ const _weekKeys = ['weeks', 'semanas', 'mesocycle', 'blocks'];
const _dayKeys = ['days', 'dias', 'weekdays', 'schedule', 'on'];
const _setKeys = ['sets', 'series', 'setcount'];
const _repKeys = ['reps', 'repetitions', 'repeticiones', 'rep', 'repeticoes', 'ripetizioni'];
+const _repMaxKeys = ['repsmax', 'maxreps', 'repmax', 'maxrep', 'repsto', 'repsmaximum'];
const _weightKeys = ['weight', 'weightkg', 'load', 'kg', 'peso', 'carga', 'lbs', 'lb'];
const _restKeys = ['rest', 'restseconds', 'restsec', 'descanso', 'pause', 'riposo'];
const _timeKeys = ['time', 'duration', 'seconds', 'sec', 'secs', 'tiempo', 'durationseconds'];
@@ -176,6 +180,14 @@ List<String> _candidates(String raw) {
String _norm(Object? key) => key.toString().toLowerCase().replaceAll(RegExp(r'[^a-z]'), '');
+int? _repsMax(Map<Object?, Object?> map, int? low) {
+ final explicit = _int(_value(map, _repMaxKeys));
+ final raw = _value(map, _repKeys);
+ final fromText = raw is String ? RegExp(r'(\d+)\s*(?:-|–|—|to|a)\s*(\d+)').firstMatch(raw)?.group(2) : null;
+ final max = explicit ?? (fromText == null ? null : int.parse(fromText));
+ return max != null && low != null && max > low ? max : null;
+}
+
Object? _value(Map<Object?, Object?> map, List<String> keys) {
for (final key in keys) {
for (final entry in map.entries) {
@@ -276,6 +288,7 @@ List<PlanSet> _planSets(Object? raw, bool lb) {
if (s is! Map<Object?, Object?>) continue;
out.add(PlanSet(
reps: _int(_value(s, _repKeys)),
+ repsMax: _repsMax(s, _int(_value(s, _repKeys))),
weightKg: _weight(_value(s, _weightKeys), lb || _value(s, ['lbs', 'lb']) != null),
kind: _kind(_value(s, ['type', 'kind', 'tipo', 'settype'])),
sec: _seconds(_value(s, _timeKeys)),
@@ -307,10 +320,11 @@ List<PlanItem> _items(Object? raw, bool lb) {
_int(_value(entry, _setKeys)),
id: id.isEmpty ? null : id,
reps: _int(_value(entry, _repKeys)),
+ repsMax: _repsMax(entry, _int(_value(entry, _repKeys))),
weightKg: _weight(_value(entry, _weightKeys), itemLb),
restSec: _seconds(_value(entry, _restKeys)),
superset: superset == true || (superset is String && superset.toLowerCase() == 'true'),
- plan: _planSets(_value(entry, ['plan', 'setplan', 'setsplan', 'detail']), itemLb),
+ plan: _planSets(_value(entry, ['plan', 'setplan', 'setsplan', 'detail']) ?? (_value(entry, _setKeys) is List ? _value(entry, _setKeys) : null), itemLb),
muscle: _string(_value(info, ['muscle', 'primary', 'musculo'])),
equipment: _string(_value(info, ['equipment', 'material', 'gear'])),
level: _string(_value(info, ['level', 'difficulty', 'nivel'])),
@@ -336,12 +350,22 @@ List<PlanSet> _expanded(PlanItem item) {
final working = item.plan.where((p) => p.kind != 1).length;
return [
for (final p in item.plan)
- PlanSet(reps: p.reps ?? item.reps, weightKg: p.weightKg ?? item.weightKg, kind: p.kind, sec: p.sec ?? item.sec, km: p.km ?? item.km),
+ PlanSet(
+ reps: p.reps ?? item.reps,
+ repsMax: p.reps == null ? item.repsMax : p.repsMax,
+ weightKg: p.weightKg ?? item.weightKg,
+ kind: p.kind,
+ sec: p.sec ?? item.sec,
+ km: p.km ?? item.km,
+ ),
for (var i = working; i < (item.sets ?? working); i++)
- PlanSet(reps: item.reps, weightKg: item.weightKg, sec: item.sec, km: item.km),
+ PlanSet(reps: item.reps, repsMax: item.repsMax, weightKg: item.weightKg, sec: item.sec, km: item.km),
];
}
- return [for (var i = 0; i < (item.sets ?? 1); i++) PlanSet(reps: item.reps, weightKg: item.weightKg, sec: item.sec, km: item.km)];
+ return [
+ for (var i = 0; i < (item.sets ?? 1); i++)
+ PlanSet(reps: item.reps, repsMax: item.repsMax, weightKg: item.weightKg, sec: item.sec, km: item.km),
+ ];
}
List<PlanItem> _mergeRepeats(List<PlanItem> items) {
@@ -362,6 +386,7 @@ List<PlanItem> _mergeRepeats(List<PlanItem> items) {
plan.where((p) => p.kind != 1).length,
id: first.id,
reps: first.reps ?? item.reps,
+ repsMax: first.repsMax ?? item.repsMax,
weightKg: first.weightKg ?? item.weightKg,
restSec: first.restSec ?? item.restSec,
superset: first.superset || item.superset,
diff --git a/test/plan_share_test.dart b/test/plan_share_test.dart
index 69a2213..d98a0c6 100644
--- a/test/plan_share_test.dart
+++ b/test/plan_share_test.dart
@@ -1,4 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/models/workout.dart';
import 'package:gymmane/services/plan_share.dart';
import 'package:gymmane/state/fit_state.dart';
@@ -96,6 +97,28 @@ void main() {
expect(hold.every((p) => p.sec == 45 && p.km == null), isTrue);
});
+ test('sets como lista de series con sus propias repeticiones y peso', () {
+ fit.importPlan('{"name":"X","exercises":[{"name":"Barbell Bent Over Row","sets":[{"reps":12,"weight":50},{"reps":12,"weight":50},{"reps":10,"weight":45},{"reps":8,"weight":40}]}]}');
+ final routine = fit.routines.single;
+ final sets = fit.plannedSets(routine, routine.exerciseIds.single);
+ expect(sets.map((s) => s.reps).toList(), [12, 12, 10, 8]);
+ expect(sets.map((s) => s.weightKg).toList(), [50, 50, 45, 40]);
+ });
+
+ test('rangos de repeticiones: texto, campo aparte y ida y vuelta', () {
+ fit.importPlan('{"name":"X","exercises":[{"name":"Barbell Bent Over Row","sets":3,"reps":"8-12"},{"name":"Dumbbell Biceps Curl","sets":2,"reps":10,"repsMax":15}]}');
+ final routine = fit.routines.single;
+ final row = fit.plannedSets(routine, routine.exerciseIds[0]);
+ expect(row.map((s) => s.repsLabel).toList(), ['8-12', '8-12', '8-12']);
+ final curl = fit.plannedSets(routine, routine.exerciseIds[1]);
+ expect(curl.first.reps, 10);
+ expect(curl.first.repsMax, 15);
+ expect(PlannedSet.fromJson(curl.first.toJson()).repsLabel, '10-15');
+ expect(const PlannedSet(reps: 10, repsMax: 8).repsLabel, '10');
+ final again = parsePlan(fit.exportPlanJson(fit.routines));
+ expect(again.single.items.first.plan.first.repsMax, 12);
+ });
+
test('un ejercicio solo con tiempo no se pierde como si no tuviera datos', () {
fit.importPlan('{"name":"X","exercises":[{"name":"Treadmill Run","time":600}]}');
final routine = fit.routines.single;