Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/helpers/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/models/workouts/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion lib/models/workouts/log.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion lib/models/workouts/routine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <String, Log>{};

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;
}

Expand Down
37 changes: 28 additions & 9 deletions lib/widgets/routines/gym_mode/log_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _LogPageState extends State<LogPage> {
children: [
Text(
AppLocalizations.of(context).newEntry,
style: Theme.of(context).textTheme.titleLarge,
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
if (!_detailed)
Expand Down Expand Up @@ -335,19 +335,22 @@ class _LogPageState extends State<LogPage> {

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
Expand All @@ -365,7 +368,6 @@ class _LogPageState extends State<LogPage> {
));
});
},
contentPadding: const EdgeInsets.symmetric(horizontal: 40),
);
}),
],
Expand All @@ -384,7 +386,7 @@ class _LogPageState extends State<LogPage> {
children: [
Text(
AppLocalizations.of(context).plateCalculator,
style: Theme.of(context).textTheme.titleLarge,
style: Theme.of(context).textTheme.titleMedium,
),
SizedBox(
height: 35,
Expand Down Expand Up @@ -419,7 +421,7 @@ class _LogPageState extends State<LogPage> {
),
),
),
const SizedBox(width: 10),
const SizedBox(width: 5),
],
),
),
Expand All @@ -436,6 +438,16 @@ class _LogPageState extends State<LogPage> {

@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(
Expand All @@ -446,7 +458,14 @@ class _LogPageState extends State<LogPage> {
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,
),
),
Expand Down