mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
added CameraFeature
model
This commit is contained in:
parent
5d75ac4a11
commit
f4f1960fda
10 changed files with 180 additions and 51 deletions
13
lib/data/models/camera_feature.dart
Normal file
13
lib/data/models/camera_feature.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
enum CameraFeature {
|
||||
histogram,
|
||||
spotMetering,
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.name, value));
|
||||
}
|
|
@ -1,18 +1,31 @@
|
|||
enum MeteringScreenLayoutFeature {
|
||||
extremeExposurePairs,
|
||||
filmPicker,
|
||||
histogram,
|
||||
equipmentProfiles,
|
||||
extremeExposurePairs, // 0
|
||||
filmPicker, // 1
|
||||
equipmentProfiles, // 3
|
||||
}
|
||||
|
||||
typedef MeteringScreenLayoutConfig = Map<MeteringScreenLayoutFeature, bool>;
|
||||
|
||||
extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig {
|
||||
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) =>
|
||||
<MeteringScreenLayoutFeature, bool>{
|
||||
for (final f in MeteringScreenLayoutFeature.values)
|
||||
f: data[f.index.toString()] as bool? ?? true
|
||||
};
|
||||
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) {
|
||||
int? migratedIndex(MeteringScreenLayoutFeature feature) {
|
||||
switch (feature) {
|
||||
case MeteringScreenLayoutFeature.extremeExposurePairs:
|
||||
return 0;
|
||||
case MeteringScreenLayoutFeature.filmPicker:
|
||||
return 1;
|
||||
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||
return 3;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.index.toString(), value));
|
||||
return <MeteringScreenLayoutFeature, bool>{
|
||||
for (final f in MeteringScreenLayoutFeature.values)
|
||||
f: (data[migratedIndex(f).toString()] ?? data[f.name]) as bool? ?? true
|
||||
};
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.name, value));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/data/models/camera_feature.dart';
|
||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||
|
@ -18,6 +19,7 @@ class UserPreferencesService {
|
|||
static const cameraEvCalibrationKey = "cameraEvCalibration";
|
||||
static const lightSensorEvCalibrationKey = "lightSensorEvCalibration";
|
||||
static const meteringScreenLayoutKey = "meteringScreenLayout";
|
||||
static const cameraFeaturesKey = "cameraFeatures";
|
||||
|
||||
static const caffeineKey = "caffeine";
|
||||
static const hapticsKey = "haptics";
|
||||
|
@ -70,16 +72,13 @@ class UserPreferencesService {
|
|||
}
|
||||
}
|
||||
|
||||
IsoValue get iso =>
|
||||
IsoValue.values.firstWhere((v) => v.value == (_sharedPreferences.getInt(isoKey) ?? 100));
|
||||
IsoValue get iso => IsoValue.values.firstWhere((v) => v.value == (_sharedPreferences.getInt(isoKey) ?? 100));
|
||||
set iso(IsoValue value) => _sharedPreferences.setInt(isoKey, value.value);
|
||||
|
||||
NdValue get ndFilter =>
|
||||
NdValue.values.firstWhere((v) => v.value == (_sharedPreferences.getInt(ndFilterKey) ?? 0));
|
||||
NdValue get ndFilter => NdValue.values.firstWhere((v) => v.value == (_sharedPreferences.getInt(ndFilterKey) ?? 0));
|
||||
set ndFilter(NdValue value) => _sharedPreferences.setInt(ndFilterKey, value.value);
|
||||
|
||||
EvSourceType get evSourceType =>
|
||||
EvSourceType.values[_sharedPreferences.getInt(evSourceTypeKey) ?? 0];
|
||||
EvSourceType get evSourceType => EvSourceType.values[_sharedPreferences.getInt(evSourceTypeKey) ?? 0];
|
||||
set evSourceType(EvSourceType value) => _sharedPreferences.setInt(evSourceTypeKey, value.index);
|
||||
|
||||
StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2];
|
||||
|
@ -96,7 +95,6 @@ class UserPreferencesService {
|
|||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +102,21 @@ class UserPreferencesService {
|
|||
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<String, dynamic>);
|
||||
} else {
|
||||
return {
|
||||
CameraFeature.spotMetering: false,
|
||||
CameraFeature.histogram: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
set cameraFeatures(CameraFeaturesConfig value) =>
|
||||
_sharedPreferences.setString(cameraFeaturesKey, json.encode(value.toJson()));
|
||||
|
||||
bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false;
|
||||
set caffeine(bool value) => _sharedPreferences.setBool(caffeineKey, value);
|
||||
|
||||
|
@ -114,8 +127,7 @@ class UserPreferencesService {
|
|||
(e) => e.toString() == _sharedPreferences.getString(volumeActionKey),
|
||||
orElse: () => VolumeAction.shutter,
|
||||
);
|
||||
set volumeAction(VolumeAction value) =>
|
||||
_sharedPreferences.setString(volumeActionKey, value.toString());
|
||||
set volumeAction(VolumeAction value) => _sharedPreferences.setString(volumeActionKey, value.toString());
|
||||
|
||||
SupportedLocale get locale => SupportedLocale.values.firstWhere(
|
||||
(e) => e.toString() == _sharedPreferences.getString(localeKey),
|
||||
|
@ -124,13 +136,10 @@ class UserPreferencesService {
|
|||
set locale(SupportedLocale value) => _sharedPreferences.setString(localeKey, value.toString());
|
||||
|
||||
double get cameraEvCalibration => _sharedPreferences.getDouble(cameraEvCalibrationKey) ?? 0.0;
|
||||
set cameraEvCalibration(double value) =>
|
||||
_sharedPreferences.setDouble(cameraEvCalibrationKey, value);
|
||||
set cameraEvCalibration(double value) => _sharedPreferences.setDouble(cameraEvCalibrationKey, value);
|
||||
|
||||
double get lightSensorEvCalibration =>
|
||||
_sharedPreferences.getDouble(lightSensorEvCalibrationKey) ?? 0.0;
|
||||
set lightSensorEvCalibration(double value) =>
|
||||
_sharedPreferences.setDouble(lightSensorEvCalibrationKey, value);
|
||||
double get lightSensorEvCalibration => _sharedPreferences.getDouble(lightSensorEvCalibrationKey) ?? 0.0;
|
||||
set lightSensorEvCalibration(double value) => _sharedPreferences.setDouble(lightSensorEvCalibrationKey, value);
|
||||
|
||||
ThemeType get themeType => ThemeType.values[_sharedPreferences.getInt(themeTypeKey) ?? 0];
|
||||
set themeType(ThemeType value) => _sharedPreferences.setInt(themeTypeKey, value.index);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||
import 'package:lightmeter/data/models/camera_feature.dart';
|
||||
import 'package:lightmeter/platform_config.dart';
|
||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
@ -92,9 +92,9 @@ class _CameraPreviewBuilderState extends State<_CameraPreviewBuilder> {
|
|||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
CameraView(controller: widget.controller),
|
||||
if (UserPreferencesProvider.meteringScreenFeatureOf(
|
||||
if (UserPreferencesProvider.cameraFeatureOf(
|
||||
context,
|
||||
MeteringScreenLayoutFeature.histogram,
|
||||
CameraFeature.histogram,
|
||||
))
|
||||
Positioned(
|
||||
left: Dimens.grid8,
|
||||
|
@ -102,7 +102,11 @@ class _CameraPreviewBuilderState extends State<_CameraPreviewBuilder> {
|
|||
bottom: Dimens.grid16,
|
||||
child: CameraHistogram(controller: widget.controller),
|
||||
),
|
||||
CameraSpotDetector(onSpotTap: widget.onSpotTap)
|
||||
if (UserPreferencesProvider.cameraFeatureOf(
|
||||
context,
|
||||
CameraFeature.spotMetering,
|
||||
))
|
||||
CameraSpotDetector(onSpotTap: widget.onSpotTap)
|
||||
],
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
|
|
|
@ -47,8 +47,6 @@ class MeteringScreenLayoutListTile extends StatelessWidget {
|
|||
return S.of(context).meteringScreenFeatureExtremeExposurePairs;
|
||||
case MeteringScreenLayoutFeature.filmPicker:
|
||||
return S.of(context).meteringScreenFeatureFilmPicker;
|
||||
case MeteringScreenLayoutFeature.histogram:
|
||||
return S.of(context).meteringScreenFeatureHistogram;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ void main() {
|
|||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.histogram: false,
|
||||
}.toJson(),
|
||||
),
|
||||
|
||||
|
|
47
test/data/models/camera_features_config_test.dart
Normal file
47
test/data/models/camera_features_config_test.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
import 'package:lightmeter/data/models/camera_feature.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group(
|
||||
'fromJson()',
|
||||
() {
|
||||
test('All keys', () {
|
||||
expect(
|
||||
CameraFeaturesConfigJson.fromJson(
|
||||
{
|
||||
'spotMetering': true,
|
||||
'histogram': true,
|
||||
},
|
||||
),
|
||||
{
|
||||
CameraFeature.spotMetering: true,
|
||||
CameraFeature.histogram: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('Legacy (no spotMetering & histogram)', () {
|
||||
expect(
|
||||
CameraFeaturesConfigJson.fromJson({}),
|
||||
{
|
||||
CameraFeature.spotMetering: false,
|
||||
CameraFeature.histogram: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test('toJson()', () {
|
||||
expect(
|
||||
{
|
||||
CameraFeature.spotMetering: true,
|
||||
CameraFeature.histogram: true,
|
||||
}.toJson(),
|
||||
{
|
||||
'spotMetering': true,
|
||||
'histogram': true,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -18,7 +18,6 @@ void main() {
|
|||
{
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
},
|
||||
);
|
||||
|
@ -35,7 +34,6 @@ void main() {
|
|||
{
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: false,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
},
|
||||
);
|
||||
|
@ -53,7 +51,6 @@ void main() {
|
|||
{
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: false,
|
||||
MeteringScreenLayoutFeature.histogram: false,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
},
|
||||
);
|
||||
|
@ -67,13 +64,11 @@ void main() {
|
|||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
}.toJson(),
|
||||
{
|
||||
'3': true,
|
||||
'0': true,
|
||||
'1': true,
|
||||
'2': true,
|
||||
'equipmentProfiles': true,
|
||||
'extremeExposurePairs': true,
|
||||
'filmPicker': true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lightmeter/data/models/camera_feature.dart';
|
||||
import 'package:lightmeter/data/models/ev_source_type.dart';
|
||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||
|
@ -191,12 +192,11 @@ void main() {
|
|||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('get', () {
|
||||
test('get (legacy)', () {
|
||||
when(
|
||||
() => sharedPreferences.getString(UserPreferencesService.meteringScreenLayoutKey),
|
||||
).thenReturn("""{"0":false,"1":true}""");
|
||||
|
@ -206,7 +206,20 @@ void main() {
|
|||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('get', () {
|
||||
when(
|
||||
() => sharedPreferences.getString(UserPreferencesService.meteringScreenLayoutKey),
|
||||
).thenReturn("""{"extremeExposurePairs":false,"filmPicker":true}""");
|
||||
expect(
|
||||
service.meteringScreenLayout,
|
||||
{
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -215,19 +228,62 @@ void main() {
|
|||
when(
|
||||
() => sharedPreferences.setString(
|
||||
UserPreferencesService.meteringScreenLayoutKey,
|
||||
"""{"0":false,"1":true,"2":true,"3":true}""",
|
||||
"""{"extremeExposurePairs":false,"filmPicker":true,"equipmentProfiles":true}""",
|
||||
),
|
||||
).thenAnswer((_) => Future.value(true));
|
||||
service.meteringScreenLayout = {
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
};
|
||||
verify(
|
||||
() => sharedPreferences.setString(
|
||||
UserPreferencesService.meteringScreenLayoutKey,
|
||||
"""{"0":false,"1":true,"2":true,"3":true}""",
|
||||
"""{"extremeExposurePairs":false,"filmPicker":true,"equipmentProfiles":true}""",
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
group('cameraFeatures', () {
|
||||
test('get default', () {
|
||||
when(() => sharedPreferences.getString(UserPreferencesService.cameraFeaturesKey)).thenReturn(null);
|
||||
expect(
|
||||
service.cameraFeatures,
|
||||
{
|
||||
CameraFeature.spotMetering: false,
|
||||
CameraFeature.histogram: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('get', () {
|
||||
when(() => sharedPreferences.getString(UserPreferencesService.cameraFeaturesKey))
|
||||
.thenReturn("""{"spotMetering":false,"histogram":true}""");
|
||||
expect(
|
||||
service.cameraFeatures,
|
||||
{
|
||||
CameraFeature.spotMetering: false,
|
||||
CameraFeature.histogram: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('set', () {
|
||||
when(
|
||||
() => sharedPreferences.setString(
|
||||
UserPreferencesService.cameraFeaturesKey,
|
||||
"""{"spotMetering":false,"histogram":true}""",
|
||||
),
|
||||
).thenAnswer((_) => Future.value(true));
|
||||
service.cameraFeatures = {
|
||||
CameraFeature.spotMetering: false,
|
||||
CameraFeature.histogram: true,
|
||||
};
|
||||
verify(
|
||||
() => sharedPreferences.setString(
|
||||
UserPreferencesService.cameraFeaturesKey,
|
||||
"""{"spotMetering":false,"histogram":true}""",
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
|
|
@ -31,7 +31,6 @@ void main() {
|
|||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||
MeteringScreenLayoutFeature.filmPicker: true,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
});
|
||||
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
|
||||
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
|
||||
|
@ -184,7 +183,6 @@ void main() {
|
|||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: false,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
}),
|
||||
child: const Text(''),
|
||||
),
|
||||
|
@ -196,20 +194,17 @@ void main() {
|
|||
expect(find.text("${MeteringScreenLayoutFeature.equipmentProfiles}: true"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.extremeExposurePairs}: true"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.filmPicker}: true"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.histogram}: true"), findsNWidgets(2));
|
||||
|
||||
await tester.tap(find.byType(ElevatedButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text("${MeteringScreenLayoutFeature.equipmentProfiles}: true"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.extremeExposurePairs}: false"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.filmPicker}: false"), findsNWidgets(2));
|
||||
expect(find.text("${MeteringScreenLayoutFeature.histogram}: true"), findsNWidgets(2));
|
||||
verify(
|
||||
() => mockUserPreferencesService.meteringScreenLayout = {
|
||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
||||
MeteringScreenLayoutFeature.filmPicker: false,
|
||||
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||
MeteringScreenLayoutFeature.histogram: true,
|
||||
},
|
||||
).called(1);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue