diff --git a/lib/helpers/json.dart b/lib/helpers/json.dart index f10c1f80..b50ee5f8 100644 --- a/lib/helpers/json.dart +++ b/lib/helpers/json.dart @@ -53,6 +53,16 @@ String? dateToYYYYMMDD(DateTime? dateTime) { return DateFormat('yyyy-MM-dd').format(dateTime); } +/* + * Converts a datetime format with time to string date time + */ +String? dateToYYYYMMDDHHMM(DateTime? dateTime) { + if (dateTime == null) { + return null; + } + return DateFormat('yyyy-MM-dd HH:mm').format(dateTime); +} + /* * Converts a time to a date object. * Needed e.g. when the wger api only sends a time but no date information. diff --git a/lib/models/workouts/log.dart b/lib/models/workouts/log.dart index 49a04923..62e25d8a 100644 --- a/lib/models/workouts/log.dart +++ b/lib/models/workouts/log.dart @@ -80,7 +80,7 @@ class Log { @JsonKey(includeFromJson: false, includeToJson: false) late WeightUnit? weightUnitObj; - @JsonKey(required: true, toJson: dateToYYYYMMDD) + @JsonKey(required: true, toJson: dateToYYYYMMDDHHMM) late DateTime date; Log({ diff --git a/lib/models/workouts/log.g.dart b/lib/models/workouts/log.g.dart index 397df1b5..54a66586 100644 --- a/lib/models/workouts/log.g.dart +++ b/lib/models/workouts/log.g.dart @@ -58,5 +58,5 @@ Map _$LogToJson(Log instance) => { 'weight': numToString(instance.weight), 'weight_target': numToString(instance.weightTarget), 'weight_unit': instance.weightUnitId, - 'date': dateToYYYYMMDD(instance.date), + 'date': dateToYYYYMMDDHHMM(instance.date), }; diff --git a/lib/models/workouts/routine.dart b/lib/models/workouts/routine.dart index d0f55dbb..fc0dbd78 100644 --- a/lib/models/workouts/routine.dart +++ b/lib/models/workouts/routine.dart @@ -144,10 +144,23 @@ class Routine { var out = logs.where((log) => log.exerciseId == exerciseId).toList(); if (unique) { - out = out.toSet().toList(); + //out = out.toSet().toList(); - OLD METHOD + + // Create a map to store unique logs by date + var uniqueLogsByDate = {}; + + for (var log in out) { + var uniqueString = + '${log.date.year}/${log.date.month}/${log.date.day}/${log.weight}/${log.repetitions}'; + uniqueLogsByDate[uniqueString] = log; + } + + // Extract the unique logs + out = uniqueLogsByDate.values.toList(); } out.sort((a, b) => b.date.compareTo(a.date)); + return out; } diff --git a/lib/widgets/routines/gym_mode/log_page.dart b/lib/widgets/routines/gym_mode/log_page.dart index 9e2d9cce..751ed841 100644 --- a/lib/widgets/routines/gym_mode/log_page.dart +++ b/lib/widgets/routines/gym_mode/log_page.dart @@ -225,7 +225,7 @@ class _LogPageState extends State { children: [ Text( AppLocalizations.of(context).newEntry, - style: Theme.of(context).textTheme.titleLarge, + style: Theme.of(context).textTheme.titleMedium, textAlign: TextAlign.center, ), if (!_detailed) @@ -335,19 +335,22 @@ class _LogPageState extends State { Widget getPastLogs() { return ListView( + padding: const EdgeInsets.only(left: 10), children: [ Text( AppLocalizations.of(context).labelWorkoutLogs, - style: Theme.of(context).textTheme.titleLarge, - textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleMedium, + textAlign: TextAlign.left, ), ...widget._workoutPlan.filterLogsByExercise(widget._exercise.id!, unique: true).map((log) { return ListTile( title: Text(log.singleLogRepTextNoNl), subtitle: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode).format(log.date), - ), + '${DateFormat.yMd(Localizations.localeOf(context).languageCode).format(log.date)}: ' + '${widget._workoutPlan.logs.where((logs) => logs.exerciseId == log.exerciseId && log.date.day == logs.date.day && log.date.month == logs.date.month && log.date.year == logs.date.year && log.repetitions == logs.repetitions && log.weight == logs.weight).length} ${AppLocalizations.of(context).sets}'), trailing: const Icon(Icons.copy), + dense: true, + visualDensity: VisualDensity(vertical: -3), onTap: () { setState(() { // Text field @@ -365,7 +368,6 @@ class _LogPageState extends State { )); }); }, - contentPadding: const EdgeInsets.symmetric(horizontal: 40), ); }), ], @@ -384,7 +386,7 @@ class _LogPageState extends State { children: [ Text( AppLocalizations.of(context).plateCalculator, - style: Theme.of(context).textTheme.titleLarge, + style: Theme.of(context).textTheme.titleMedium, ), SizedBox( height: 35, @@ -419,7 +421,7 @@ class _LogPageState extends State { ), ), ), - const SizedBox(width: 10), + const SizedBox(width: 5), ], ), ), @@ -436,6 +438,16 @@ class _LogPageState extends State { @override Widget build(BuildContext context) { + const Duration currentSetWindow = Duration(hours: -4); + final int currentSet = 1 + + widget._workoutPlan.logs + .where((logs) => + logs.exerciseId == widget._exercise.id && + logs.slotEntryId == widget._log.slotEntryId && + logs.date.isAfter(DateTime.now().add(currentSetWindow))) + .length; + final int totalExerciseSets = + widget._slotData.setConfigs.where((logs) => logs.exerciseId == widget._exercise.id).length; return Column( children: [ NavigationHeader( @@ -446,7 +458,14 @@ class _LogPageState extends State { Center( child: Text( widget._configData.textRepr, - style: Theme.of(context).textTheme.headlineMedium, + style: Theme.of(context).textTheme.titleLarge, + textAlign: TextAlign.center, + ), + ), + Center( + child: Text( + '${AppLocalizations.of(context).set} $currentSet / $totalExerciseSets', + style: Theme.of(context).textTheme.bodyMedium, textAlign: TextAlign.center, ), ),