diff --git a/lib/data/models/metering_screen_layout_config.dart b/lib/data/models/metering_screen_layout_config.dart index dffaab4..375d12f 100644 --- a/lib/data/models/metering_screen_layout_config.dart +++ b/lib/data/models/metering_screen_layout_config.dart @@ -1,11 +1,17 @@ -enum MeteringScreenLayoutFeature { equipmentProfiles, extremeExposurePairs, filmPicker } +enum MeteringScreenLayoutFeature { + extremeExposurePairs, + filmPicker, + equipmentProfiles, +} typedef MeteringScreenLayoutConfig = Map; extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig { - static MeteringScreenLayoutConfig fromJson(Map data) => data.map( - (key, value) => MapEntry(MeteringScreenLayoutFeature.values[int.parse(key)], value as bool), - ); + static MeteringScreenLayoutConfig fromJson(Map data) => + { + for (final f in MeteringScreenLayoutFeature.values) + f: data[f.index.toString()] as bool? ?? true + }; Map toJson() => map((key, value) => MapEntry(key.index.toString(), value)); } diff --git a/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart b/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart index 53e8451..a02471e 100644 --- a/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart +++ b/lib/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart @@ -33,18 +33,9 @@ class _MeteringScreenLayoutFeaturesDialogState extends State SwitchListTile( - contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left), - title: Text(_toStringLocalized(context, f)), - value: _features[f]!, - onChanged: (value) { - setState(() { - _features.update(f, (_) => value); - }); - }, - ), - ), + _featureListTile(MeteringScreenLayoutFeature.equipmentProfiles), + _featureListTile(MeteringScreenLayoutFeature.extremeExposurePairs), + _featureListTile(MeteringScreenLayoutFeature.filmPicker), ], ), ), @@ -65,6 +56,19 @@ class _MeteringScreenLayoutFeaturesDialogState extends State value); + }); + }, + ); + } + String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) { switch (feature) { case MeteringScreenLayoutFeature.equipmentProfiles: diff --git a/test/data/models/metering_screen_layout_config_test.dart b/test/data/models/metering_screen_layout_config_test.dart index 53922ae..2dd31aa 100644 --- a/test/data/models/metering_screen_layout_config_test.dart +++ b/test/data/models/metering_screen_layout_config_test.dart @@ -2,30 +2,56 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:test/test.dart'; void main() { - test('fromJson', () { - expect( - MeteringScreenLayoutConfigJson.fromJson({'0': true, '1': true}), - { - MeteringScreenLayoutFeature.extremeExposurePairs: true, - MeteringScreenLayoutFeature.filmPicker: true, - }, - ); - expect( - MeteringScreenLayoutConfigJson.fromJson({'0': false, '1': false}), - { - MeteringScreenLayoutFeature.extremeExposurePairs: false, - MeteringScreenLayoutFeature.filmPicker: false, - }, - ); - }); + group( + 'fromJson()', + () { + test('All keys', () { + expect( + MeteringScreenLayoutConfigJson.fromJson( + { + '0': true, + '1': true, + '2': true, + }, + ), + { + MeteringScreenLayoutFeature.extremeExposurePairs: true, + MeteringScreenLayoutFeature.filmPicker: true, + MeteringScreenLayoutFeature.equipmentProfiles: true, + }, + ); + }); - test('toJson', () { + test('Legacy (no equipment profiles)', () { + expect( + MeteringScreenLayoutConfigJson.fromJson( + { + '0': true, + '1': true, + }, + ), + { + MeteringScreenLayoutFeature.extremeExposurePairs: true, + MeteringScreenLayoutFeature.filmPicker: true, + MeteringScreenLayoutFeature.equipmentProfiles: true, + }, + ); + }); + }, + ); + + test('toJson()', () { expect( { + MeteringScreenLayoutFeature.equipmentProfiles: true, MeteringScreenLayoutFeature.extremeExposurePairs: true, MeteringScreenLayoutFeature.filmPicker: true, }.toJson(), - {'0': true, '1': true}, + { + '2': true, + '0': true, + '1': true, + }, ); }); }