From 02e2803d971ee54765cba8f9184b74aae3e9055b Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 3 Apr 2023 20:05:48 +0300 Subject: [PATCH] implemented `MeteringScreenLayoutFeaturesDialog` --- lib/l10n/intl_en.arb | 4 + lib/providers/features_provider.dart | 31 +++++--- .../widget_container_camera.dart | 10 ++- .../widget_container_readings.dart | 10 ++- ...ialog_metering_screen_layout_features.dart | 75 +++++++++++++++++++ ...dget_list_tile_metering_screen_layout.dart | 22 ++++++ .../widget_settings_section_metering.dart | 2 + 7 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart create mode 100644 lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 4a2b65a..9e23b89 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -34,6 +34,10 @@ "calibrationMessageCameraOnly": "The accuracy of the readings measured by this application depends entirely on the rear camera of the device. Therefore, consider testing this application and setting up an EV calibration value that will give you the desired measurement results.", "camera": "Camera", "lightSensor": "Light sensor", + "meteringScreenLayout": "Metering screen layout", + "meteringScreenLayoutHint": "Hide elements on the metering screen that you don't need so that they don't waste exposure pairs list space.", + "meteringScreenFeatureExtremeExposurePairs": "Extreme exposure pairs", + "meteringScreenFeatureFilmPicker": "Film picker", "film": "Film", "equipment": "Equipment", "equipmentProfileName": "Equipment profile name", diff --git a/lib/providers/features_provider.dart b/lib/providers/features_provider.dart index 319063e..2c11b25 100644 --- a/lib/providers/features_provider.dart +++ b/lib/providers/features_provider.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -enum MeteringScreenLayoutFeature { extremeExposurePairs, reciprocity } +enum MeteringScreenLayoutFeature { extremeExposurePairs, filmPicker } class MeteringScreenLayoutProvider extends StatefulWidget { final Widget child; @@ -18,24 +18,26 @@ class MeteringScreenLayoutProvider extends StatefulWidget { class MeteringScreenLayoutProviderState extends State { final Map _features = { MeteringScreenLayoutFeature.extremeExposurePairs: true, - MeteringScreenLayoutFeature.reciprocity: true, + MeteringScreenLayoutFeature.filmPicker: true, }; @override Widget build(BuildContext context) { return MeteringScreenLayout( - features: _features, + features: Map.from(_features), child: widget.child, ); } - void setFeature(MeteringScreenLayoutFeature feature, {required bool enabled}) { + void updateFeatures(Map features) { setState(() { - _features.update( - feature, - (_) => enabled, - ifAbsent: () => enabled, - ); + features.forEach((key, value) { + _features.update( + key, + (_) => value, + ifAbsent: () => value, + ); + }); }); } } @@ -49,14 +51,19 @@ class MeteringScreenLayout extends InheritedModel { super.key, }); - static bool of(BuildContext context, MeteringScreenLayoutFeature feature, {bool listen = true}) { + static Map of(BuildContext context, {bool listen = true}) { if (listen) { - return context.dependOnInheritedWidgetOfExactType()!.features[feature]!; + return context.dependOnInheritedWidgetOfExactType()!.features; } else { - return context.findAncestorWidgetOfExactType()!.features[feature]!; + return context.findAncestorWidgetOfExactType()!.features; } } + static bool featureStatusOf(BuildContext context, MeteringScreenLayoutFeature feature) { + return InheritedModel.inheritFrom(context, aspect: feature)! + .features[feature]!; + } + @override bool updateShouldNotify(MeteringScreenLayout oldWidget) => true; diff --git a/lib/screens/metering/components/camera_container/widget_container_camera.dart b/lib/screens/metering/components/camera_container/widget_container_camera.dart index d5b5827..0a62cd6 100644 --- a/lib/screens/metering/components/camera_container/widget_container_camera.dart +++ b/lib/screens/metering/components/camera_container/widget_container_camera.dart @@ -56,11 +56,17 @@ class CameraContainer extends StatelessWidget { topBarOverflow += Dimens.readingContainerSingleValueHeight; topBarOverflow += Dimens.paddingS; } - if (MeteringScreenLayout.of(context, MeteringScreenLayoutFeature.extremeExposurePairs)) { + if (MeteringScreenLayout.featureStatusOf( + context, + MeteringScreenLayoutFeature.extremeExposurePairs, + )) { topBarOverflow += Dimens.readingContainerDoubleValueHeight; topBarOverflow += Dimens.paddingS; } - if (MeteringScreenLayout.of(context, MeteringScreenLayoutFeature.reciprocity)) { + if (MeteringScreenLayout.featureStatusOf( + context, + MeteringScreenLayoutFeature.filmPicker, + )) { topBarOverflow += Dimens.readingContainerSingleValueHeight; topBarOverflow += Dimens.paddingS; } diff --git a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart index 39427dd..dc8a5f7 100644 --- a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart +++ b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart @@ -43,7 +43,10 @@ class ReadingsContainer extends StatelessWidget { const _EquipmentProfilePicker(), const _InnerPadding(), ], - if (MeteringScreenLayout.of(context, MeteringScreenLayoutFeature.extremeExposurePairs)) ...[ + if (MeteringScreenLayout.featureStatusOf( + context, + MeteringScreenLayoutFeature.extremeExposurePairs, + )) ...[ ReadingValueContainer( values: [ ReadingValue( @@ -58,7 +61,10 @@ class ReadingsContainer extends StatelessWidget { ), const _InnerPadding(), ], - if (MeteringScreenLayout.of(context, MeteringScreenLayoutFeature.reciprocity)) ...[ + if (MeteringScreenLayout.featureStatusOf( + context, + MeteringScreenLayoutFeature.filmPicker, + )) ...[ _FilmPicker( values: Film.values, selectedValue: film, diff --git a/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart b/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart new file mode 100644 index 0000000..c37b72d --- /dev/null +++ b/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/providers/features_provider.dart'; +import 'package:lightmeter/res/dimens.dart'; + +class MeteringScreenLayoutFeaturesDialog extends StatefulWidget { + const MeteringScreenLayoutFeaturesDialog({super.key}); + + @override + State createState() => + _MeteringScreenLayoutFeaturesDialogState(); +} + +class _MeteringScreenLayoutFeaturesDialogState extends State { + late final _features = + Map.from(MeteringScreenLayout.of(context, listen: false)); + + @override + Widget build(BuildContext context) { + return AlertDialog( + icon: const Icon(Icons.layers_outlined), + titlePadding: Dimens.dialogIconTitlePadding, + title: Text(S.of(context).meteringScreenLayout), + contentPadding: EdgeInsets.zero, + content: SizedBox( + width: double.maxFinite, + child: ListView( + shrinkWrap: true, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL), + child: Text(S.of(context).meteringScreenLayoutHint), + ), + const SizedBox(height: Dimens.grid16), + ...MeteringScreenLayoutFeature.values.map( + (f) => SwitchListTile( + contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left), + title: Text(_toStringLocalized(context, f)), + value: _features[f]!, + onChanged: (value) { + setState(() { + _features.update(f, (_) => value); + }); + }, + ), + ), + ], + ), + ), + actionsPadding: Dimens.dialogActionsPadding, + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text(S.of(context).cancel), + ), + TextButton( + onPressed: () { + MeteringScreenLayoutProvider.of(context).updateFeatures(_features); + Navigator.of(context).pop(); + }, + child: Text(S.of(context).save), + ), + ], + ); + } + + String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) { + switch (feature) { + case MeteringScreenLayoutFeature.extremeExposurePairs: + return S.of(context).meteringScreenFeatureExtremeExposurePairs; + case MeteringScreenLayoutFeature.filmPicker: + return S.of(context).meteringScreenFeatureFilmPicker; + } + } +} diff --git a/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart new file mode 100644 index 0000000..9823366 --- /dev/null +++ b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/generated/l10n.dart'; + +import 'components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart'; + +class MeteringScreenLayoutListTile extends StatelessWidget { + const MeteringScreenLayoutListTile({super.key}); + + @override + Widget build(BuildContext context) { + return ListTile( + leading: const Icon(Icons.layers_outlined), + title: Text(S.of(context).meteringScreenLayout), + onTap: () { + showDialog( + context: context, + builder: (_) => const MeteringScreenLayoutFeaturesDialog(), + ); + }, + ); + } +} diff --git a/lib/screens/settings/components/metering/widget_settings_section_metering.dart b/lib/screens/settings/components/metering/widget_settings_section_metering.dart index 45e057a..495c57f 100644 --- a/lib/screens/settings/components/metering/widget_settings_section_metering.dart +++ b/lib/screens/settings/components/metering/widget_settings_section_metering.dart @@ -4,6 +4,7 @@ import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/screens/settings/components/shared/settings_section/widget_settings_section.dart'; import 'components/calibration/widget_list_tile_calibration.dart'; +import 'components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart'; import 'components/equipment_profiles/widget_list_tile_equipment_profiles.dart'; import 'components/fractional_stops/widget_list_tile_fractional_stops.dart'; @@ -17,6 +18,7 @@ class MeteringSettingsSection extends StatelessWidget { children: const [ StopTypeListTile(), CalibrationListTile(), + MeteringScreenLayoutListTile(), if (FeaturesConfig.equipmentProfilesEnabled) EquipmentProfilesListTile(), ], );