Skip to content

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

Show repetition records above the exercise history

InlitXd602e7c25662
diff --git a/lib/widgets/exercise_history_sheet.dart b/lib/widgets/exercise_history_sheet.dart
index 67a308f..034646e 100644
--- a/lib/widgets/exercise_history_sheet.dart
+++ b/lib/widgets/exercise_history_sheet.dart
@@ -37,6 +37,8 @@ class _ExerciseHistorySheetState extends State<ExerciseHistorySheet> {
String get _id => widget.exerciseId;
late final _history = fit.exerciseHistory(_id);
late final bool _charted = fit.modeOf(_id).isEmpty && fit.exerciseTrend(_id).length > 1;
+ late final _ladder = fit.repRecords(_id);
+ late final _record = fit.exerciseRecord(_id);
late int _range = _pickRange();
bool _relative = false;
int _shown = _page;
@@ -87,6 +89,10 @@ class _ExerciseHistorySheetState extends State<ExerciseHistorySheet> {
const SizedBox(height: 4),
Text('${titleCase(t.history)} · ${t.sessionCount(_history.length)}',
style: AppTheme.f(12.5, weight: FontWeight.w500, color: gc.textSecondary)),
+ if (_record != null) ...[
+ const SizedBox(height: 16),
+ _records(gc, _record),
+ ],
if (_charted) ...[
const SizedBox(height: 18),
_trend(gc),
@@ -153,6 +159,67 @@ class _ExerciseHistorySheetState extends State<ExerciseHistorySheet> {
);
}
+ String _when(DateTime d) => d.year == DateTime.now().year ? t.shortDate(d) : t.shortMonthYear(d);
+
+ Widget _records(GymColors gc, PersonalRecord pr) {
+ final kind = _ladder.isNotEmpty
+ ? PrKind.weight
+ : pr.kind == PrKind.weight && fit.isAssisted(_id)
+ ? PrKind.reps
+ : pr.kind;
+ final work = kind == PrKind.weight || kind == PrKind.reps ? fit.bestWorkout(_id, kind) : null;
+ return Container(
+ padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
+ if (_ladder.isNotEmpty) ...[
+ SectionLabel('${t.repRecordsTitle} · ${fit.unitsFor(_id)}'),
+ const SizedBox(height: 10),
+ Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ for (var i = 0; i < _ladder.length; i++) ...[
+ if (i > 0) const SizedBox(width: 8),
+ Expanded(child: _rung(gc, _ladder[i])),
+ ],
+ ]),
+ ] else ...[
+ SectionLabel(t.personalRecord),
+ const SizedBox(height: 8),
+ FitText(fit.recordLabel(pr), style: AppTheme.d(22, weight: FontWeight.w800, color: gc.text)),
+ ],
+ if (work != null) ...[
+ const SizedBox(height: 14),
+ Row(children: [
+ Expanded(
+ child: Text(t.prBestWorkout,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ const SizedBox(width: 10),
+ Text(
+ kind == PrKind.weight
+ ? '${groupedInt(fit.toShownFor(_id, work.score).round())} ${fit.unitsFor(_id)}'
+ : t.repCount(work.score.round()),
+ style: AppTheme.d(13.5, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(width: 8),
+ Text(_when(work.date), style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary)),
+ ]),
+ ],
+ ]),
+ );
+ }
+
+ Widget _rung(GymColors gc, ({int reps, double kg, DateTime date}) r) => Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ FitText(fit.weightValueFor(_id, r.kg), style: AppTheme.d(20, weight: FontWeight.w800, color: gc.text)),
+ const SizedBox(height: 5),
+ FitText(t.repCount(r.reps), style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary)),
+ const SizedBox(height: 2),
+ FitText(_when(r.date), style: AppTheme.f(11, weight: FontWeight.w500, color: gc.textTertiary)),
+ ],
+ );
+
Widget _trend(GymColors gc) {
final points = fit.exerciseTrend(_id, days: _range, relative: _relative);
final values = [
diff --git a/test/history_test.dart b/test/history_test.dart
index 64f0ec6..7cb431f 100644
--- a/test/history_test.dart
+++ b/test/history_test.dart
@@ -362,6 +362,31 @@ void main() {
expect(fit.canShowRelative(fit.matchExerciseByName('Pull Up')!.id), isFalse);
});
+ test('los récords por reps solo guardan lo que no supera una serie más larga', () {
+ final n = DateTime.now();
+ LoggedSession day(int ago, List<LoggedSet> sets) => LoggedSession(
+ DateTime(n.year, n.month, n.day - ago, 18), 3600, [LoggedExercise(bench(), 'Bench Press', 'chest', sets)]);
+ fit.sessions.addAll([
+ day(30, [LoggedSet(5, 100), LoggedSet(8, 90)]),
+ day(10, [LoggedSet(3, 100), LoggedSet(10, 80), LoggedSet(6, 85)]),
+ day(2, [LoggedSet(5, 100), LoggedSet(1, 110)]),
+ ]);
+ final ladder = fit.repRecords(bench());
+ expect([for (final r in ladder) (r.reps, r.kg)], [(1, 110.0), (5, 100.0), (8, 90.0), (10, 80.0)]);
+ expect(ladder[1].date.day, DateTime(n.year, n.month, n.day - 30).day);
+ expect(fit.repRecords(fit.matchExerciseByName('Pull Up')!.id), isEmpty);
+ });
+
+ test('los récords por reps se quedan en cinco repartidos', () {
+ final n = DateTime.now();
+ fit.sessions.add(LoggedSession(DateTime(n.year, n.month, n.day - 1, 18), 3600, [
+ LoggedExercise(bench(), 'Bench Press', 'chest', [
+ for (var r = 1; r <= 9; r++) LoggedSet(r, 120.0 - r * 5),
+ ]),
+ ]));
+ expect([for (final r in fit.repRecords(bench())) r.reps], [1, 3, 5, 7, 9]);
+ });
+
test('el total levantado suma todo lo que has hecho', () {
logDays([(3, 100), (1, 50)]);
expect(fit.totalVolumeKg, 5 * 100 + 5 * 50);