Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Choose the first day of the week and count bodyweight work in records, activity and streaks
InlitX7361b04d97ae
diff --git a/lib/models/workout.dart b/lib/models/workout.dartindex f8c1a7f..57c1cf1 100644--- a/lib/models/workout.dart+++ b/lib/models/workout.dart@@ -52,6 +52,22 @@ class LoggedSet {);}+enum PrKind {+ weight,+ distance,+ time,+ reps;++ double score(LoggedSet s) => switch (this) {+ PrKind.weight => s.weight,+ PrKind.distance => s.km ?? 0,+ PrKind.time => (s.sec ?? 0).toDouble(),+ PrKind.reps => s.reps.toDouble(),+ };+}++typedef PersonalRecord = ({String id, String name, PrKind kind, double best, double oneRm});+class LoggedExercise {LoggedExercise(this.id, this.name, this.primary, this.sets);final String id;diff --git a/lib/screens/progress_screen.dart b/lib/screens/progress_screen.dartindex ff91068..8f33ec4 100644--- a/lib/screens/progress_screen.dart+++ b/lib/screens/progress_screen.dart@@ -120,9 +120,7 @@ class ProgressScreen extends StatelessWidget {children: [Row(children: [Expanded(- child: Text(label.toUpperCase(),- maxLines: 1,- overflow: TextOverflow.ellipsis,+ child: FitText(label.toUpperCase(),style: AppTheme.f(10,weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 0.9)),),@@ -268,7 +266,7 @@ class ProgressScreen extends StatelessWidget {Text(t.streakDays(fit.currentStreak),style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.text)),const Spacer(),- Text(t.weekOfGoal(fit.sessionsThisWeek, fit.weeklyTarget),+ Text(t.weekOfGoal(fit.daysDoneThisWeek, fit.weeklyTarget),style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary)),]),],@@ -364,7 +362,7 @@ class ProgressScreen extends StatelessWidget {for (var i = 0; i < 7; i++) ...[Expanded(child: Text(- t.weekdayInitial((t.firstWeekday - 1 + i) % 7 + 1),+ t.weekdayInitial(fit.weekdayAt(i)),textAlign: TextAlign.center,style: AppTheme.f(11,weight: i == todayIndex ? FontWeight.w700 : FontWeight.w500,@@ -453,7 +451,7 @@ class ProgressScreen extends StatelessWidget {GymColors gc,List<double> bw,List<({String name, int pct})> split,- List<({String id, String name, double topWeight, double oneRm})> prs,+ List<PersonalRecord> prs,) {return [if (fit.sessions.isNotEmpty) _thisWeek(gc),@@ -1136,7 +1134,7 @@ class _PrThumb extends StatelessWidget {class _PrCard extends StatefulWidget {const _PrCard(this.prs);- final List<({String id, String name, double topWeight, double oneRm})> prs;+ final List<PersonalRecord> prs;@overrideState<_PrCard> createState() => _PrCardState();@@ -1205,7 +1203,7 @@ class _PrCardState extends State<_PrCard> {);}- Widget _row(GymColors gc, ({String id, String name, double topWeight, double oneRm}) pr, int rank, bool border) {+ Widget _row(GymColors gc, PersonalRecord pr, int rank, bool border) {final medal = rank < 3 ? [gc.brass, gc.textSecondary, gc.accent][rank] : null;return Container(padding: const EdgeInsets.symmetric(vertical: 11),@@ -1246,13 +1244,13 @@ class _PrCardState extends State<_PrCard> {overflow: TextOverflow.ellipsis,style: AppTheme.s(14, weight: FontWeight.w600, color: gc.text, height: 1.25)),const SizedBox(height: 3),- Text(t.oneRmEst(fit.weightLabel(pr.oneRm)),+ Text(fit.recordDetail(pr),style: AppTheme.s(11.5, weight: FontWeight.w500, color: gc.textTertiary)),],),),const SizedBox(width: 12),- Text(fit.weightLabel(pr.topWeight), style: AppTheme.d(19, weight: FontWeight.w800, color: gc.text)),+ Text(fit.recordLabel(pr), style: AppTheme.d(19, weight: FontWeight.w800, color: gc.text)),],),);diff --git a/lib/state/fit_core.dart b/lib/state/fit_core.dartindex 10eeb3a..cc920bd 100644--- a/lib/state/fit_core.dart+++ b/lib/state/fit_core.dart@@ -46,6 +46,8 @@ abstract class FitCore extends ChangeNotifier {final Set<String> checkins = {};final List<Routine> routines = [];final Map<int, String> weeklyPlan = {};+ final Map<int, List<String>> planExtras = {};+ bool multiPlan = false;final List<Exercise> customExercises = [];final List<GymPlace> places = [];@@ -63,6 +65,10 @@ abstract class FitCore extends ChangeNotifier {final Set<String> noSuggest = {};+ final Set<String> archived = {};++ final Map<String, Map<int, int>> videoMarks = {};+final Map<String, String> modeOverride = {};VoidCallback? onWidgetsShouldUpdate;@@ -81,6 +87,7 @@ abstract class FitCore extends ChangeNotifier {double? get placeBarKg => null;String units = 'kg';+ int weekStartDay = DateTime.monday;bool _loading = false;Timer? _saveDebounce;diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dartindex 972f9c0..e380986 100644--- a/lib/state/fit_state.dart+++ b/lib/state/fit_state.dart@@ -89,6 +89,7 @@ class FitState extends FitCore..clear()..addAll(((data['weeklyPlan'] as Map?) ?? {}).map((k, v) => MapEntry(int.parse(k as String), v as String)));+ _loadPlanExtras(data);customExercises..clear()..addAll(((data['custom'] as List?) ?? [])@@ -154,12 +155,25 @@ class FitState extends FitCorenoSuggest..clear()..addAll(((data['noSuggest'] as List?) ?? const []).cast<String>());+ archived+ ..clear()+ ..addAll(((data['archived'] as List?) ?? const []).cast<String>());+ videoMarks+ ..clear()+ ..addAll(((data['marks'] as Map?) ?? const {}).map((k, v) => MapEntry(+ k as String,+ (v as Map).map((i, ms) => MapEntry(int.parse(i as String), (ms as num).toInt())),+ )));modeOverride..clear()..addAll(((data['exMode'] as Map?) ?? const {}).map((k, v) => MapEntry(k as String, v as String))..removeWhere((_, v) => !const ['weight', 'cardio', 'time'].contains(v)));bgDim = (data['bgDim'] as num?)?.toDouble() ?? 0.55;showFocus = data['showFocus'] as bool? ?? true;+ showRecommended = data['showRecs'] as bool? ?? true;+ multiPlan = data['multiPlan'] as bool? ?? false;+ final weekStart = data['weekStart'];+ weekStartDay = SettingsState.weekStarts.contains(weekStart) ? weekStart as int : DateTime.monday;autoAdvance = data['autoAdvance'] as bool? ?? true;keepScreenOn = data['keepAwake'] as bool? ?? true;startCountdown = data['countdown'] as bool? ?? true;@@ -177,6 +191,16 @@ class FitState extends FitCore..addAll(((data['warmup'] as List?) ?? const []).cast<String>());}+ void _loadPlanExtras(Map<String, dynamic> data) {+ planExtras+ ..clear()+ ..addAll(((data['planExtras'] as Map?) ?? const {}).map((k, v) => MapEntry(+ int.parse(k as String),+ (v as List).cast<String>().where((id) => id != weeklyPlan[int.parse(k)]).toList(),+ )))+ ..removeWhere((_, v) => v.isEmpty);+ }+void _restoreLiveSession(Map<String, dynamic> data) {final live = data['live'] as Map?;if (live == null) return;@@ -315,6 +339,8 @@ class FitState extends FitCore'heatTone': heatTone,'bgDim': bgDim,'showFocus': showFocus,+ 'showRecs': showRecommended,+ 'weekStart': weekStartDay,'autoAdvance': autoAdvance,'keepAwake': keepScreenOn,'countdown': startCountdown,@@ -324,6 +350,8 @@ class FitState extends FitCore'demo': demoSize,'alarmStyle': alarmStyle,'noSuggest': noSuggest.toList(),+ 'archived': archived.toList(),+ 'marks': videoMarks.map((k, v) => MapEntry(k, v.map((i, ms) => MapEntry('$i', ms)))),'exMode': modeOverride,'trainAt': trainReminderMin,'trainSmart': smartReminder,@@ -336,6 +364,8 @@ class FitState extends FitCore'checkins': checkins.toList(),'routines': routines.map((r) => r.toJson()).toList(),'weeklyPlan': weeklyPlan.map((k, v) => MapEntry(k.toString(), v)),+ 'planExtras': planExtras.map((k, v) => MapEntry(k.toString(), v)),+ 'multiPlan': multiPlan,'custom': customExercises.map((e) => e.toJson()).toList(),'media': exerciseMedia,'exRest': exerciseRest,@@ -386,6 +416,8 @@ class FitState extends FitCorecheckins.clear();routines.clear();weeklyPlan.clear();+ planExtras.clear();+ multiPlan = false;customExercises.clear();exerciseMedia.clear();repsOnly.clear();@@ -394,6 +426,8 @@ class FitState extends FitCoreprogressStep.clear();autoWarmup.clear();noSuggest.clear();+ archived.clear();+ videoMarks.clear();modeOverride.clear();demoSize = 'large';MediaStore.clearAll();@@ -402,6 +436,8 @@ class FitState extends FitCoreselectedMuscles.clear();profile = Profile();showFocus = true;+ showRecommended = true;+ weekStartDay = DateTime.monday;autoAdvance = true;startCountdown = true;gamification = true;@@ -466,6 +502,7 @@ class FitState extends FitCore..clear()..addAll(((map['weeklyPlan'] as Map?) ?? {}).map((k, v) => MapEntry(int.parse(k as String), v as String)));+ _loadPlanExtras(map);customExercises..clear()..addAll(((map['custom'] as List?) ?? [])@@ -615,9 +652,19 @@ class FitState extends FitCore']}';String planRequestText() {- final here = allExercises.where(fitsHere).toList();+ final here = allExercises.where((e) => fitsHere(e) && !isArchived(e.id)).toList();+ final month = DateTime.now().subtract(const Duration(days: 30));+ final recent = sessions.where((s) => s.date.isAfter(month)).length;+ final records = personalRecords.take(5).toList();final lines = <String>['GymMane · ${activePlace?.name ?? t.placeAll}',+ t.planAboutMe,+ '- ${t.planBody(profile.sex == 'female' ? t.female : t.male, profile.age, heightLabel(profile.heightCm), weightLabel(profile.weightKg))}',+ '- ${t.planDays(weeklyTarget)}',+ if (sessions.isEmpty) '- ${t.planNoHistory}' else '- ${t.planHistory(recent)}',+ if (records.isNotEmpty) '- ${t.planBestLifts}: ${records.map((r) => '${r.name} ${recordLabel(r)}').join('; ')}',+ t.planAskFirst,+ '',t.planIntro,t.planFormat,planTemplate,@@ -764,7 +811,7 @@ class FitState extends FitCore'name': routineTitle(r),if (r.group.isNotEmpty) 'group': r.group,if (withSchedule)- 'days': [for (var d = 1; d <= 7; d++) if (weeklyPlan[d] == r.id) d],+ 'days': [for (var d = 1; d <= 7; d++) if (plannedOn(d, r.id)) d],'exercises': [for (final id in r.exerciseIds)if (exerciseById(id) case final ex?)@@ -803,7 +850,7 @@ class FitState extends FitCoreString planSummaryText(List<Routine> list) {final out = <String>[];for (final r in list) {- final days = [for (var d = 1; d <= 7; d++) if (weeklyPlan[d] == r.id) t.weekdayShort(d)];+ final days = [for (var d = 1; d <= 7; d++) if (plannedOn(d, r.id)) t.weekdayShort(d)];out.add(days.isEmpty ? routineTitle(r) : '${routineTitle(r)} · ${days.join(', ')}');for (final id in r.exerciseIds) {final ex = exerciseById(id);diff --git a/lib/state/stats_state.dart b/lib/state/stats_state.dartindex 3bb048c..4328833 100644--- a/lib/state/stats_state.dart+++ b/lib/state/stats_state.dart@@ -3,7 +3,7 @@ part of 'fit_state.dart';mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {List<Exercise> recommendedExercises(int n) {final muscles = suggestedFocus.muscles;- final pool = kExercises.where((e) => !noSuggest.contains(e.id));+ final pool = kExercises.where((e) => !noSuggest.contains(e.id) && !isArchived(e.id) && fitsHere(e));final picks = [for (final m in muscles) ...pool.where((e) => e.primary == m).take(1),];@@ -35,14 +35,13 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {notifyListeners();}- int get todayIndex => DateTime.now().weekday - 1;+ int get todayIndex => (DateTime.now().weekday - weekStartDay + 7) % 7;++ int weekdayAt(int i) => (weekStartDay - 1 + i) % 7 + 1;DateTime get weekStartDate => _weekStart;- DateTime get _weekStart {- final t = _dayKey(DateTime.now());- return shiftDays(t, 1 - t.weekday);- }+ DateTime get _weekStart => shiftDays(_dayKey(DateTime.now()), -todayIndex);Iterable<LoggedSession> get _thisWeekSessions {final start = _weekStart;@@ -173,7 +172,13 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {List<int> get heatmapLevels => heatmapLevelsFor(kHeatmapDays);List<int> heatmapLevelsFor(int days) {- final daily = _dailyVolumes(days);+ final load = <DateTime, double>{for (final d in _checkinDays) d: 1};+ for (final s in sessions) {+ final k = _dayKey(s.date);+ load[k] = (load[k] ?? 0) + math.max(1, s.setCount);+ }+ final today = _dayKey(DateTime.now());+ final daily = List.generate(days, (i) => load[shiftDays(today, i - (days - 1))] ?? 0.0);final maxV = daily.fold(0.0, (m, v) => v > m ? v : m);if (maxV <= 0) return List.filled(days, 0);return daily.map((v) => heatLevel(v / maxV)).toList();@@ -284,24 +289,29 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {);}- int get currentStreak {- final days = sessions.map((s) => _dayKey(s.date)).toSet();+ Iterable<DateTime> get _checkinDays sync* {for (final id in checkins) {final p = id.split('-');- if (p.length == 3) {- final y = int.tryParse(p[0]), m = int.tryParse(p[1]), d = int.tryParse(p[2]);- if (y != null && m != null && d != null) days.add(DateTime(y, m, d));- }+ if (p.length != 3) continue;+ final y = int.tryParse(p[0]), m = int.tryParse(p[1]), d = int.tryParse(p[2]);+ if (y != null && m != null && d != null) yield DateTime(y, m, d);}+ }++ int get currentStreak {+ final days = {...sessions.map((s) => _dayKey(s.date)), ..._checkinDays};if (days.isEmpty) return 0;+ final first = days.reduce((a, b) => a.isBefore(b) ? a : b);+ bool rest(DateTime d) => weeklyPlan.isNotEmpty && !weeklyPlan.containsKey(d.weekday);var cursor = _dayKey(DateTime.now());- if (!days.contains(cursor)) {- cursor = shiftDays(cursor, -1);- if (!days.contains(cursor)) return 0;- }+ if (!days.contains(cursor)) cursor = shiftDays(cursor, -1);var n = 0;- while (days.contains(cursor)) {- n++;+ while (!cursor.isBefore(first)) {+ if (days.contains(cursor)) {+ n++;+ } else if (!rest(cursor)) {+ break;+ }cursor = shiftDays(cursor, -1);}return n;@@ -360,35 +370,60 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {int get weeklyTarget => profile.weeklyGoal <= 0 ? 4 : profile.weeklyGoal;- int get goalPct => ((sessionsThisWeek / weeklyTarget) * 100).round().clamp(0, 100);+ int get daysDoneThisWeek => [for (var i = 0; i < 7; i++) isDayDone(i)].where((d) => d).length;++ int get goalPct => ((daysDoneThisWeek / weeklyTarget) * 100).round().clamp(0, 100);- List<({String id, String name, double topWeight, double oneRm})> get personalRecords {- final best = <String, ({String id, String name, double topWeight, double oneRm})>{};+ PersonalRecord _record(String id, String name, List<LoggedSet> sets) {+ double top(double Function(LoggedSet) f) => sets.fold(0.0, (m, s) => math.max(m, f(s)));+ final kind = PrKind.values.firstWhere((k) => top(k.score) > 0, orElse: () => PrKind.reps);+ return (id: id, name: name, kind: kind, best: top(kind.score), oneRm: top((s) => s.oneRm));+ }++ List<PersonalRecord> get personalRecords {+ final sets = <String, List<LoggedSet>>{};+ final names = <String, String>{};for (final s in sessions) {for (final e in s.exercises) {- for (final st in e.workingSets) {- final c = best[e.id];- best[e.id] = (- id: e.id,- name: e.name,- topWeight: c == null ? st.weight : math.max(c.topWeight, st.weight),- oneRm: c == null ? st.oneRm : math.max(c.oneRm, st.oneRm),- );- }+ (sets[e.id] ??= []).addAll(e.workingSets);+ names[e.id] = e.name;}}- final list = best.values.toList()..sort((a, b) => b.oneRm.compareTo(a.oneRm));- return list;+ return [+ for (final e in sets.entries)+ if (e.value.isNotEmpty) _record(e.key, names[e.key]!, e.value),+ ]..sort((a, b) => a.kind != b.kind+ ? a.kind.index.compareTo(b.kind.index)+ : (a.kind == PrKind.weight ? b.oneRm.compareTo(a.oneRm) : b.best.compareTo(a.best)));+ }++ PersonalRecord? exerciseRecord(String id) {+ final sets = [for (final h in exerciseHistory(id)) ...h.ex.workingSets];+ return sets.isEmpty ? null : _record(id, '', sets);}+ String recordLabel(PersonalRecord r) => switch (r.kind) {+ PrKind.weight => weightLabel(r.best),+ PrKind.distance => distanceLabel(r.best),+ PrKind.time => durationLabel(r.best.round()),+ PrKind.reps => t.repCount(r.best.round()),+ };++ String recordDetail(PersonalRecord r) =>+ r.kind == PrKind.weight ? t.oneRmEst(weightLabel(r.oneRm)) : t.prBestSet;+int get prsThisWeek {- final bestOrm = <String, double>{};+ final kinds = {for (final r in personalRecords) r.id: r.kind};+ final bestScore = <String, double>{};final bestDate = <String, DateTime>{};for (final s in sessions) {for (final e in s.exercises) {- for (final st in e.sets) {- if (!bestOrm.containsKey(e.id) || st.oneRm > bestOrm[e.id]!) {- bestOrm[e.id] = st.oneRm;+ final kind = kinds[e.id];+ if (kind == null) continue;+ for (final st in e.workingSets) {+ final score = kind == PrKind.weight ? st.oneRm : kind.score(st);+ if (score > (bestScore[e.id] ?? 0)) {+ bestScore[e.id] = score;bestDate[e.id] = s.date;}}@@ -626,17 +661,6 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {return '${weightValue(s.weight)}×${s.reps}';}- ({double topWeight, double oneRm})? exercisePr(String id) {- final h = exerciseHistory(id);- if (h.isEmpty) return null;- double tw = 0, orm = 0;- for (final r in h) {- tw = math.max(tw, r.ex.topWeight);- orm = math.max(orm, r.ex.bestOneRm);- }- return (topWeight: tw, oneRm: orm);- }-String? strengthExerciseId;List<({String id, String name, int sessions})> get trackedExercises {@@ -644,6 +668,7 @@ mixin StatsState on FitCore, ToolsState, LibraryState, TimelineState {final names = <String, String>{};for (final s in sessions) {for (final e in s.exercises) {+ if (e.topWeight <= 0) continue;count[e.id] = (count[e.id] ?? 0) + 1;names[e.id] = e.name;}diff --git a/lib/widgets/note_kit.dart b/lib/widgets/note_kit.dartindex 4b8834d..da2f7c1 100644--- a/lib/widgets/note_kit.dart+++ b/lib/widgets/note_kit.dart@@ -67,7 +67,7 @@ class NoteCalendar extends StatelessWidget {final today = DateTime.now();final first = DateTime(month.year, month.month);final days = DateTime(month.year, month.month + 1, 0).day;- final lead = (first.weekday - t.firstWeekday + 7) % 7;+ final lead = (first.weekday - fit.weekStartDay + 7) % 7;return Column(children: [@@ -87,7 +87,7 @@ class NoteCalendar extends StatelessWidget {children: [for (int i = 0; i < 7; i++)Expanded(- child: Text(t.weekdayInitial((t.firstWeekday + i - 1) % 7 + 1).toUpperCase(),+ child: Text(t.weekdayInitial(fit.weekdayAt(i)).toUpperCase(),textAlign: TextAlign.center,style: AppTheme.f(10.5,weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),