added showEV100 to user preferences

This commit is contained in:
Vadim 2024-01-15 14:03:24 +01:00
parent 73d0c32323
commit 33f1a84910
4 changed files with 62 additions and 0 deletions

View file

@ -16,6 +16,7 @@ class UserPreferencesService {
static const evSourceTypeKey = "evSourceType"; static const evSourceTypeKey = "evSourceType";
static const stopTypeKey = "stopType"; static const stopTypeKey = "stopType";
static const showEv100Key = "showEv100";
static const cameraEvCalibrationKey = "cameraEvCalibration"; static const cameraEvCalibrationKey = "cameraEvCalibration";
static const lightSensorEvCalibrationKey = "lightSensorEvCalibration"; static const lightSensorEvCalibrationKey = "lightSensorEvCalibration";
static const meteringScreenLayoutKey = "meteringScreenLayout"; static const meteringScreenLayoutKey = "meteringScreenLayout";
@ -84,6 +85,9 @@ class UserPreferencesService {
StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2]; StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2];
set stopType(StopType value) => _sharedPreferences.setInt(stopTypeKey, value.index); set stopType(StopType value) => _sharedPreferences.setInt(stopTypeKey, value.index);
bool get showEv100 => _sharedPreferences.getBool(showEv100Key) ?? false;
set showEv100(bool value) => _sharedPreferences.setBool(showEv100Key, value);
MeteringScreenLayoutConfig get meteringScreenLayout { MeteringScreenLayoutConfig get meteringScreenLayout {
final configJson = _sharedPreferences.getString(meteringScreenLayoutKey); final configJson = _sharedPreferences.getString(meteringScreenLayoutKey);
if (configJson != null) { if (configJson != null) {

View file

@ -53,6 +53,10 @@ class UserPreferencesProvider extends StatefulWidget {
return _inheritFromEnumsModel(context, _Aspect.stopType).stopType; return _inheritFromEnumsModel(context, _Aspect.stopType).stopType;
} }
static bool showEv100Of(BuildContext context) {
return _inheritFromEnumsModel(context, _Aspect.showEv100).showEv100;
}
static CameraFeaturesConfig cameraConfigOf(BuildContext context) { static CameraFeaturesConfig cameraConfigOf(BuildContext context) {
return context.findAncestorWidgetOfExactType<_CameraFeaturesModel>()!.data; return context.findAncestorWidgetOfExactType<_CameraFeaturesModel>()!.data;
} }
@ -83,6 +87,7 @@ class UserPreferencesProvider extends StatefulWidget {
class _UserPreferencesProviderState extends State<UserPreferencesProvider> with WidgetsBindingObserver { class _UserPreferencesProviderState extends State<UserPreferencesProvider> with WidgetsBindingObserver {
late EvSourceType _evSourceType; late EvSourceType _evSourceType;
late StopType _stopType = widget.userPreferencesService.stopType; late StopType _stopType = widget.userPreferencesService.stopType;
late bool _showEv100 = widget.userPreferencesService.showEv100;
late MeteringScreenLayoutConfig _meteringScreenLayout = widget.userPreferencesService.meteringScreenLayout; late MeteringScreenLayoutConfig _meteringScreenLayout = widget.userPreferencesService.meteringScreenLayout;
late CameraFeaturesConfig _cameraFeatures = widget.userPreferencesService.cameraFeatures; late CameraFeaturesConfig _cameraFeatures = widget.userPreferencesService.cameraFeatures;
late SupportedLocale _locale = widget.userPreferencesService.locale; late SupportedLocale _locale = widget.userPreferencesService.locale;
@ -135,6 +140,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider> with
evSourceType: _evSourceType, evSourceType: _evSourceType,
locale: _locale, locale: _locale,
primaryColor: dynamicPrimaryColor ?? _primaryColor, primaryColor: dynamicPrimaryColor ?? _primaryColor,
showEv100: _showEv100,
stopType: _stopType, stopType: _stopType,
themeType: _themeType, themeType: _themeType,
child: _MeteringScreenLayoutModel( child: _MeteringScreenLayoutModel(
@ -201,6 +207,13 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider> with
widget.userPreferencesService.primaryColor = primaryColor; widget.userPreferencesService.primaryColor = primaryColor;
} }
void toggleShowEV100() {
setState(() {
_showEv100 = !_showEv100;
});
widget.userPreferencesService.showEv100 = _showEv100;
}
void setStopType(StopType stopType) { void setStopType(StopType stopType) {
setState(() { setState(() {
_stopType = stopType; _stopType = stopType;
@ -231,6 +244,7 @@ enum _Aspect {
dynamicColorState, dynamicColorState,
evSourceType, evSourceType,
locale, locale,
showEv100,
stopType, stopType,
theme, theme,
themeType, themeType,
@ -240,6 +254,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> {
final DynamicColorState dynamicColorState; final DynamicColorState dynamicColorState;
final EvSourceType evSourceType; final EvSourceType evSourceType;
final SupportedLocale locale; final SupportedLocale locale;
final bool showEv100;
final StopType stopType; final StopType stopType;
final ThemeType themeType; final ThemeType themeType;
@ -252,6 +267,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> {
required this.evSourceType, required this.evSourceType,
required this.locale, required this.locale,
required Color primaryColor, required Color primaryColor,
required this.showEv100,
required this.stopType, required this.stopType,
required this.themeType, required this.themeType,
required super.child, required super.child,
@ -267,6 +283,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> {
evSourceType != oldWidget.evSourceType || evSourceType != oldWidget.evSourceType ||
locale != oldWidget.locale || locale != oldWidget.locale ||
_primaryColor != oldWidget._primaryColor || _primaryColor != oldWidget._primaryColor ||
showEv100 != oldWidget.showEv100 ||
stopType != oldWidget.stopType || stopType != oldWidget.stopType ||
themeType != oldWidget.themeType; themeType != oldWidget.themeType;
} }
@ -279,6 +296,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> {
return (dependencies.contains(_Aspect.dynamicColorState) && dynamicColorState != oldWidget.dynamicColorState) || return (dependencies.contains(_Aspect.dynamicColorState) && dynamicColorState != oldWidget.dynamicColorState) ||
(dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) || (dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) ||
(dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) || (dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) ||
(dependencies.contains(_Aspect.showEv100) && showEv100 != oldWidget.showEv100) ||
(dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) || (dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) ||
(dependencies.contains(_Aspect.theme) && (dependencies.contains(_Aspect.theme) &&
(_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) || (_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) ||

View file

@ -181,6 +181,25 @@ void main() {
}); });
}); });
group('showEv100', () {
test('get default', () {
when(() => sharedPreferences.getBool(UserPreferencesService.showEv100Key)).thenReturn(null);
expect(service.showEv100, false);
});
test('get', () {
when(() => sharedPreferences.getBool(UserPreferencesService.showEv100Key)).thenReturn(true);
expect(service.showEv100, true);
});
test('set', () {
when(() => sharedPreferences.setBool(UserPreferencesService.showEv100Key, false))
.thenAnswer((_) => Future.value(true));
service.showEv100 = false;
verify(() => sharedPreferences.setBool(UserPreferencesService.showEv100Key, false)).called(1);
});
});
group('meteringScreenLayout', () { group('meteringScreenLayout', () {
test('get default', () { test('get default', () {
when( when(

View file

@ -164,6 +164,27 @@ void main() {
}, },
); );
testWidgets(
'Toggle EV100',
(tester) async {
when(() => mockUserPreferencesService.showEv100).thenReturn(false);
await pumpTestWidget(
tester,
builder: (context) => ElevatedButton(
onPressed: () => UserPreferencesProvider.of(context).toggleShowEV100(),
child: Text('${UserPreferencesProvider.showEv100Of(context)}'),
),
);
await tester.pumpAndSettle();
expect(find.text("${false}"), findsOneWidget);
await tester.tap(find.text("${false}"));
await tester.pumpAndSettle();
expect(find.text("${true}"), findsOneWidget);
verify(() => mockUserPreferencesService.showEv100 = true).called(1);
},
);
testWidgets( testWidgets(
'Set metering screen layout config', 'Set metering screen layout config',
(tester) async { (tester) async {