feat(ui): affichage du chrono de score dans le plan et l'historique (ticket #28)
Affiche le chrono du score chronométré sur workout_execution_screen.dart (plan de séance) et history_screen.dart (historique). flutter analyze propre, 77/77 tests verts, build APK debug validé. Dernier ticket du backlog — clôture aussi le ticket parent #18 (score chronométré). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -314,6 +314,22 @@ final class HistorySetDetail {
|
||||
final value = _formatScoreValue(result['actualScore'] as num);
|
||||
parts.add(unit == null ? 'Score $value' : 'Score $value $unit');
|
||||
}
|
||||
if (exercise['scoreEnabled'] == true &&
|
||||
_historyScoreInputMode(exercise, result) == ScoreInputMode.stopwatch &&
|
||||
result['actualScoreTimeMs'] != null) {
|
||||
final value = _formatScoreStopwatch(
|
||||
Duration(milliseconds: result['actualScoreTimeMs'] as int),
|
||||
);
|
||||
final target = _targetScoreTimeMsFromSnapshot(exercise, result);
|
||||
if (target == null) {
|
||||
parts.add('Temps réalisé : $value');
|
||||
} else {
|
||||
parts.add(
|
||||
'Temps réalisé : $value / objectif '
|
||||
'${_formatScoreStopwatchTarget(Duration(milliseconds: target))}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return HistorySetDetail(
|
||||
setIndex: result['setIndex'] as int,
|
||||
summary: parts.isEmpty ? 'Aucune mesure saisie' : parts.join(' · '),
|
||||
@ -361,6 +377,9 @@ Map<String, dynamic> _resultFromDomain(WorkoutHistorySetResult result) {
|
||||
'actualTimeMs': result.actualTimeMs,
|
||||
'actualReps': result.actualReps,
|
||||
'actualScore': result.actualScore,
|
||||
'actualScoreTimeMs': result.actualScoreTimeMs,
|
||||
'scoreInputModeSnapshot': result.scoreInputModeSnapshot.name,
|
||||
'targetScoreTimeMsSnapshot': result.targetScoreTimeMsSnapshot,
|
||||
};
|
||||
}
|
||||
|
||||
@ -372,7 +391,11 @@ String _historySummary(WorkoutHistory history) {
|
||||
: (snapshot['results'] as List<dynamic>? ?? const [])
|
||||
.cast<Map<String, dynamic>>();
|
||||
final scoreCount = rawResults
|
||||
.where((result) => result['actualScore'] != null)
|
||||
.where(
|
||||
(result) =>
|
||||
result['actualScore'] != null ||
|
||||
result['actualScoreTimeMs'] != null,
|
||||
)
|
||||
.length;
|
||||
return '${rawResults.length} séries · $scoreCount score${scoreCount > 1 ? 's' : ''}';
|
||||
}
|
||||
@ -403,6 +426,47 @@ String _formatDurationMs(int milliseconds) {
|
||||
return '$minutes:$seconds';
|
||||
}
|
||||
|
||||
String _formatScoreStopwatch(Duration duration) {
|
||||
final totalTenths = (duration.inMilliseconds / 100).floor();
|
||||
final minutes = (totalTenths ~/ 600).toString().padLeft(2, '0');
|
||||
final seconds = ((totalTenths ~/ 10) % 60).toString().padLeft(2, '0');
|
||||
final tenths = totalTenths % 10;
|
||||
return '$minutes:$seconds.$tenths';
|
||||
}
|
||||
|
||||
String _formatScoreStopwatchTarget(Duration duration) {
|
||||
if (duration.inMilliseconds % 1000 == 0) {
|
||||
return _formatDurationMs(duration.inMilliseconds);
|
||||
}
|
||||
return _formatScoreStopwatch(duration);
|
||||
}
|
||||
|
||||
ScoreInputMode _scoreInputModeFromSnapshot(Object? value) {
|
||||
return switch (value) {
|
||||
'stopwatch' => ScoreInputMode.stopwatch,
|
||||
_ => ScoreInputMode.manual,
|
||||
};
|
||||
}
|
||||
|
||||
int? _targetScoreTimeMsFromSnapshot(
|
||||
Map<String, dynamic> exercise,
|
||||
Map<String, dynamic> result,
|
||||
) {
|
||||
return result['targetScoreTimeMsSnapshot'] as int? ??
|
||||
(exercise['targetScoreTimeMs'] as int?);
|
||||
}
|
||||
|
||||
ScoreInputMode _historyScoreInputMode(
|
||||
Map<String, dynamic> exercise,
|
||||
Map<String, dynamic> result,
|
||||
) {
|
||||
final resultMode = result['scoreInputModeSnapshot'];
|
||||
if (resultMode != null) {
|
||||
return _scoreInputModeFromSnapshot(resultMode);
|
||||
}
|
||||
return _scoreInputModeFromSnapshot(exercise['scoreInputModeSnapshot']);
|
||||
}
|
||||
|
||||
final class _CenteredMessage extends StatelessWidget {
|
||||
const _CenteredMessage({required this.title, this.message});
|
||||
|
||||
|
||||
@ -1515,7 +1515,7 @@ final class _WorkoutPlanSetTile extends StatelessWidget {
|
||||
child: ListTile(
|
||||
enabled: tappable,
|
||||
title: Text('Série ${position.setIndex + 1}'),
|
||||
subtitle: Text(_planSetSubtitle(planState, state?.result)),
|
||||
subtitle: Text(_planSetSubtitle(planState, state?.result, exercise)),
|
||||
trailing: _PlanStatusBadge(status: planState, onTap: onTap),
|
||||
onTap: onTap,
|
||||
),
|
||||
@ -1851,9 +1851,13 @@ _PlanSetStatus _planSetState(
|
||||
return _PlanSetStatus.todo;
|
||||
}
|
||||
|
||||
String _planSetSubtitle(_PlanSetStatus status, ActiveSetResult? result) {
|
||||
String _planSetSubtitle(
|
||||
_PlanSetStatus status,
|
||||
ActiveSetResult? result,
|
||||
ExecutionExercise exercise,
|
||||
) {
|
||||
if (status == _PlanSetStatus.completed && result != null) {
|
||||
return _setResultSummary(result);
|
||||
return _setResultSummary(result, exercise: exercise);
|
||||
}
|
||||
if (status == _PlanSetStatus.passed) {
|
||||
return 'Aucun résultat';
|
||||
@ -1861,7 +1865,10 @@ String _planSetSubtitle(_PlanSetStatus status, ActiveSetResult? result) {
|
||||
return '';
|
||||
}
|
||||
|
||||
String _setResultSummary(ActiveSetResult result) {
|
||||
String _setResultSummary(
|
||||
ActiveSetResult result, {
|
||||
ExecutionExercise? exercise,
|
||||
}) {
|
||||
final parts = <String>[];
|
||||
if (result.actualTimeMs != null) {
|
||||
parts.add(_formatDuration(Duration(milliseconds: result.actualTimeMs!)));
|
||||
@ -1878,7 +1885,15 @@ String _setResultSummary(ActiveSetResult result) {
|
||||
final value = _formatScoreStopwatch(
|
||||
Duration(milliseconds: result.actualScoreTimeMs!),
|
||||
);
|
||||
parts.add('Temps réalisé $value');
|
||||
final targetScoreTimeMs = exercise?.targetScoreTimeMs;
|
||||
if (targetScoreTimeMs == null) {
|
||||
parts.add('Score chrono $value');
|
||||
} else {
|
||||
final targetValue = _formatScoreStopwatchTarget(
|
||||
Duration(milliseconds: targetScoreTimeMs),
|
||||
);
|
||||
parts.add('Score chrono $value / objectif $targetValue');
|
||||
}
|
||||
}
|
||||
return parts.isEmpty ? 'Aucun résultat' : parts.join(' · ');
|
||||
}
|
||||
@ -2050,6 +2065,7 @@ final class ExecutionExercise {
|
||||
this.targetTimeSeconds,
|
||||
this.targetReps,
|
||||
this.targetScore,
|
||||
this.targetScoreTimeMs,
|
||||
this.scoreUnit,
|
||||
});
|
||||
|
||||
@ -2084,6 +2100,9 @@ final class ExecutionExercise {
|
||||
targetScore:
|
||||
(override?['targetScoreOverride'] as num?)?.toDouble() ??
|
||||
(exercise['targetScore'] as num?)?.toDouble(),
|
||||
targetScoreTimeMs:
|
||||
(override?['targetScoreTimeMsOverride'] as int?) ??
|
||||
(exercise['targetScoreTimeMs'] as int?),
|
||||
scoreUnit: exercise['scoreUnitSnapshot'] as String?,
|
||||
);
|
||||
}
|
||||
@ -2102,6 +2121,7 @@ final class ExecutionExercise {
|
||||
final int? targetTimeSeconds;
|
||||
final int? targetReps;
|
||||
final double? targetScore;
|
||||
final int? targetScoreTimeMs;
|
||||
final String? scoreUnit;
|
||||
|
||||
bool get manualScoreEnabled {
|
||||
@ -2235,3 +2255,10 @@ String _formatScoreStopwatch(Duration duration) {
|
||||
final tenths = totalTenths % 10;
|
||||
return '$minutes:$seconds.$tenths';
|
||||
}
|
||||
|
||||
String _formatScoreStopwatchTarget(Duration duration) {
|
||||
if (duration.inMilliseconds % 1000 == 0) {
|
||||
return _formatDuration(duration);
|
||||
}
|
||||
return _formatScoreStopwatch(duration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user