From 10794258b8e4a5db558c40ea92347336e4ab0f85 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 12 May 2025 16:04:24 +0200 Subject: [PATCH] enable focal length feature by default --- lib/data/models/camera_feature.dart | 16 ++++++++++-- lib/data/shared_prefs_service.dart | 26 +++---------------- .../models/camera_features_config_test.dart | 8 +++--- test/data/shared_prefs_service_test.dart | 6 ++--- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lib/data/models/camera_feature.dart b/lib/data/models/camera_feature.dart index 59f2db0..1f7c086 100644 --- a/lib/data/models/camera_feature.dart +++ b/lib/data/models/camera_feature.dart @@ -7,8 +7,20 @@ enum CameraFeature { typedef CameraFeaturesConfig = Map; extension CameraFeaturesConfigJson on CameraFeaturesConfig { - static CameraFeaturesConfig fromJson(Map data) => - {for (final f in CameraFeature.values) f: data[f.name] as bool? ?? false}; + static CameraFeaturesConfig fromJson(Map data) { + MapEntry valueOrBool(CameraFeature feature, {bool defaultValue = true}) => MapEntry( + feature, + data[feature.name] as bool? ?? defaultValue, + ); + + return Map.fromEntries( + [ + valueOrBool(CameraFeature.spotMetering), + valueOrBool(CameraFeature.histogram, defaultValue: false), + valueOrBool(CameraFeature.showFocalLength), + ], + ); + } Map toJson() => map((key, value) => MapEntry(key.name, value)); } diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart index bfb91fc..e1144bf 100644 --- a/lib/data/shared_prefs_service.dart +++ b/lib/data/shared_prefs_service.dart @@ -94,34 +94,16 @@ class UserPreferencesService { set showEv100(bool value) => _sharedPreferences.setBool(showEv100Key, value); MeteringScreenLayoutConfig get meteringScreenLayout { - final configJson = _sharedPreferences.getString(meteringScreenLayoutKey); - if (configJson != null) { - return MeteringScreenLayoutConfigJson.fromJson( - json.decode(configJson) as Map, - ); - } else { - return { - MeteringScreenLayoutFeature.equipmentProfiles: true, - MeteringScreenLayoutFeature.extremeExposurePairs: true, - MeteringScreenLayoutFeature.filmPicker: true, - }; - } + final configJson = _sharedPreferences.getString(meteringScreenLayoutKey) ?? '{}'; + return MeteringScreenLayoutConfigJson.fromJson(json.decode(configJson) as Map); } set meteringScreenLayout(MeteringScreenLayoutConfig value) => _sharedPreferences.setString(meteringScreenLayoutKey, json.encode(value.toJson())); CameraFeaturesConfig get cameraFeatures { - final configJson = _sharedPreferences.getString(cameraFeaturesKey); - if (configJson != null) { - return CameraFeaturesConfigJson.fromJson(json.decode(configJson) as Map); - } else { - return { - CameraFeature.spotMetering: false, - CameraFeature.histogram: false, - CameraFeature.showFocalLength: false, - }; - } + final configJson = _sharedPreferences.getString(cameraFeaturesKey) ?? '{}'; + return CameraFeaturesConfigJson.fromJson(json.decode(configJson) as Map); } set cameraFeatures(CameraFeaturesConfig value) => diff --git a/test/data/models/camera_features_config_test.dart b/test/data/models/camera_features_config_test.dart index 53264c4..ceed378 100644 --- a/test/data/models/camera_features_config_test.dart +++ b/test/data/models/camera_features_config_test.dart @@ -22,13 +22,13 @@ void main() { ); }); - test('Legacy (no spotMetering & histogram)', () { + test('Legacy', () { expect( CameraFeaturesConfigJson.fromJson({}), { - CameraFeature.spotMetering: false, + CameraFeature.spotMetering: true, CameraFeature.histogram: false, - CameraFeature.showFocalLength: false, + CameraFeature.showFocalLength: true, }, ); }); @@ -40,10 +40,12 @@ void main() { { CameraFeature.spotMetering: true, CameraFeature.histogram: true, + CameraFeature.showFocalLength: true, }.toJson(), { 'spotMetering': true, 'histogram': true, + 'showFocalLength': true, }, ); }); diff --git a/test/data/shared_prefs_service_test.dart b/test/data/shared_prefs_service_test.dart index 67855cf..0ee45a9 100644 --- a/test/data/shared_prefs_service_test.dart +++ b/test/data/shared_prefs_service_test.dart @@ -270,9 +270,9 @@ void main() { expect( service.cameraFeatures, { - CameraFeature.spotMetering: false, + CameraFeature.spotMetering: true, CameraFeature.histogram: false, - CameraFeature.showFocalLength: false, + CameraFeature.showFocalLength: true, }, ); }); @@ -285,7 +285,7 @@ void main() { { CameraFeature.spotMetering: false, CameraFeature.histogram: true, - CameraFeature.showFocalLength: false, + CameraFeature.showFocalLength: true, }, ); });