Skip to content

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

Archive routines you don't use

InlitXaf8e03697481
diff --git a/lib/models/workout.dart b/lib/models/workout.dart
index 7e5c280..95b248e 100644
--- a/lib/models/workout.dart
+++ b/lib/models/workout.dart
@@ -232,7 +232,8 @@ class Routine {
Map<String, List<PlannedSet>>? plan,
Map<String, int>? rest,
this.group = '',
- this.color = -1})
+ this.color = -1,
+ this.archived = false})
: sets = sets ?? {},
chained = chained ?? {},
plan = plan ?? {},
@@ -241,6 +242,7 @@ class Routine {
String name;
String group;
int color;
+ bool archived;
final List<String> exerciseIds;
final Map<String, int> sets;
final Set<String> chained;
@@ -256,6 +258,7 @@ class Routine {
if (chained.isNotEmpty) 'c': chained.toList(),
if (group.isNotEmpty) 'g': group,
if (color >= 0) 'k': color,
+ if (archived) 'a': true,
if (plan.isNotEmpty)
'p': plan.map((k, v) => MapEntry(k, v.map((s) => s.toJson()).toList())),
};
@@ -274,5 +277,6 @@ class Routine {
.map((k, v) => MapEntry(k as String, ((v as num).toInt()).clamp(0, 600))),
group: (j['g'] as String?) ?? '',
color: (j['k'] as num?)?.toInt() ?? -1,
+ archived: j['a'] == true,
);
}
diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dart
index ef25b62..5122e34 100644
--- a/lib/state/routines_state.dart
+++ b/lib/state/routines_state.dart
@@ -112,10 +112,57 @@ mixin RoutinesState on FitCore, LibraryState {
return last;
}
+ 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];
+
+ bool showArchivedRoutines = false;
+
+ void toggleArchivedRoutines() {
+ showArchivedRoutines = !showArchivedRoutines;
+ notifyListeners();
+ }
+
+ VoidCallback? archiveRoutine(String id, bool on) {
+ final r = _routine(id);
+ if (r == null || r.archived == on) return null;
+ final week = {...weeklyPlan};
+ final extras = {for (final e in planExtras.entries) e.key: [...e.value]};
+ final moves = {for (final e in planMoves.entries) e.key: [...e.value]};
+ final rotation = [...rotationIds];
+ final next = rotationNextId;
+ r.archived = on;
+ if (on) _unplanRoutine(id);
+ _persist();
+ syncTrainReminder();
+ notifyListeners();
+ if (!on) return null;
+ return () {
+ r.archived = false;
+ weeklyPlan
+ ..clear()
+ ..addAll(week);
+ planExtras
+ ..clear()
+ ..addAll(extras);
+ planMoves
+ ..clear()
+ ..addAll(moves);
+ rotationIds
+ ..clear()
+ ..addAll(rotation);
+ rotationNextId = next;
+ _persist();
+ syncTrainReminder();
+ notifyListeners();
+ };
+ }
+
List<Routine> get routinesByLastDone {
- final last = {for (final r in routines) r.id: lastDoneOf(r.id)};
- final order = {for (final (i, r) in routines.indexed) r.id: i};
- return [...routines]..sort((a, b) {
+ final active = activeRoutines;
+ final last = {for (final r in active) r.id: lastDoneOf(r.id)};
+ final order = {for (final (i, r) in active.indexed) r.id: i};
+ return [...active]..sort((a, b) {
final la = last[a.id], lb = last[b.id];
if (la != null && lb != null && la != lb) return lb.compareTo(la);
if ((la == null) != (lb == null)) return la == null ? 1 : -1;
@@ -351,14 +398,14 @@ mixin RoutinesState on FitCore, LibraryState {
List<String> get routineGroups {
final out = <String>[];
- for (final r in routines) {
+ for (final r in activeRoutines) {
if (r.group.isNotEmpty && !out.contains(r.group)) out.add(r.group);
}
return out;
}
List<Routine> routinesInGroup(String group) =>
- routines.where((r) => r.group == group).toList();
+ routines.where((r) => r.group == group && !r.archived).toList();
void setRoutineGroup(String id, String group) {
final r = _routine(id);
@@ -417,12 +464,20 @@ mixin RoutinesState on FitCore, LibraryState {
}
void _dropRoutine(String id) {
+ _unplanRoutine(id);
+ routines.removeWhere((r) => r.id == id);
+ _fixRotationNext();
+ for (final p in savedPlans) {
+ p.drop(id);
+ }
+ }
+
+ void _unplanRoutine(String id) {
final i = rotationIds.indexOf(id);
if (i >= 0) {
if (rotationNextId == id) rotationNextId = rotationIds[(i + 1) % rotationIds.length];
rotationIds.removeAt(i);
}
- routines.removeWhere((r) => r.id == id);
_fixRotationNext();
weeklyPlan.removeWhere((_, v) => v == id);
for (final extras in planExtras.values) {
@@ -438,9 +493,6 @@ mixin RoutinesState on FitCore, LibraryState {
weeklyPlan[day] = extras.removeAt(0);
if (extras.isEmpty) planExtras.remove(day);
}
- for (final p in savedPlans) {
- p.drop(id);
- }
if (activeRoutineId == id) activeRoutineId = null;
}