Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Offer a copy when importing a routine you already have
InlitXd244892bca7b
diff --git a/lib/screens/plan_import_sheet.dart b/lib/screens/plan_import_sheet.dartindex 2a7d320..eb3096e 100644--- a/lib/screens/plan_import_sheet.dart+++ b/lib/screens/plan_import_sheet.dart@@ -110,8 +110,8 @@ class _PlanImportSheetState extends State<_PlanImportSheet> {_parse();}- void _apply() {- final result = fit.applyPlan(_plans, schedule: _schedule);+ void _apply({bool copies = false}) {+ final result = fit.applyPlan(_plans, schedule: _schedule, copies: copies);final gc = context.gc;showNotchToast(context,@@ -130,6 +130,7 @@ class _PlanImportSheetState extends State<_PlanImportSheet> {final gc = context.gc;final preview = _plans.isEmpty ? null : fit.previewPlan(_plans);final hasDays = _plans.any((p) => p.days.isNotEmpty);+ final allOwned = preview != null && preview.routines > 0 && preview.owned == preview.routines;return Container(padding: sheetPad(context).add(EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom)),constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.9),@@ -214,8 +215,26 @@ class _PlanImportSheetState extends State<_PlanImportSheet> {),),],+ if (allOwned) ...[+ const SizedBox(height: 12),+ Row(children: [+ Icon(PhosphorIconsRegular.checkCircle, size: 16, color: gc.sage),+ const SizedBox(width: 8),+ Expanded(+ child: Text(t.importAlreadyHave,+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textSecondary, height: 1.35)),+ ),+ ]),+ ],const SizedBox(height: 16),- PrimaryButton(label: t.addToMyRoutines, onTap: _apply),+ if (allOwned)+ GhostButton(+ label: t.importAsCopy,+ icon: PhosphorIconsRegular.copy,+ onTap: () => _apply(copies: true),+ )+ else+ PrimaryButton(label: t.addToMyRoutines, onTap: _apply),] else if (_text.text.trim().isNotEmpty) ...[const SizedBox(height: 16),Row(children: [@@ -293,6 +312,14 @@ class _PlanImportSheetState extends State<_PlanImportSheet> {],),),+ if (fit.ownsPlan(p)) ...[+ const SizedBox(width: 8),+ Container(+ padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 4),+ decoration: BoxDecoration(color: gc.sageSoft, borderRadius: BorderRadius.circular(100)),+ child: Text(t.importOwned, style: AppTheme.f(11, weight: FontWeight.w700, color: gc.sage)),+ ),+ ],]),);}diff --git a/lib/services/plan_share.dart b/lib/services/plan_share.dartindex 4855045..fb9f18f 100644--- a/lib/services/plan_share.dart+++ b/lib/services/plan_share.dart@@ -231,6 +231,7 @@ int _kind(Object? v) {if (s.startsWith('drop')) return 2;if (s.startsWith('fail') || s.startsWith('fallo') || s == 'amrap') return 3;if (s.startsWith('restpause') || s == 'rp') return 4;+ if (s.startsWith('cluster') || s == 'c') return 5;return 0;}diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dartindex 584a1fe..dccf93d 100644--- a/lib/state/fit_state.dart+++ b/lib/state/fit_state.dart@@ -17,6 +17,7 @@ import '../models/note.dart';import '../models/nutrition.dart';import '../models/place.dart';import '../models/profile.dart';+import '../models/progression.dart';import '../models/progress_shot.dart';import '../models/workout.dart';import '../services/alarm_store.dart';@@ -212,6 +213,7 @@ class FitState extends FitCore..clear()..addAll(((data['exSecondary'] as Map?) ?? const {}).map((k, v) => MapEntry(k as String, (v as List).whereType<String>().toList())));+ plateBar = (data['plateBar'] as num?)?.toDouble();_builtInExercises = null;bgDim = (data['bgDim'] as num?)?.toDouble() ?? 0.55;showFocus = data['showFocus'] as bool? ?? true;@@ -224,6 +226,12 @@ class FitState extends FitCoreheatmapLabels = data['heatLabels'] as bool? ?? true;hideShots = data['hideShots'] as bool? ?? false;multiPlan = data['multiPlan'] as bool? ?? false;+ savedPlans+ ..clear()+ ..addAll(((data['savedPlans'] as List?) ?? const [])+ .map((e) => SavedPlan.fromJson((e as Map).cast<String, dynamic>())));+ currentPlanId = data['planId'] as String? ?? '';+ if (!savedPlans.any((p) => p.id == currentPlanId)) currentPlanId = '';final weekStart = data['weekStart'];weekStartDay = SettingsState.weekStarts.contains(weekStart) ? weekStart as int : DateTime.monday;autoAdvance = data['autoAdvance'] as bool? ?? true;@@ -242,6 +250,10 @@ class FitState extends FitCore..clear()..addAll(((data['progress'] as Map?) ?? const {}).map((k, v) => MapEntry(k as String, (v as num).toDouble())));+ progressRules+ ..clear()+ ..addAll(((data['progressRules'] as Map?) ?? const {}).map(+ (k, v) => MapEntry(k as String, ProgressRule.fromJson(Map<String, dynamic>.from(v as Map)))));autoWarmup..clear()..addAll(((data['warmup'] as List?) ?? const []).cast<String>());@@ -444,6 +456,7 @@ class FitState extends FitCore'levelShown': Map.of(levelShown),'goals': exerciseGoals.map((k, g) => MapEntry(k, {'t': g.target, if (g.due != null) 'd': g.due!.millisecondsSinceEpoch})),'barKg': exerciseBar,+ if (plateBar != null) 'plateBar': plateBar,'marks': videoMarks.map((k, v) => MapEntry(k, v.map((i, ms) => MapEntry('$i', ms)))),'exMode': modeOverride,'exSecondary': secondaryOverride,@@ -461,6 +474,8 @@ class FitState extends FitCore'weeklyPlan': weeklyPlan.map((k, v) => MapEntry(k.toString(), v)),'planExtras': planExtras.map((k, v) => MapEntry(k.toString(), v)),'multiPlan': multiPlan,+ if (savedPlans.isNotEmpty) 'savedPlans': savedPlansLive.map((p) => p.toJson()).toList(),+ if (currentPlanId.isNotEmpty) 'planId': currentPlanId,if (rotation) 'rotation': rotation,if (rotationIds.isNotEmpty) 'rotationIds': rotationIds,if (rotationNextId.isNotEmpty) 'rotationNext': rotationNextId,@@ -469,6 +484,8 @@ class FitState extends FitCore'media': exerciseMedia,'exRest': exerciseRest,'progress': progressStep,+ if (progressRules.isNotEmpty)+ 'progressRules': progressRules.map((k, v) => MapEntry(k, v.toJson())),'warmup': autoWarmup.toList(),'repsOnly': repsOnly.toList(),'repsOnlyOff': repsOnlyOff.toList(),@@ -525,6 +542,8 @@ class FitState extends FitCoreweeklyPlan.clear();planExtras.clear();multiPlan = false;+ savedPlans.clear();+ currentPlanId = '';rotation = false;rotationIds.clear();rotationNextId = '';@@ -539,6 +558,7 @@ class FitState extends FitCoreassistedOff.clear();exerciseRest.clear();progressStep.clear();+ progressRules.clear();autoWarmup.clear();noSuggest.clear();archived.clear();@@ -548,6 +568,7 @@ class FitState extends FitCoreexerciseGoals.clear();videoMarks.clear();exerciseBar.clear();+ plateBar = null;modeOverride.clear();secondaryOverride.clear();_builtInExercises = null;@@ -852,8 +873,8 @@ class FitState extends FitCorereturn exerciseById(id);}- ({int routines, int added, List<String> missed}) previewPlan(List<PlanRoutine> plans) {- var made = 0, added = 0;+ ({int routines, int added, List<String> missed, int owned}) previewPlan(List<PlanRoutine> plans) {+ var made = 0, added = 0, owned = 0;final missed = <String>[];for (final plan in plans) {var found = 0;@@ -866,9 +887,28 @@ class FitState extends FitCore}}if (found > 0) made++;+ if (found > 0 && ownsPlan(plan)) owned++;added += found;}- return (routines: made, added: added, missed: missed);+ return (routines: made, added: added, missed: missed, owned: owned);+ }++ Routine? _ownedRoutine(PlanRoutine plan, List<String> ids) {+ final name = plan.name.isEmpty ? t.newRoutineName : plan.name;+ return routines.where((r) => _sameRoutine(r, name, ids) && r.group == plan.group).firstOrNull;+ }++ bool ownsPlan(PlanRoutine plan) {+ final ids = <String>[];+ for (final item in plan.items) {+ final ex = _planExercise(item);+ if (ex == null) {+ if ((item.muscle ?? '').isNotEmpty) return false;+ continue;+ }+ if (!ids.contains(ex.id)) ids.add(ex.id);+ }+ return ids.isNotEmpty && _ownedRoutine(plan, ids) != null;}bool _sameRoutine(Routine r, String name, List<String> ids) =>@@ -877,7 +917,7 @@ class FitState extends FitCore[for (var i = 0; i < ids.length; i++) r.exerciseIds[i] == ids[i]].every((x) => x);({int routines, int added, List<String> missed}) applyPlan(List<PlanRoutine> plans,- {bool schedule = false}) {+ {bool schedule = false, bool copies = false}) {var made = 0, added = 0;final missed = <String>[];for (final plan in plans) {@@ -893,8 +933,7 @@ class FitState extends FitCore}if (picked.isEmpty) continue;final name = plan.name.isEmpty ? t.newRoutineName : plan.name;- final ids = [for (final p in picked) p.$1.id];- final existing = routines.where((r) => _sameRoutine(r, name, ids) && r.group == plan.group).firstOrNull;+ final existing = copies ? null : _ownedRoutine(plan, [for (final p in picked) p.$1.id]);final id = existing?.id ?? createRoutine(name);if (existing == null) {setRoutineGroup(id, plan.group);@@ -948,7 +987,7 @@ class FitState extends FitCore];}- static const _kindNames = ['normal', 'warmup', 'drop', 'failure', 'restpause'];+ static const _kindNames = ['normal', 'warmup', 'drop', 'failure', 'restpause', 'cluster'];String exportPlanJson(List<Routine> list, {bool withSchedule = true}) {return encodePlan({