From 933a0e30cc41e62479922f3366554a78a4f12017 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 3 Jul 2023 10:47:01 +0200 Subject: [PATCH] implemented `VolumeEventsService` --- README.md | 42 +++++++--------------- lib/data/volume_events_service.dart | 27 ++++++++++++++ test/data/volume_events_service_test.dart | 44 +++++++++++++++++++++++ 3 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 lib/data/volume_events_service.dart create mode 100644 test/data/volume_events_service_test.dart diff --git a/README.md b/README.md index c801a9c..3c77415 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ - [Table of contents](#table-of-contents) - [Backstory](#backstory) -- [Legacy features](#legacy-features) - [Build](#build) - [Contribution](#contribution) +- [iOS Limitations](#ios-limitations) # Backstory @@ -21,38 +21,22 @@ But as the existing repo contained some sensitive data, that I've pushed due to Without further delay behold my new Lightmeter app inspired by Material You (a.k.a. M3) -# Legacy features - -The list of features that the old lightmeter app has and that have to be implemeneted in the M3 lightmeter. - -### Metering -- [x] ISO selecting -- [x] Reciprocity for different films -- [x] Reflected light metering -- [x] Incident light metering - -### Adjust -- [x] Light sources EV calibration -- [ ] Customizable aperture range -- [ ] Customizable shutter speed range -- [x] ND filter select - -### General -- [x] Caffeine -- [x] Vibration -- [ ] Volume button actions - -### Theme -- [x] Dark theme -- [x] Picking primary color -- [x] Russian language - -## Build +# Build As part of this project is private, you will be able to run this app from the _main_dev.dart_ file (i.e. --flavor dev). Also to avoid fatal errors the _main_prod.dart_ file is excluded from analysis. -## Contribution +# Contribution To report a bug or suggest a new feature open a new [issue](https://github.com/vodemn/m3_lightmeter/issues). In case you want to help develop this project you need to follow this [style guide](doc/style_guide.md). + +# iOS Limitations + +A list of features, that Android version of the app has and that iOS does not. + +## Incident light metering +Apple does not provide API for reading Lux stream form the ambient light sensor. Lux can be calculated based on front camera image stream, but this would be a reflected light. So there is no way incident light metering can be implemented on iOS. + +## Volume buttons action +This can be [implemented](https://stackoverflow.com/questions/70161271/ios-override-hardware-volume-buttons-same-as-zello) but the app will be rejected due to [2.5.9](https://developer.apple.com/app-store/review/guidelines/#software-requirements) \ No newline at end of file diff --git a/lib/data/volume_events_service.dart b/lib/data/volume_events_service.dart new file mode 100644 index 0000000..f43e41b --- /dev/null +++ b/lib/data/volume_events_service.dart @@ -0,0 +1,27 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +class VolumeEventsService { + @visibleForTesting + static const volumeHandlingChannel = MethodChannel("com.vodemn.lightmeter/volumeHandling"); + + @visibleForTesting + static const volumeEventsChannel = EventChannel("com.vodemn.lightmeter/volumeEvents"); + + const VolumeEventsService(); + + /// Returns current status of volume handling + Future setVolumeHandling(bool enableHandling) async { + return volumeHandlingChannel + .invokeMethod("setVolumeHandling", enableHandling) + .then((value) => value!); + } + + /// Emits new events on + /// KEYCODE_VOLUME_UP = 24; + /// KEYCODE_VOLUME_DOWN = 25; + /// pressed + Stream volumeButtonsEventStream() { + return volumeEventsChannel.receiveBroadcastStream().cast(); + } +} diff --git a/test/data/volume_events_service_test.dart b/test/data/volume_events_service_test.dart new file mode 100644 index 0000000..8566d3a --- /dev/null +++ b/test/data/volume_events_service_test.dart @@ -0,0 +1,44 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:lightmeter/data/volume_events_service.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + late VolumeEventsService service; + Future? methodCallSuccessHandler(MethodCall methodCall) async { + switch (methodCall.method) { + case "setVolumeHandling": + return methodCall.arguments as bool; + default: + throw UnimplementedError(); + } + } + + setUp(() { + service = const VolumeEventsService(); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + VolumeEventsService.volumeHandlingChannel, + methodCallSuccessHandler, + ); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + VolumeEventsService.volumeHandlingChannel, + null, + ); + }); + + group('setVolumeHandling', () { + test('true', () async => expectLater(service.setVolumeHandling(true), completion(true))); + + test('false', () async => expectLater(service.setVolumeHandling(false), completion(false))); + }); + + group('volumeButtonsEventStream', () { + test('true', () async => expectLater(service.setVolumeHandling(true), completion(true))); + + test('false', () async => expectLater(service.setVolumeHandling(false), completion(false))); + }); +}