mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-23 16:00:41 +00:00
fixed redundant vibrations
This commit is contained in:
parent
0daa689c01
commit
67f8e6e236
3 changed files with 59 additions and 51 deletions
|
@ -1,8 +1,8 @@
|
|||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class PermissionsService {
|
||||
|
||||
const PermissionsService();
|
||||
|
||||
Future<PermissionStatus> checkCameraPermission() async => Permission.camera.status;
|
||||
|
||||
Future<PermissionStatus> requestCameraPermission() async => Permission.camera.request();
|
||||
|
|
|
@ -3,35 +3,6 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
|||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||
|
||||
class MeteringScreenLayout extends InheritedModelBase<MeteringScreenLayoutFeature, bool> {
|
||||
const MeteringScreenLayout({
|
||||
required super.data,
|
||||
required super.child,
|
||||
super.key,
|
||||
});
|
||||
|
||||
static MeteringScreenLayoutConfig of(BuildContext context, {bool listen = true}) {
|
||||
if (listen) {
|
||||
return context
|
||||
.dependOnInheritedWidgetOfExactType<
|
||||
InheritedModelBase<MeteringScreenLayoutFeature, bool>>()!
|
||||
.data;
|
||||
} else {
|
||||
return context
|
||||
.findAncestorWidgetOfExactType<InheritedModelBase<MeteringScreenLayoutFeature, bool>>()!
|
||||
.data;
|
||||
}
|
||||
}
|
||||
|
||||
static bool featureOf(BuildContext context, MeteringScreenLayoutFeature aspect) {
|
||||
return InheritedModel.inheritFrom<InheritedModelBase<MeteringScreenLayoutFeature, bool>>(
|
||||
context,
|
||||
aspect: aspect,
|
||||
)!
|
||||
.data[aspect]!;
|
||||
}
|
||||
}
|
||||
|
||||
class MeteringScreenLayoutProvider extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
||||
|
@ -70,3 +41,20 @@ class MeteringScreenLayoutProviderState extends State<MeteringScreenLayoutProvid
|
|||
context.get<UserPreferencesService>().meteringScreenLayout = _config;
|
||||
}
|
||||
}
|
||||
|
||||
typedef _MeteringScreenLayoutModel = InheritedModelBase<MeteringScreenLayoutFeature, bool>;
|
||||
|
||||
extension MeteringScreenLayout on InheritedModelBase<MeteringScreenLayoutFeature, bool> {
|
||||
static MeteringScreenLayoutConfig of(BuildContext context, {bool listen = true}) {
|
||||
if (listen) {
|
||||
return context.dependOnInheritedWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||
} else {
|
||||
return context.findAncestorWidgetOfExactType<_MeteringScreenLayoutModel>()!.data;
|
||||
}
|
||||
}
|
||||
|
||||
static bool featureOf(BuildContext context, MeteringScreenLayoutFeature aspect) {
|
||||
return InheritedModel.inheritFrom<_MeteringScreenLayoutModel>(context, aspect: aspect)!
|
||||
.data[aspect]!;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
this.stopType,
|
||||
) : super(
|
||||
MeteringDataState(
|
||||
ev: 0.0,
|
||||
ev: null,
|
||||
film: _meteringInteractor.film,
|
||||
iso: _meteringInteractor.iso,
|
||||
nd: _meteringInteractor.ndFilter,
|
||||
|
@ -77,55 +77,75 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
}
|
||||
|
||||
void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
|
||||
stopType = event.stopType;
|
||||
_updateMeasurements();
|
||||
if (stopType != event.stopType) {
|
||||
stopType = event.stopType;
|
||||
_updateMeasurements();
|
||||
}
|
||||
}
|
||||
|
||||
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
|
||||
_equipmentProfileData = event.equipmentProfileData;
|
||||
bool willUpdateMeasurements = false;
|
||||
|
||||
/// Update selected ISO value, if selected equipment profile
|
||||
/// doesn't contain currently selected value
|
||||
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
|
||||
_meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
|
||||
_iso = event.equipmentProfileData.isoValues.first;
|
||||
willUpdateMeasurements &= true;
|
||||
}
|
||||
|
||||
/// The same for ND filter
|
||||
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
|
||||
_meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
|
||||
_nd = event.equipmentProfileData.ndValues.first;
|
||||
willUpdateMeasurements &= true;
|
||||
}
|
||||
|
||||
_updateMeasurements();
|
||||
if (willUpdateMeasurements) {
|
||||
_updateMeasurements();
|
||||
}
|
||||
}
|
||||
|
||||
void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
|
||||
if (_iso.value != event.data.iso) {
|
||||
final newIso = IsoValue.values.firstWhere(
|
||||
(e) => e.value == event.data.iso,
|
||||
orElse: () => _iso,
|
||||
);
|
||||
add(IsoChangedEvent(newIso));
|
||||
if (_film.name != event.data.name) {
|
||||
_film = event.data;
|
||||
_meteringInteractor.film = event.data;
|
||||
|
||||
/// If user selects 'Other' film we preserve currently selected ISO
|
||||
/// and therefore only discard reciprocity formula
|
||||
if (_iso.value != event.data.iso && event.data != const Film.other()) {
|
||||
final newIso = IsoValue.values.firstWhere(
|
||||
(e) => e.value == event.data.iso,
|
||||
orElse: () => _iso,
|
||||
);
|
||||
_meteringInteractor.iso = newIso;
|
||||
_iso = newIso;
|
||||
}
|
||||
|
||||
_updateMeasurements();
|
||||
}
|
||||
_film = event.data;
|
||||
_meteringInteractor.film = event.data;
|
||||
_updateMeasurements();
|
||||
}
|
||||
|
||||
void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
|
||||
if (event.isoValue.value != _film.iso) {
|
||||
_film = Film.values.first;
|
||||
/// Discard currently selected film even if ISO is the same,
|
||||
/// because, for example, Fomapan 400 and any Ilford 400
|
||||
/// have different reciprocity formulas
|
||||
_film = Film.values.first;
|
||||
|
||||
if (_iso != event.isoValue) {
|
||||
_meteringInteractor.iso = event.isoValue;
|
||||
_iso = event.isoValue;
|
||||
_updateMeasurements();
|
||||
}
|
||||
_meteringInteractor.iso = event.isoValue;
|
||||
_iso = event.isoValue;
|
||||
_updateMeasurements();
|
||||
}
|
||||
|
||||
void _onNdChanged(NdChangedEvent event, Emitter emit) {
|
||||
_meteringInteractor.ndFilter = event.ndValue;
|
||||
_nd = event.ndValue;
|
||||
_updateMeasurements();
|
||||
if (_nd != event.ndValue) {
|
||||
_meteringInteractor.ndFilter = event.ndValue;
|
||||
_nd = event.ndValue;
|
||||
_updateMeasurements();
|
||||
}
|
||||
}
|
||||
|
||||
void _onMeasure(MeasureEvent _, Emitter emit) {
|
||||
|
|
Loading…
Reference in a new issue