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>; typedef CameraFeaturesConfig = Map<CameraFeature, bool>;
extension CameraFeaturesConfigJson on CameraFeaturesConfig { extension CameraFeaturesConfigJson on CameraFeaturesConfig {
static CameraFeaturesConfig fromJson(Map<String, dynamic> data) => static CameraFeaturesConfig fromJson(Map<String, dynamic> data) {
<CameraFeature, bool>{for (final f in CameraFeature.values) f: data[f.name] as bool? ?? false}; 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)); 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); 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) { return MeteringScreenLayoutConfigJson.fromJson(json.decode(configJson) as Map<String, dynamic>);
return MeteringScreenLayoutConfigJson.fromJson(
json.decode(configJson) as Map<String, dynamic>,
);
} else {
return {
MeteringScreenLayoutFeature.equipmentProfiles: true,
MeteringScreenLayoutFeature.extremeExposurePairs: true,
MeteringScreenLayoutFeature.filmPicker: true,
};
}
} }
set meteringScreenLayout(MeteringScreenLayoutConfig value) => set meteringScreenLayout(MeteringScreenLayoutConfig value) =>
_sharedPreferences.setString(meteringScreenLayoutKey, json.encode(value.toJson())); _sharedPreferences.setString(meteringScreenLayoutKey, json.encode(value.toJson()));
CameraFeaturesConfig get cameraFeatures { CameraFeaturesConfig get cameraFeatures {
final configJson = _sharedPreferences.getString(cameraFeaturesKey); final configJson = _sharedPreferences.getString(cameraFeaturesKey) ?? '{}';
if (configJson != null) { return CameraFeaturesConfigJson.fromJson(json.decode(configJson) as Map<String, dynamic>);
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) => set cameraFeatures(CameraFeaturesConfig value) =>

View file

@ -22,13 +22,13 @@ void main() {
); );
}); });
test('Legacy (no spotMetering & histogram)', () { test('Legacy', () {
expect( expect(
CameraFeaturesConfigJson.fromJson({}), CameraFeaturesConfigJson.fromJson({}),
{ {
CameraFeature.spotMetering: false, CameraFeature.spotMetering: true,
CameraFeature.histogram: false, CameraFeature.histogram: false,
CameraFeature.showFocalLength: false, CameraFeature.showFocalLength: true,
}, },
); );
}); });
@ -40,10 +40,12 @@ void main() {
{ {
CameraFeature.spotMetering: true, CameraFeature.spotMetering: true,
CameraFeature.histogram: true, CameraFeature.histogram: true,
CameraFeature.showFocalLength: true,
}.toJson(), }.toJson(),
{ {
'spotMetering': true, 'spotMetering': true,
'histogram': true, 'histogram': true,
'showFocalLength': true,
}, },
); );
}); });

View file

@ -270,9 +270,9 @@ void main() {
expect( expect(
service.cameraFeatures, service.cameraFeatures,
{ {
CameraFeature.spotMetering: false, CameraFeature.spotMetering: true,
CameraFeature.histogram: false, CameraFeature.histogram: false,
CameraFeature.showFocalLength: false, CameraFeature.showFocalLength: true,
}, },
); );
}); });
@ -285,7 +285,7 @@ void main() {
{ {
CameraFeature.spotMetering: false, CameraFeature.spotMetering: false,
CameraFeature.histogram: true, CameraFeature.histogram: true,
CameraFeature.showFocalLength: false, CameraFeature.showFocalLength: true,
}, },
); );
}); });