enable focal length feature by default

This commit is contained in:
Vadim 2025-05-12 16:04:24 +02:00
parent eb90123a26
commit 10794258b8
4 changed files with 26 additions and 30 deletions

View file

@ -7,8 +7,20 @@ enum CameraFeature {
typedef CameraFeaturesConfig = Map<CameraFeature, bool>;
extension CameraFeaturesConfigJson on CameraFeaturesConfig {
static CameraFeaturesConfig fromJson(Map<String, dynamic> data) =>
<CameraFeature, bool>{for (final f in CameraFeature.values) f: data[f.name] as bool? ?? false};
static CameraFeaturesConfig fromJson(Map<String, dynamic> data) {
MapEntry<CameraFeature, bool> 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<String, dynamic> toJson() => map((key, value) => MapEntry(key.name, value));
}

View file

@ -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<String, dynamic>,
);
} else {
return {
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.extremeExposurePairs: true,
MeteringScreenLayoutFeature.filmPicker: true,
};
}
final configJson = _sharedPreferences.getString(meteringScreenLayoutKey) ?? '{}';
return MeteringScreenLayoutConfigJson.fromJson(json.decode(configJson) as Map<String, dynamic>);
}
set meteringScreenLayout(MeteringScreenLayoutConfig value) =>
_sharedPreferences.setString(meteringScreenLayoutKey, json.encode(value.toJson()));
CameraFeaturesConfig get cameraFeatures {
final configJson = _sharedPreferences.getString(cameraFeaturesKey);
if (configJson != null) {
final configJson = _sharedPreferences.getString(cameraFeaturesKey) ?? '{}';
return CameraFeaturesConfigJson.fromJson(json.decode(configJson) as Map<String, dynamic>);
} else {
return {
CameraFeature.spotMetering: false,
CameraFeature.histogram: false,
CameraFeature.showFocalLength: false,
};
}
}
set cameraFeatures(CameraFeaturesConfig value) =>

View file

@ -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,
},
);
});

View file

@ -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,
},
);
});