2023-02-11 12:58:47 +00:00
|
|
|
import 'package:lightmeter/data/caffeine_service.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
import 'package:lightmeter/data/haptics_service.dart';
|
2023-07-09 11:39:33 +00:00
|
|
|
import 'package:lightmeter/data/models/volume_action.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
2023-07-09 11:39:33 +00:00
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
class SettingsInteractor {
|
2023-01-21 10:37:49 +00:00
|
|
|
final UserPreferencesService _userPreferencesService;
|
2023-02-11 12:58:47 +00:00
|
|
|
final CaffeineService _caffeineService;
|
2023-01-21 10:37:49 +00:00
|
|
|
final HapticsService _hapticsService;
|
2023-07-09 11:39:33 +00:00
|
|
|
final VolumeEventsService _volumeEventsService;
|
2023-01-21 10:37:49 +00:00
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
const SettingsInteractor(
|
2023-01-21 10:37:49 +00:00
|
|
|
this._userPreferencesService,
|
2023-02-11 12:58:47 +00:00
|
|
|
this._caffeineService,
|
2023-01-21 10:37:49 +00:00
|
|
|
this._hapticsService,
|
2023-07-09 11:39:33 +00:00
|
|
|
this._volumeEventsService,
|
2023-01-21 10:37:49 +00:00
|
|
|
);
|
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
|
|
|
|
void setCameraEvCalibration(double value) => _userPreferencesService.cameraEvCalibration = value;
|
|
|
|
|
2023-01-29 16:57:47 +00:00
|
|
|
double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration;
|
2023-02-11 12:58:47 +00:00
|
|
|
void setLightSensorEvCalibration(double value) =>
|
|
|
|
_userPreferencesService.lightSensorEvCalibration = value;
|
|
|
|
|
|
|
|
bool get isCaffeineEnabled => _userPreferencesService.caffeine;
|
|
|
|
Future<void> enableCaffeine(bool enable) async {
|
|
|
|
await _caffeineService.keepScreenOn(enable).then((value) {
|
|
|
|
_userPreferencesService.caffeine = enable;
|
|
|
|
});
|
|
|
|
}
|
2023-01-29 16:57:47 +00:00
|
|
|
|
2023-07-09 11:39:33 +00:00
|
|
|
Future<void> disableVolumeHandling() async {
|
|
|
|
await _volumeEventsService.setVolumeHandling(false);
|
|
|
|
}
|
|
|
|
Future<void> restoreVolumeHandling() async {
|
|
|
|
await _volumeEventsService
|
|
|
|
.setVolumeHandling(_userPreferencesService.volumeAction != VolumeAction.none);
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeAction get volumeAction => _userPreferencesService.volumeAction;
|
|
|
|
Future<void> setVolumeAction(VolumeAction value) async {
|
|
|
|
_userPreferencesService.volumeAction = value;
|
2023-07-10 15:49:34 +00:00
|
|
|
await _volumeEventsService.setVolumeHandling(value != VolumeAction.none);
|
2023-07-09 11:39:33 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
bool get isHapticsEnabled => _userPreferencesService.haptics;
|
2023-02-11 12:58:47 +00:00
|
|
|
void enableHaptics(bool enable) {
|
|
|
|
_userPreferencesService.haptics = enable;
|
|
|
|
quickVibration();
|
|
|
|
}
|
2023-01-21 10:37:49 +00:00
|
|
|
|
|
|
|
/// Executes vibration if haptics are enabled in settings
|
|
|
|
void quickVibration() {
|
|
|
|
if (_userPreferencesService.haptics) _hapticsService.quickVibration();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Executes vibration if haptics are enabled in settings
|
|
|
|
void responseVibration() {
|
|
|
|
if (_userPreferencesService.haptics) _hapticsService.responseVibration();
|
|
|
|
}
|
|
|
|
}
|