From bf37d1a1d25ca5d2352f9bd828ce7035b5c6aa62 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 9 Jul 2023 13:10:58 +0200 Subject: [PATCH] removed `VolumeAction.zoom` --- lib/data/models/volume_action.dart | 2 +- lib/l10n/intl_en.arb | 4 +- lib/l10n/intl_fr.arb | 4 +- lib/l10n/intl_ru.arb | 4 +- .../bloc_container_camera.dart | 18 --- .../provider_container_camera.dart | 2 - .../bloc_list_tile_volume_actions.dart | 8 +- .../widget_list_tile_volume_actions.dart | 40 +----- test/screens/metering/bloc_metering_test.dart | 13 -- .../camera/bloc_container_camera_test.dart | 124 ------------------ 10 files changed, 15 insertions(+), 204 deletions(-) diff --git a/lib/data/models/volume_action.dart b/lib/data/models/volume_action.dart index 0ab98e8..b28f9dc 100644 --- a/lib/data/models/volume_action.dart +++ b/lib/data/models/volume_action.dart @@ -1,3 +1,3 @@ -enum VolumeAction { shutter, zoom, none } +enum VolumeAction { shutter, none } enum VolumeKey { up, down } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 61a682d..39700b8 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -56,9 +56,7 @@ "general": "General", "keepScreenOn": "Keep screen on", "haptics": "Haptics", - "volumeKeysAction": "Volume keys action", - "shutter": "Shutter", - "zoom": "Zoom", + "volumeKeysAction": "Shutter by volume keys", "language": "Language", "chooseLanguage": "Choose language", "theme": "Theme", diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 46dff93..5957d0d 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -56,9 +56,7 @@ "general": "Général", "keepScreenOn": "Garder l'écran allumé", "haptics": "Haptiques", - "volumeKeysAction": "Action des touches de volume", - "shutter": "Obturateur", - "zoom": "Zoom", + "volumeKeysAction": "Obturateur par boutons de volume", "language": "Langue", "chooseLanguage": "Choisissez la langue", "theme": "Thème", diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index d61529f..f6b3833 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -56,9 +56,7 @@ "general": "Общие", "keepScreenOn": "Запрет блокировки", "haptics": "Вибрация", - "volumeKeysAction": "Кнопки регулировки громкости", - "shutter": "Затвор", - "zoom": "Зум", + "volumeKeysAction": "Затвор по кнопкам громкости", "language": "Язык", "chooseLanguage": "Выберите язык", "theme": "Тема", 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 aa0aa2e..8868f7e 100644 --- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart +++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart @@ -8,7 +8,6 @@ import 'package:camera/camera.dart'; import 'package:exif/exif.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:lightmeter/data/models/volume_action.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' @@ -19,12 +18,10 @@ import 'package:lightmeter/screens/metering/components/camera_container/event_co import 'package:lightmeter/screens/metering/components/camera_container/models/camera_error_type.dart'; import 'package:lightmeter/screens/metering/components/camera_container/state_container_camera.dart'; import 'package:lightmeter/screens/metering/components/shared/ev_source_base/bloc_base_ev_source.dart'; -import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart'; import 'package:lightmeter/utils/log_2.dart'; class CameraContainerBloc extends EvSourceBlocBase { final MeteringInteractor _meteringInteractor; - final VolumeKeysNotifier _volumeKeysNotifier; late final _WidgetsBindingObserver _observer; CameraController? _cameraController; @@ -44,13 +41,11 @@ class CameraContainerBloc extends EvSourceBlocBase close() async { WidgetsBinding.instance.removeObserver(_observer); - _volumeKeysNotifier.removeListener(onVolumeKey); unawaited(_cameraController?.dispose().then((_) => _cameraController = null)); communicationBloc.add(communication_event.MeteringEndedEvent(_ev100)); return super.close(); @@ -245,18 +239,6 @@ class CameraContainerBloc extends EvSourceBlocBase CameraContainerBloc( context.get(), - context.get(), context.read(), )..add(const RequestPermissionEvent()), child: CameraContainer( diff --git a/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart b/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart index 7af8fb5..a8b8e3e 100644 --- a/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart +++ b/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart @@ -2,15 +2,15 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/volume_action.dart'; import 'package:lightmeter/interactors/settings_interactor.dart'; -class VolumeActionsListTileBloc extends Cubit { +class VolumeActionsListTileBloc extends Cubit { final SettingsInteractor _settingsInteractor; VolumeActionsListTileBloc( this._settingsInteractor, - ) : super(_settingsInteractor.volumeAction); + ) : super(_settingsInteractor.volumeAction == VolumeAction.shutter); - void onVolumeActionChanged(VolumeAction value) { - _settingsInteractor.setVolumeAction(value); + void onVolumeActionChanged(bool value) { + _settingsInteractor.setVolumeAction(value ? VolumeAction.shutter : VolumeAction.none); // while in settings we allow system to handle volume // so that volume keys action works only when necessary - on the metering screen diff --git a/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart b/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart index 232c610..0502b60 100644 --- a/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart +++ b/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart @@ -1,48 +1,22 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:lightmeter/data/models/volume_action.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart'; -import 'package:lightmeter/screens/settings/components/shared/dialog_picker.dart/widget_dialog_picker.dart'; class VolumeActionsListTile extends StatelessWidget { const VolumeActionsListTile({super.key}); @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) => ListTile( - leading: const Icon(Icons.volume_up), + return BlocBuilder( + builder: (context, state) => SwitchListTile( + secondary: const Icon(Icons.volume_up), title: Text(S.of(context).volumeKeysAction), - trailing: Text(actionToString(context, state)), - onTap: () { - showDialog( - context: context, - builder: (_) => DialogPicker( - icon: Icons.volume_up, - title: S.of(context).volumeKeysAction, - selectedValue: state, - values: VolumeAction.values, - titleAdapter: (context, value) => actionToString(context, value), - ), - ).then((value) { - if (value != null) { - context.read().onVolumeActionChanged(value); - } - }); - }, + value: state, + onChanged: context.read().onVolumeActionChanged, + contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM), ), ); } - - String actionToString(BuildContext context, VolumeAction themeType) { - switch (themeType) { - case VolumeAction.shutter: - return S.of(context).shutter; - case VolumeAction.zoom: - return S.of(context).zoom; - case VolumeAction.none: - return S.of(context).none; - } - } } diff --git a/test/screens/metering/bloc_metering_test.dart b/test/screens/metering/bloc_metering_test.dart index 121d103..3593c91 100644 --- a/test/screens/metering/bloc_metering_test.dart +++ b/test/screens/metering/bloc_metering_test.dart @@ -641,19 +641,6 @@ void main() { expect: () => [isA()], ); - blocTest( - 'onVolumeKey & VolumeAction.zoom', - build: () => bloc, - act: (bloc) async { - bloc.onVolumeKey(); - }, - setUp: () { - when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.zoom); - }, - verify: (_) {}, - expect: () => [], - ); - blocTest( 'onVolumeKey & VolumeAction.none', build: () => bloc, 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 1264082..298d5b8 100644 --- a/test/screens/metering/components/camera/bloc_container_camera_test.dart +++ b/test/screens/metering/components/camera/bloc_container_camera_test.dart @@ -2,7 +2,6 @@ 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/models/volume_action.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' @@ -13,13 +12,10 @@ import 'package:lightmeter/screens/metering/components/camera_container/bloc_con import 'package:lightmeter/screens/metering/components/camera_container/event_container_camera.dart'; import 'package:lightmeter/screens/metering/components/camera_container/models/camera_error_type.dart'; import 'package:lightmeter/screens/metering/components/camera_container/state_container_camera.dart'; -import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart'; import 'package:mocktail/mocktail.dart'; class _MockMeteringInteractor extends Mock implements MeteringInteractor {} -class _MockVolumeKeysNotifier extends Mock implements VolumeKeysNotifier {} - class _MockMeteringCommunicationBloc extends MockBloc< communication_events.MeteringCommunicationEvent, communication_states.MeteringCommunicationState> implements MeteringCommunicationBloc {} @@ -28,7 +24,6 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); late _MockMeteringInteractor meteringInteractor; - late _MockVolumeKeysNotifier volumeKeysNotifier; late _MockMeteringCommunicationBloc communicationBloc; late CameraContainerBloc bloc; @@ -117,7 +112,6 @@ void main() { setUpAll(() { meteringInteractor = _MockMeteringInteractor(); - volumeKeysNotifier = _MockVolumeKeysNotifier(); communicationBloc = _MockMeteringCommunicationBloc(); when(() => meteringInteractor.cameraEvCalibration).thenReturn(0.0); @@ -127,7 +121,6 @@ void main() { setUp(() { bloc = CameraContainerBloc( meteringInteractor, - volumeKeysNotifier, communicationBloc, ); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger @@ -483,123 +476,6 @@ void main() { ); }, ); - - group( - '`Volume keys shutter action`', - () { - blocTest( - 'Add/remove listener', - build: () => bloc, - verify: (_) { - verify(() => volumeKeysNotifier.addListener(bloc.onVolumeKey)).called(1); - verify(() => volumeKeysNotifier.removeListener(bloc.onVolumeKey)).called(1); - }, - expect: () => [], - ); - - blocTest( - 'onVolumeKey & VolumeAction.shutter', - build: () => bloc, - act: (bloc) async { - bloc.onVolumeKey(); - }, - setUp: () { - when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.shutter); - }, - verify: (_) {}, - expect: () => [], - ); - - blocTest( - 'onVolumeKey.up & VolumeAction.zoom', - build: () => bloc, - act: (bloc) async { - bloc.add(const InitializeEvent()); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - }, - setUp: () { - when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true); - when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.zoom); - when(() => volumeKeysNotifier.value).thenReturn(VolumeKey.up); - }, - verify: (_) {}, - expect: () => [ - ...initializedStateSequence, - isA() - .having((state) => state.zoomRange, 'zoomRange', const RangeValues(1.0, 7.0)) - .having((state) => state.currentZoom, 'currentZoom', 1.5) - .having( - (state) => state.exposureOffsetRange, - 'exposureOffsetRange', - const RangeValues(-4.0, 4.0), - ) - .having((state) => state.exposureOffsetStep, 'exposureOffsetStep', 0.1666666) - .having((state) => state.currentExposureOffset, 'currentExposureOffset', 0.0), - isA() - .having((state) => state.zoomRange, 'zoomRange', const RangeValues(1.0, 7.0)) - .having((state) => state.currentZoom, 'currentZoom', 2.0) - .having( - (state) => state.exposureOffsetRange, - 'exposureOffsetRange', - const RangeValues(-4.0, 4.0), - ) - .having((state) => state.exposureOffsetStep, 'exposureOffsetStep', 0.1666666) - .having((state) => state.currentExposureOffset, 'currentExposureOffset', 0.0), - isA() - .having((state) => state.zoomRange, 'zoomRange', const RangeValues(1.0, 7.0)) - .having((state) => state.currentZoom, 'currentZoom', 2.5) - .having( - (state) => state.exposureOffsetRange, - 'exposureOffsetRange', - const RangeValues(-4.0, 4.0), - ) - .having((state) => state.exposureOffsetStep, 'exposureOffsetStep', 0.1666666) - .having((state) => state.currentExposureOffset, 'currentExposureOffset', 0.0), - ], - ); - - blocTest( - 'onVolumeKey.down & VolumeAction.zoom', - build: () => bloc, - act: (bloc) async { - bloc.add(const InitializeEvent()); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - await Future.delayed(Duration.zero); - bloc.onVolumeKey(); - }, - setUp: () { - when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true); - when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.zoom); - when(() => volumeKeysNotifier.value).thenReturn(VolumeKey.down); - }, - verify: (_) {}, - expect: () => [ - ...initializedStateSequence, - ], - ); - - blocTest( - 'onVolumeKey & VolumeAction.none', - build: () => bloc, - act: (bloc) async { - bloc.onVolumeKey(); - }, - setUp: () { - when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.none); - }, - verify: (_) {}, - expect: () => [], - ); - }, - ); } extension _MethodChannelMock on MethodChannel {