2023-01-29 16:57:47 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-02-10 21:49:51 +00:00
|
|
|
import 'package:app_settings/app_settings.dart';
|
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-01-29 16:57:47 +00:00
|
|
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
2023-05-16 09:47:53 +00:00
|
|
|
import 'package:lightmeter/data/models/film.dart';
|
2023-07-03 15:19:48 +00:00
|
|
|
import 'package:lightmeter/data/models/volume_action.dart';
|
2023-02-10 21:49:51 +00:00
|
|
|
import 'package:lightmeter/data/permissions_service.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
2023-07-03 15:19:48 +00:00
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
2023-05-16 09:47:53 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
2023-02-10 21:49:51 +00:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
class MeteringInteractor {
|
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-02-10 21:49:51 +00:00
|
|
|
final PermissionsService _permissionsService;
|
2023-01-29 16:57:47 +00:00
|
|
|
final LightSensorService _lightSensorService;
|
2023-07-03 15:19:48 +00:00
|
|
|
final VolumeEventsService _volumeEventsService;
|
2023-01-21 10:37:49 +00:00
|
|
|
|
2023-02-11 12:58:47 +00:00
|
|
|
MeteringInteractor(
|
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-02-10 21:49:51 +00:00
|
|
|
this._permissionsService,
|
2023-01-29 16:57:47 +00:00
|
|
|
this._lightSensorService,
|
2023-07-03 15:19:48 +00:00
|
|
|
this._volumeEventsService,
|
2023-02-11 12:58:47 +00:00
|
|
|
) {
|
|
|
|
if (_userPreferencesService.caffeine) {
|
|
|
|
_caffeineService.keepScreenOn(true);
|
|
|
|
}
|
2023-07-03 15:19:48 +00:00
|
|
|
_volumeEventsService
|
|
|
|
.setVolumeHandling(_userPreferencesService.volumeAction != VolumeAction.none);
|
2023-02-11 12:58:47 +00:00
|
|
|
}
|
2023-01-21 10:37:49 +00:00
|
|
|
|
2023-01-26 09:10:23 +00:00
|
|
|
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
|
2023-01-29 16:57:47 +00:00
|
|
|
double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration;
|
2023-06-20 06:43:49 +00:00
|
|
|
bool get isHapticsEnabled => _userPreferencesService.haptics;
|
2023-01-26 09:10:23 +00:00
|
|
|
|
2023-05-16 09:47:53 +00:00
|
|
|
IsoValue get iso => _userPreferencesService.iso;
|
|
|
|
set iso(IsoValue value) => _userPreferencesService.iso = value;
|
|
|
|
|
|
|
|
NdValue get ndFilter => _userPreferencesService.ndFilter;
|
|
|
|
set ndFilter(NdValue value) => _userPreferencesService.ndFilter = value;
|
|
|
|
|
|
|
|
Film get film => _userPreferencesService.film;
|
|
|
|
set film(Film value) => _userPreferencesService.film = value;
|
|
|
|
|
2023-07-03 15:19:48 +00:00
|
|
|
VolumeAction get volumeAction => _userPreferencesService.volumeAction;
|
2023-07-05 10:46:03 +00:00
|
|
|
|
2023-05-16 09:47:53 +00:00
|
|
|
/// Executes vibration if haptics are enabled in settings
|
|
|
|
Future<void> quickVibration() async {
|
|
|
|
if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
|
|
|
|
}
|
2023-01-21 10:37:49 +00:00
|
|
|
|
|
|
|
/// Executes vibration if haptics are enabled in settings
|
2023-05-16 09:47:53 +00:00
|
|
|
Future<void> responseVibration() async {
|
|
|
|
if (_userPreferencesService.haptics) await _hapticsService.responseVibration();
|
2023-01-21 10:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Executes vibration if haptics are enabled in settings
|
2023-05-16 09:47:53 +00:00
|
|
|
Future<void> errorVibration() async {
|
|
|
|
if (_userPreferencesService.haptics) await _hapticsService.errorVibration();
|
2023-01-21 10:37:49 +00:00
|
|
|
}
|
|
|
|
|
2023-02-10 21:49:51 +00:00
|
|
|
Future<bool> checkCameraPermission() async {
|
|
|
|
return _permissionsService
|
|
|
|
.checkCameraPermission()
|
|
|
|
.then((value) => value == PermissionStatus.granted);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> requestPermission() async {
|
|
|
|
return _permissionsService
|
|
|
|
.requestCameraPermission()
|
|
|
|
.then((value) => value == PermissionStatus.granted);
|
|
|
|
}
|
|
|
|
|
|
|
|
void openAppSettings() {
|
|
|
|
AppSettings.openAppSettings();
|
|
|
|
}
|
|
|
|
|
2023-01-29 16:57:47 +00:00
|
|
|
Future<bool> hasAmbientLightSensor() async {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
return _lightSensorService.hasSensor();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream<int> luxStream() => _lightSensorService.luxStream();
|
2023-01-21 10:37:49 +00:00
|
|
|
}
|