From 2b2a5441c79341512784378bba8d63aadd50e3ca Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 15 Jan 2024 22:57:40 +0100 Subject: [PATCH] ML-130 Added ff for the "Pro features" tile on the main screen (#149) * added ff for Pro features tile on main screen --- lib/data/models/feature.dart | 4 +-- lib/data/remote_config_service.dart | 2 +- .../widget_container_camera.dart | 8 ++++-- .../widget_container_readings.dart | 4 ++- .../remote_config_provider_test.dart | 26 +++++++++---------- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/data/models/feature.dart b/lib/data/models/feature.dart index b022db7..429a322 100644 --- a/lib/data/models/feature.dart +++ b/lib/data/models/feature.dart @@ -1,5 +1,5 @@ -enum Feature { unlockProFeaturesText } +enum Feature { showUnlockProOnMainScreen } const featuresDefaultValues = { - Feature.unlockProFeaturesText: true, + Feature.showUnlockProOnMainScreen: false, }; diff --git a/lib/data/remote_config_service.dart b/lib/data/remote_config_service.dart index f8c123b..9bd4051 100644 --- a/lib/data/remote_config_service.dart +++ b/lib/data/remote_config_service.dart @@ -124,7 +124,7 @@ class MockRemoteConfigService implements IRemoteConfigService { extension on RemoteConfigValue { dynamic toValue(Feature feature) { switch (feature) { - case Feature.unlockProFeaturesText: + case Feature.showUnlockProOnMainScreen: return asBool(); } } 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 5ed2b43..3e81d48 100644 --- a/lib/screens/metering/components/camera_container/widget_container_camera.dart +++ b/lib/screens/metering/components/camera_container/widget_container_camera.dart @@ -3,8 +3,10 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/exposure_pair.dart'; +import 'package:lightmeter/data/models/feature.dart'; import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:lightmeter/platform_config.dart'; +import 'package:lightmeter/providers/remote_config_provider.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/metering/components/camera_container/bloc_container_camera.dart'; import 'package:lightmeter/screens/metering/components/camera_container/components/camera_controls/widget_camera_controls.dart'; @@ -103,8 +105,10 @@ class CameraContainer extends StatelessWidget { double _meteringContainerHeight(BuildContext context) { double enabledFeaturesHeight = 0; if (!context.isPro) { - enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight; - enabledFeaturesHeight += Dimens.paddingS; + if (RemoteConfig.isEnabled(context, Feature.showUnlockProOnMainScreen)) { + enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight; + enabledFeaturesHeight += Dimens.paddingS; + } } else { if (context.meteringFeature(MeteringScreenLayoutFeature.equipmentProfiles)) { enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight; 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 ce373a8..1b9a1c4 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 @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/exposure_pair.dart'; +import 'package:lightmeter/data/models/feature.dart'; import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:lightmeter/providers/equipment_profile_provider.dart'; +import 'package:lightmeter/providers/remote_config_provider.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/equipment_profile_picker/widget_picker_equipment_profiles.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/extreme_exposure_pairs_container/widget_container_extreme_exposure_pairs.dart'; @@ -35,7 +37,7 @@ class ReadingsContainer extends StatelessWidget { return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - if (!context.isPro) ...[ + if (!context.isPro && RemoteConfig.isEnabled(context, Feature.showUnlockProOnMainScreen)) ...[ const LightmeterProAnimatedDialog(), const _InnerPadding(), ], diff --git a/test/providers/remote_config_provider_test.dart b/test/providers/remote_config_provider_test.dart index a215cbe..c8d9b03 100644 --- a/test/providers/remote_config_provider_test.dart +++ b/test/providers/remote_config_provider_test.dart @@ -19,8 +19,8 @@ void main() { setUp(() { when(() => mockRemoteConfigService.fetchConfig()).thenAnswer((_) async {}); - when(() => mockRemoteConfigService.getValue(Feature.unlockProFeaturesText)).thenReturn(false); - when(() => mockRemoteConfigService.getAll()).thenReturn({Feature.unlockProFeaturesText: false}); + when(() => mockRemoteConfigService.getValue(Feature.showUnlockProOnMainScreen)).thenReturn(false); + when(() => mockRemoteConfigService.getAll()).thenReturn({Feature.showUnlockProOnMainScreen: false}); }); tearDown(() { @@ -42,7 +42,7 @@ void main() { when(() => mockRemoteConfigService.onConfigUpdated()).thenAnswer((_) => const Stream.empty()); await pumpTestWidget(tester); - expect(find.text('unlockProFeaturesText: false'), findsOneWidget); + expect(find.text('showUnlockProOnMainScreen: false'), findsOneWidget); }, ); @@ -53,34 +53,34 @@ void main() { when(() => mockRemoteConfigService.onConfigUpdated()).thenAnswer((_) => remoteConfigUpdateController.stream); await pumpTestWidget(tester); - expect(find.text('unlockProFeaturesText: false'), findsOneWidget); + expect(find.text('showUnlockProOnMainScreen: false'), findsOneWidget); - when(() => mockRemoteConfigService.getValue(Feature.unlockProFeaturesText)).thenReturn(true); - remoteConfigUpdateController.add({Feature.unlockProFeaturesText}); + when(() => mockRemoteConfigService.getValue(Feature.showUnlockProOnMainScreen)).thenReturn(true); + remoteConfigUpdateController.add({Feature.showUnlockProOnMainScreen}); await tester.pumpAndSettle(); - expect(find.text('unlockProFeaturesText: true'), findsOneWidget); + expect(find.text('showUnlockProOnMainScreen: true'), findsOneWidget); await remoteConfigUpdateController.close(); }, ); test('RemoteConfig.updateShouldNotifyDependent', () { - const config = RemoteConfig(config: {Feature.unlockProFeaturesText: false}, child: SizedBox()); + const config = RemoteConfig(config: {Feature.showUnlockProOnMainScreen: false}, child: SizedBox()); expect( config.updateShouldNotifyDependent(config, {}), false, ); expect( config.updateShouldNotifyDependent( - const RemoteConfig(config: {Feature.unlockProFeaturesText: false}, child: SizedBox()), - {Feature.unlockProFeaturesText}, + const RemoteConfig(config: {Feature.showUnlockProOnMainScreen: false}, child: SizedBox()), + {Feature.showUnlockProOnMainScreen}, ), false, ); expect( config.updateShouldNotifyDependent( - const RemoteConfig(config: {Feature.unlockProFeaturesText: true}, child: SizedBox()), - {Feature.unlockProFeaturesText}, + const RemoteConfig(config: {Feature.showUnlockProOnMainScreen: true}, child: SizedBox()), + {Feature.showUnlockProOnMainScreen}, ), true, ); @@ -96,7 +96,7 @@ class _Application extends StatelessWidget { home: Scaffold( body: Center( child: Text( - "${Feature.unlockProFeaturesText.name}: ${RemoteConfig.isEnabled(context, Feature.unlockProFeaturesText)}", + "${Feature.showUnlockProOnMainScreen.name}: ${RemoteConfig.isEnabled(context, Feature.showUnlockProOnMainScreen)}", ), ), ),