This commit is contained in:
@ -4,6 +4,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:watch_bridge_contract/watch_bridge_contract.dart';
|
||||
|
||||
import '../application/application.dart';
|
||||
import '../domain/domain.dart';
|
||||
@ -30,6 +31,7 @@ final class WorkoutExecutionScreen extends StatefulWidget {
|
||||
this.stepUseCases,
|
||||
this.sensorUseCases,
|
||||
this.stepAudioCuePlayer,
|
||||
this.watchAlertPublisher,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@ -45,6 +47,7 @@ final class WorkoutExecutionScreen extends StatefulWidget {
|
||||
final VideoMediaBuilder? videoMediaBuilder;
|
||||
final ActiveWorkoutSensorUseCases? sensorUseCases;
|
||||
final ExerciseStepAudioCuePlayer? stepAudioCuePlayer;
|
||||
final WatchAlertPublisher? watchAlertPublisher;
|
||||
|
||||
@override
|
||||
State<WorkoutExecutionScreen> createState() => _WorkoutExecutionScreenState();
|
||||
@ -1077,6 +1080,7 @@ final class _WorkoutExecutionScreenState extends State<WorkoutExecutionScreen> {
|
||||
}
|
||||
|
||||
Future<void> _playStepAudioCue({required bool short}) async {
|
||||
unawaited(_publishStepAlert(short: short));
|
||||
try {
|
||||
if (short) {
|
||||
await _stepAudioCuePlayer.playShortCountdownBeep();
|
||||
@ -1088,6 +1092,52 @@ final class _WorkoutExecutionScreenState extends State<WorkoutExecutionScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _publishStepAlert({required bool short}) async {
|
||||
final publisher = widget.watchAlertPublisher;
|
||||
if (publisher == null) {
|
||||
return;
|
||||
}
|
||||
final nowMs = DateTime.now().toUtc().millisecondsSinceEpoch;
|
||||
final position = _position;
|
||||
final stepState = _stepProgress?.state;
|
||||
final passageIndex = stepState?.currentPassageIndex;
|
||||
final stepIndex = stepState?.currentStepIndex;
|
||||
final ttlMs = short ? 700 : 2000;
|
||||
final alert = WatchAlertEnvelope(
|
||||
alertId: [
|
||||
_session.metadata.id,
|
||||
position.programIndex,
|
||||
position.exerciseIndex,
|
||||
position.setIndex,
|
||||
passageIndex,
|
||||
stepIndex,
|
||||
short ? 'tick' : 'finish',
|
||||
nowMs,
|
||||
].join('-'),
|
||||
sessionId: _session.metadata.id,
|
||||
revision: 0,
|
||||
kind: short
|
||||
? WatchAlertKind.countdownTick
|
||||
: WatchAlertKind.countdownFinished,
|
||||
timerKind: WatchTimerKind.step,
|
||||
programIndex: position.programIndex,
|
||||
exerciseIndex: position.exerciseIndex,
|
||||
setIndex: position.setIndex,
|
||||
passageIndex: passageIndex,
|
||||
stepIndex: stepIndex,
|
||||
scheduledForEpochMs: nowMs,
|
||||
expiresAtEpochMs: nowMs + ttlMs,
|
||||
pattern: short
|
||||
? WatchAlertPattern.countdownTick
|
||||
: WatchAlertPattern.timerFinished,
|
||||
);
|
||||
try {
|
||||
await publisher.publishAlert(alert);
|
||||
} on Object catch (error) {
|
||||
debugPrint('Watch alert ignored: $error');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _startCurrentStepTimer() async {
|
||||
if (_stepProgress?.currentStep?.type != ExerciseStepType.time) return;
|
||||
try {
|
||||
@ -1818,6 +1868,7 @@ final class _WorkoutExecutionScreenState extends State<WorkoutExecutionScreen> {
|
||||
mediaAssetLoader: widget.mediaAssetLoader,
|
||||
videoMediaBuilder: widget.videoMediaBuilder,
|
||||
sensorUseCases: widget.sensorUseCases,
|
||||
watchAlertPublisher: widget.watchAlertPublisher,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user