diff --git a/lib/screens/metering/components/camera_container/bloc_container_camera.dart b/lib/screens/metering/components/camera_container/bloc_container_camera.dart index 3b5596b..cd91f59 100644 --- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart +++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart @@ -7,6 +7,7 @@ import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:lightmeter/data/analytics/analytics.dart'; import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/platform_config.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; @@ -22,6 +23,7 @@ part 'mock_bloc_container_camera.dart'; class CameraContainerBloc extends EvSourceBlocBase { final MeteringInteractor _meteringInteractor; + final LightmeterAnalytics _analytics; late final _WidgetsBindingObserver _observer; CameraController? _cameraController; @@ -42,6 +44,7 @@ class CameraContainerBloc extends EvSourceBlocBase(), + ServicesProvider.of(context).analytics, ) : CameraContainerBloc( MeteringInteractorProvider.of(context), context.read(), + ServicesProvider.of(context).analytics, )) ..add(const RequestPermissionEvent()), child: CameraContainer( diff --git a/lib/utils/ev_from_bytes.dart b/lib/utils/ev_from_bytes.dart index c7d12ea..da81831 100644 --- a/lib/utils/ev_from_bytes.dart +++ b/lib/utils/ev_from_bytes.dart @@ -1,27 +1,20 @@ -import 'dart:developer'; import 'dart:math' as math; import 'dart:typed_data'; import 'package:exif/exif.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; -Future evFromImage(Uint8List bytes) async { - try { - final tags = await readExifFromBytes(bytes); - final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}"); - final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first; - final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first; - if (iso == null || apertureValueRatio == null || speedValueRatio == null) { - log('Error parsing EXIF: ${tags.keys}'); - return null; - } - - final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator; - final speed = speedValueRatio.numerator / speedValueRatio.denominator; - - return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100); - } catch (e) { - log(e.toString()); - return null; +Future evFromImage(Uint8List bytes) async { + final tags = await readExifFromBytes(bytes); + final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}"); + final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first; + final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first; + if (iso == null || apertureValueRatio == null || speedValueRatio == null) { + throw 'Error parsing EXIF: ${tags.keys}'; } + + final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator; + final speed = speedValueRatio.numerator / speedValueRatio.denominator; + + return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100); } diff --git a/test/screens/metering/components/camera/bloc_container_camera_test.dart b/test/screens/metering/components/camera/bloc_container_camera_test.dart index 52c57c8..2ec043e 100644 --- a/test/screens/metering/components/camera/bloc_container_camera_test.dart +++ b/test/screens/metering/components/camera/bloc_container_camera_test.dart @@ -2,6 +2,7 @@ import 'package:bloc_test/bloc_test.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:lightmeter/data/analytics/analytics.dart'; import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events; @@ -18,11 +19,14 @@ class _MockMeteringCommunicationBloc extends MockBloc implements MeteringCommunicationBloc {} +class _MockLightmeterAnalytics extends Mock implements LightmeterAnalytics {} + void main() { TestWidgetsFlutterBinding.ensureInitialized(); late _MockMeteringInteractor meteringInteractor; late _MockMeteringCommunicationBloc communicationBloc; + late _MockLightmeterAnalytics analytics; late CameraContainerBloc bloc; const cameraMethodChannel = MethodChannel('plugins.flutter.io/camera'); @@ -110,16 +114,21 @@ void main() { setUpAll(() { meteringInteractor = _MockMeteringInteractor(); - communicationBloc = _MockMeteringCommunicationBloc(); + communicationBloc = _MockMeteringCommunicationBloc(); when(() => meteringInteractor.cameraEvCalibration).thenReturn(0.0); when(meteringInteractor.quickVibration).thenAnswer((_) async {}); + + analytics = _MockLightmeterAnalytics(); + registerFallbackValue(StackTrace.empty); + when(() => analytics.logCrash(any(), any())).thenAnswer((_) async {}); }); setUp(() { bloc = CameraContainerBloc( meteringInteractor, communicationBloc, + analytics, ); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(cameraMethodChannel, cameraMethodCallSuccessHandler);