From 182cb26bb3e4a68d8823b7aa1862044ff7c545cf Mon Sep 17 00:00:00 2001 From: freebeartogoodhome <801dan@protonmail.com> Date: Fri, 22 May 2026 14:11:12 -0600 Subject: [PATCH] small changes to coordinate_training_controller and refactor move_feedback --- .../model/common/service/move_feedback.dart | 29 +++++++++---------- .../coordinate_training_controller.dart | 9 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/src/model/common/service/move_feedback.dart b/lib/src/model/common/service/move_feedback.dart index 89aaeed4ac..a9f453f48c 100644 --- a/lib/src/model/common/service/move_feedback.dart +++ b/lib/src/model/common/service/move_feedback.dart @@ -7,19 +7,20 @@ import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; /// A provider for [MoveFeedbackService]. final moveFeedbackServiceProvider = Provider((Ref ref) { final soundService = ref.watch(soundServiceProvider); - return MoveFeedbackService(soundService, ref); + final hasHapticFeedback = ref.watch( + boardPreferencesProvider.select((prefs) => prefs.hapticFeedback), + ); + return MoveFeedbackService(soundService, hasHapticFeedback: hasHapticFeedback); }, name: 'MoveFeedbackServiceProvider'); class MoveFeedbackService { - MoveFeedbackService(this._soundService, this._ref); + MoveFeedbackService(this._soundService, {required this.hasHapticFeedback}); final SoundService _soundService; - final Ref _ref; + final bool hasHapticFeedback; - void moveFeedback({bool check = false}) { - _soundService.play(Sound.move); - - if (_ref.read(boardPreferencesProvider).hapticFeedback) { + void _playHapticFeedback({required bool check}) { + if (hasHapticFeedback) { if (check) { HapticFeedback.mediumImpact(); } else { @@ -28,15 +29,13 @@ class MoveFeedbackService { } } + void moveFeedback({bool check = false}) { + _soundService.play(Sound.move); + _playHapticFeedback(check: check); + } + void captureFeedback(Variant variant, {bool check = false}) { _soundService.playCaptureSound(variant); - - if (_ref.read(boardPreferencesProvider).hapticFeedback) { - if (check) { - HapticFeedback.mediumImpact(); - } else { - HapticFeedback.lightImpact(); - } - } + _playHapticFeedback(check: check); } } diff --git a/lib/src/model/coordinate_training/coordinate_training_controller.dart b/lib/src/model/coordinate_training/coordinate_training_controller.dart index 0afa9bbb66..019beae127 100644 --- a/lib/src/model/coordinate_training/coordinate_training_controller.dart +++ b/lib/src/model/coordinate_training/coordinate_training_controller.dart @@ -28,6 +28,7 @@ class CoordinateTrainingController extends Notifier { CoordinateTrainingState build() { ref.onDispose(() { _updateTimer?.cancel(); + _stopwatch.stop(); }); final sideChoice = ref.watch( coordinateTrainingPreferencesProvider.select((value) => value.sideChoice), @@ -60,19 +61,19 @@ class CoordinateTrainingController extends Notifier { void _finishTraining() { // TODO save score in local storage here (and display high score and/or average score in UI) - final orientation = _getOrientation(ref.read(coordinateTrainingPreferencesProvider).sideChoice); _updateTimer?.cancel(); + _stopwatch.stop(); state = CoordinateTrainingState( lastGuess: state.lastGuess, lastScore: state.score, - orientation: orientation, + orientation: state.orientation, ); } void abortTraining() { - final orientation = _getOrientation(ref.read(coordinateTrainingPreferencesProvider).sideChoice); _updateTimer?.cancel(); - state = CoordinateTrainingState(orientation: orientation); + _stopwatch.stop(); + state = CoordinateTrainingState(orientation: state.orientation); } Side _getOrientation(SideChoice choice) => switch (choice) {