/// A recording fake for the run foreground service. library; import 'package:audioplayers/audioplayers.dart'; import 'package:workout_app/services/feedback_cues.dart'; import 'package:workout_app/services/foreground_run_client.dart'; import 'package:workout_app/services/pace_band.dart'; /// Stands in for `flutter_foreground_task` on the run screen's side. class FakeForegroundRunClient implements ForegroundRunClient { /// Creates a fake describing a healthy Android device. FakeForegroundRunClient({ this.isSupported = true, this.permissionGranted = true, this.grantOnRequest = true, this.startSucceeds = true, this.onStart, }); @override bool isSupported; /// Whether notifications are already allowed. bool permissionGranted; /// Whether asking for them succeeds. bool grantOnRequest; /// Whether the service starts. bool startSucceeds; /// Runs inside [start], to record what had happened by then. void Function()? onStart; /// `withLocation` of each start. final starts = []; /// Notification redraws as `title|text`, the first being the start. final drawn = []; /// Calls recorded in order. final calls = []; @override Future hasNotificationPermission() async { calls.add('has'); return permissionGranted; } @override Future requestNotificationPermission() async { calls.add('request'); return permissionGranted = grantOnRequest; } @override Future start({ required bool withLocation, required String title, required String text, }) async { calls.add('start'); onStart?.call(); starts.add(withLocation); drawn.add('$title|$text'); return startSucceeds; } @override Future update({required String title, required String text}) async { drawn.add('$title|$text'); } @override Future stop() async => calls.add('stop'); } /// Cues that touch neither the database nor a speaker, and count kilometres. class QuietCues extends FeedbackCues { /// Creates cues over a player (needs the fake audio platform installed). QuietCues() : super(AudioPlayer()); /// Kilometres announced. final kilometres = []; /// How many times the finish cue fired. int finishes = 0; /// Pace cues given, in order. final paceCues = []; @override Future load() async {} @override Future paceOff(PaceCue cue) async => paceCues.add(cue); @override Future kilometreReached(int km) async => kilometres.add(km); @override Future workoutFinished() async => finishes++; /// How many times advice to finish was cued. int suggestions = 0; /// How many times the 5 h end was cued. int autoEnds = 0; @override Future finishSuggested() async => suggestions++; @override Future autoEnded() async => autoEnds++; }