mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 17:00:39 +00:00
Compare commits
No commits in common. "7633f3fd27883449957bb86b95ed6e23a912b718" and "f6a0fc2f52e1cabb00217bb4d1ec03465c5ef924" have entirely different histories.
7633f3fd27
...
f6a0fc2f52
5 changed files with 37 additions and 85 deletions
|
@ -1,17 +1,11 @@
|
||||||
enum MeteringScreenLayoutFeature {
|
enum MeteringScreenLayoutFeature { equipmentProfiles, extremeExposurePairs, filmPicker }
|
||||||
extremeExposurePairs,
|
|
||||||
filmPicker,
|
|
||||||
equipmentProfiles,
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef MeteringScreenLayoutConfig = Map<MeteringScreenLayoutFeature, bool>;
|
typedef MeteringScreenLayoutConfig = Map<MeteringScreenLayoutFeature, bool>;
|
||||||
|
|
||||||
extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig {
|
extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig {
|
||||||
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) =>
|
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) => data.map(
|
||||||
<MeteringScreenLayoutFeature, bool>{
|
(key, value) => MapEntry(MeteringScreenLayoutFeature.values[int.parse(key)], value as bool),
|
||||||
for (final f in MeteringScreenLayoutFeature.values)
|
);
|
||||||
f: data[f.index.toString()] as bool? ?? true
|
|
||||||
};
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.index.toString(), value));
|
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.index.toString(), value));
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,23 +76,13 @@ class _InheritedListeners extends StatelessWidget {
|
||||||
onDidChangeDependencies: (value) {
|
onDidChangeDependencies: (value) {
|
||||||
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
context.read<MeteringBloc>().add(EquipmentProfileChangedEvent(value));
|
||||||
},
|
},
|
||||||
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
|
||||||
aspect: MeteringScreenLayoutFeature.equipmentProfiles,
|
|
||||||
onDidChangeDependencies: (value) {
|
|
||||||
if (!value) {
|
|
||||||
EquipmentProfileProvider.of(context).setProfile(context.get<EquipmentProfiles>().first);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
child: InheritedModelAspectListener<MeteringScreenLayoutFeature, bool>(
|
||||||
aspect: MeteringScreenLayoutFeature.filmPicker,
|
aspect: MeteringScreenLayoutFeature.filmPicker,
|
||||||
onDidChangeDependencies: (value) {
|
onDidChangeDependencies: (value) {
|
||||||
if (!value) {
|
if (!value) context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
||||||
context.read<MeteringBloc>().add(const FilmChangedEvent(Film.other()));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,18 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
child: Text(S.of(context).meteringScreenLayoutHint),
|
child: Text(S.of(context).meteringScreenLayoutHint),
|
||||||
),
|
),
|
||||||
const SizedBox(height: Dimens.grid16),
|
const SizedBox(height: Dimens.grid16),
|
||||||
_featureListTile(MeteringScreenLayoutFeature.equipmentProfiles),
|
...MeteringScreenLayoutFeature.values.map(
|
||||||
_featureListTile(MeteringScreenLayoutFeature.extremeExposurePairs),
|
(f) => SwitchListTile(
|
||||||
_featureListTile(MeteringScreenLayoutFeature.filmPicker),
|
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
||||||
|
title: Text(_toStringLocalized(context, f)),
|
||||||
|
value: _features[f]!,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_features.update(f, (_) => value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -56,19 +65,6 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _featureListTile(MeteringScreenLayoutFeature f) {
|
|
||||||
return SwitchListTile(
|
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
|
||||||
title: Text(_toStringLocalized(context, f)),
|
|
||||||
value: _features[f]!,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_features.update(f, (_) => value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
||||||
switch (feature) {
|
switch (feature) {
|
||||||
case MeteringScreenLayoutFeature.equipmentProfiles:
|
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||||
|
|
|
@ -2,56 +2,30 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group(
|
test('fromJson', () {
|
||||||
'fromJson()',
|
|
||||||
() {
|
|
||||||
test('All keys', () {
|
|
||||||
expect(
|
expect(
|
||||||
MeteringScreenLayoutConfigJson.fromJson(
|
MeteringScreenLayoutConfigJson.fromJson({'0': true, '1': true}),
|
||||||
{
|
|
||||||
'0': true,
|
|
||||||
'1': true,
|
|
||||||
'2': true,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
MeteringScreenLayoutConfigJson.fromJson({'0': false, '1': false}),
|
||||||
|
{
|
||||||
|
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||||
|
MeteringScreenLayoutFeature.filmPicker: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Legacy (no equipment profiles)', () {
|
test('toJson', () {
|
||||||
expect(
|
|
||||||
MeteringScreenLayoutConfigJson.fromJson(
|
|
||||||
{
|
|
||||||
'0': true,
|
|
||||||
'1': true,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
{
|
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test('toJson()', () {
|
|
||||||
expect(
|
expect(
|
||||||
{
|
{
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
}.toJson(),
|
}.toJson(),
|
||||||
{
|
{'0': true, '1': true},
|
||||||
'2': true,
|
|
||||||
'0': true,
|
|
||||||
'1': true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,6 @@ void main() {
|
||||||
{
|
{
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -207,7 +206,6 @@ void main() {
|
||||||
{
|
{
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue