removed UserPreferencesService from MeteringBloc

This commit is contained in:
Vadim 2023-05-07 12:37:01 +02:00
parent 423694a50c
commit 46d4727629
4 changed files with 21 additions and 18 deletions

2
.vscode/launch.json vendored
View file

@ -8,7 +8,6 @@
"name": "dev (android)", "name": "dev (android)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
//"flutterMode": "profile",
"args": [ "args": [
"--flavor", "--flavor",
"dev", "dev",
@ -21,7 +20,6 @@
"name": "dev (ios)", "name": "dev (ios)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
//"flutterMode": "release",
"args": [ "args": [
"--flavor", "--flavor",
"dev", "dev",

View file

@ -4,8 +4,10 @@ import 'package:app_settings/app_settings.dart';
import 'package:lightmeter/data/caffeine_service.dart'; import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart'; import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/permissions_service.dart'; import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
class MeteringInteractor { class MeteringInteractor {
@ -30,7 +32,14 @@ class MeteringInteractor {
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration; double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration; double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration;
bool get isHapticsEnabled => _userPreferencesService.haptics; 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;
/// Executes vibration if haptics are enabled in settings /// Executes vibration if haptics are enabled in settings
Future<void> quickVibration() async { Future<void> quickVibration() async {

View file

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/film.dart'; import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
@ -17,7 +16,6 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class MeteringBloc extends Bloc<MeteringEvent, MeteringState> { class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final MeteringCommunicationBloc _communicationBloc; final MeteringCommunicationBloc _communicationBloc;
final UserPreferencesService _userPreferencesService;
final MeteringInteractor _meteringInteractor; final MeteringInteractor _meteringInteractor;
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription; late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;
@ -29,24 +27,23 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
EquipmentProfileData _equipmentProfileData; EquipmentProfileData _equipmentProfileData;
StopType stopType; StopType stopType;
late IsoValue _iso = _userPreferencesService.iso; late IsoValue _iso = _meteringInteractor.iso;
late NdValue _nd = _userPreferencesService.ndFilter; late NdValue _nd = _meteringInteractor.ndFilter;
late Film _film = _userPreferencesService.film; late Film _film = _meteringInteractor.film;
double? _ev100 = 0.0; double? _ev100 = 0.0;
bool _isMeteringInProgress = false; bool _isMeteringInProgress = false;
MeteringBloc( MeteringBloc(
this._communicationBloc, this._communicationBloc,
this._userPreferencesService,
this._meteringInteractor, this._meteringInteractor,
this._equipmentProfileData, this._equipmentProfileData,
this.stopType, this.stopType,
) : super( ) : super(
MeteringDataState( MeteringDataState(
ev: 0.0, ev: 0.0,
film: _userPreferencesService.film, film: _meteringInteractor.film,
iso: _userPreferencesService.iso, iso: _meteringInteractor.iso,
nd: _userPreferencesService.ndFilter, nd: _meteringInteractor.ndFilter,
exposurePairs: const [], exposurePairs: const [],
continuousMetering: false, continuousMetering: false,
), ),
@ -90,13 +87,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
/// Update selected ISO value, if selected equipment profile /// Update selected ISO value, if selected equipment profile
/// doesn't contain currently selected value /// doesn't contain currently selected value
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) { if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
_userPreferencesService.iso = event.equipmentProfileData.isoValues.first; _meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
_iso = event.equipmentProfileData.isoValues.first; _iso = event.equipmentProfileData.isoValues.first;
} }
/// The same for ND filter /// The same for ND filter
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) { if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
_userPreferencesService.ndFilter = event.equipmentProfileData.ndValues.first; _meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
_nd = event.equipmentProfileData.ndValues.first; _nd = event.equipmentProfileData.ndValues.first;
} }
@ -112,7 +109,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
add(IsoChangedEvent(newIso)); add(IsoChangedEvent(newIso));
} }
_film = event.data; _film = event.data;
_userPreferencesService.film = event.data; _meteringInteractor.film = event.data;
_updateMeasurements(); _updateMeasurements();
} }
@ -120,13 +117,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
if (event.isoValue.value != _film.iso) { if (event.isoValue.value != _film.iso) {
_film = Film.values.first; _film = Film.values.first;
} }
_userPreferencesService.iso = event.isoValue; _meteringInteractor.iso = event.isoValue;
_iso = event.isoValue; _iso = event.isoValue;
_updateMeasurements(); _updateMeasurements();
} }
void _onNdChanged(NdChangedEvent event, Emitter emit) { void _onNdChanged(NdChangedEvent event, Emitter emit) {
_userPreferencesService.ndFilter = event.ndValue; _meteringInteractor.ndFilter = event.ndValue;
_nd = event.ndValue; _nd = event.ndValue;
_updateMeasurements(); _updateMeasurements();
} }

View file

@ -37,7 +37,6 @@ class _MeteringFlowState extends State<MeteringFlow> {
BlocProvider( BlocProvider(
create: (context) => MeteringBloc( create: (context) => MeteringBloc(
context.read<MeteringCommunicationBloc>(), context.read<MeteringCommunicationBloc>(),
context.read<UserPreferencesService>(),
context.read<MeteringInteractor>(), context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false), EquipmentProfile.of(context, listen: false),
context.read<StopType>(), context.read<StopType>(),