This commit is contained in:
Vadim 2023-03-17 21:24:07 +03:00
parent c5179e71ea
commit 284e95854d
7 changed files with 62 additions and 76 deletions

View file

@ -8,6 +8,7 @@ import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/providers/supported_locale_provider.dart'; import 'package:lightmeter/providers/supported_locale_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -47,31 +48,33 @@ class Application extends StatelessWidget {
Provider(create: (_) => PermissionsService()), Provider(create: (_) => PermissionsService()),
Provider(create: (_) => const LightSensorService()), Provider(create: (_) => const LightSensorService()),
], ],
child: StopTypeProvider( child: IAPProductsProvider(
child: EquipmentProfileProvider( child: StopTypeProvider(
child: EvSourceTypeProvider( child: EquipmentProfileProvider(
child: SupportedLocaleProvider( child: EvSourceTypeProvider(
child: ThemeProvider( child: SupportedLocaleProvider(
builder: (context, _) => _AnnotatedRegionWrapper( child: ThemeProvider(
child: MaterialApp( builder: (context, _) => _AnnotatedRegionWrapper(
theme: context.watch<ThemeData>(), child: MaterialApp(
locale: Locale(context.watch<SupportedLocale>().intlName), theme: context.watch<ThemeData>(),
localizationsDelegates: const [ locale: Locale(context.watch<SupportedLocale>().intlName),
S.delegate, localizationsDelegates: const [
GlobalMaterialLocalizations.delegate, S.delegate,
GlobalWidgetsLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], GlobalCupertinoLocalizations.delegate,
supportedLocales: S.delegate.supportedLocales, ],
builder: (context, child) => MediaQuery( supportedLocales: S.delegate.supportedLocales,
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), builder: (context, child) => MediaQuery(
child: child!, data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!,
),
initialRoute: "metering",
routes: {
"metering": (context) => const MeteringFlow(),
"settings": (context) => const SettingsFlow(),
},
), ),
initialRoute: "metering",
routes: {
"metering": (context) => const MeteringFlow(),
"settings": (context) => const SettingsFlow(),
},
), ),
), ),
), ),

View file

@ -15,17 +15,18 @@ class EquipmentProfileProvider extends StatefulWidget {
} }
class EquipmentProfileProviderState extends State<EquipmentProfileProvider> { class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
final List<EquipmentProfileData> _profiles = [ final List<EquipmentProfileData> _profiles = [];
const EquipmentProfileData(
id: '0', late EquipmentProfileData _selectedProfile = _profiles.isNotEmpty
name: 'Default', ? _profiles.first
apertureValues: apertureValues, : const EquipmentProfileData(
ndValues: ndValues, id: 'default',
shutterSpeedValues: shutterSpeedValues, name: '',
isoValues: isoValues, apertureValues: apertureValues,
), ndValues: ndValues,
]; shutterSpeedValues: shutterSpeedValues,
late EquipmentProfileData? _selectedProfile = _profiles.isNotEmpty ? _profiles.first : null; isoValues: isoValues,
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -77,8 +78,12 @@ class EquipmentProfile extends InheritedWidget {
super.key, super.key,
}); });
static EquipmentProfileData? of(BuildContext context) { static EquipmentProfileData? of(BuildContext context, {bool listen = true}) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()?.data; if (listen) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()?.data;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfile>()?.data;
}
} }
@override @override

View file

@ -21,9 +21,12 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final MeteringInteractor _meteringInteractor; final MeteringInteractor _meteringInteractor;
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription; late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;
List<ApertureValue> get _apertureValues => apertureValues.whereStopType(stopType); List<ApertureValue> get _apertureValues =>
List<ShutterSpeedValue> get _shutterSpeedValues => shutterSpeedValues.whereStopType(stopType); _equipmentProfileData.apertureValues.whereStopType(stopType);
List<ShutterSpeedValue> get _shutterSpeedValues =>
_equipmentProfileData.shutterSpeedValues.whereStopType(stopType);
EquipmentProfileData _equipmentProfileData;
StopType stopType; StopType stopType;
late IsoValue _iso = _userPreferencesService.iso; late IsoValue _iso = _userPreferencesService.iso;
@ -35,6 +38,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
this._communicationBloc, this._communicationBloc,
this._userPreferencesService, this._userPreferencesService,
this._meteringInteractor, this._meteringInteractor,
this._equipmentProfileData,
this.stopType, this.stopType,
) : super( ) : super(
MeteringEndedState( MeteringEndedState(
@ -76,6 +80,8 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
} }
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) { void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
_equipmentProfileData = event.equipmentProfileData;
/// Update selected ISO value, if selected equipment profile /// Update selected ISO value, if selected equipment profile
/// doesn't contain currently selected value /// doesn't contain currently selected value
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) { if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
@ -90,6 +96,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
_ev = _ev - event.equipmentProfileData.ndValues.first.stopReduction + _nd.stopReduction; _ev = _ev - event.equipmentProfileData.ndValues.first.stopReduction + _nd.stopReduction;
_nd = event.equipmentProfileData.ndValues.first; _nd = event.equipmentProfileData.ndValues.first;
} }
_emitMeasuredState(emit); _emitMeasuredState(emit);
} }

View file

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'bloc_container_camera.dart'; import 'bloc_container_camera.dart';

View file

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'bloc_container_light_sensor.dart'; import 'bloc_container_light_sensor.dart';

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'components/animated_dialog_picker/widget_dialog_animated_picker.dart'; import 'components/animated_dialog_picker/widget_dialog_animated_picker.dart';
@ -37,11 +38,12 @@ class ReadingsContainer extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
if (EquipmentProfiles.of(context)!.isNotEmpty) ...[ if (IAPProducts.of(context, IAPProductType.equipment)?.status ==
IAPProductStatus.purchased) ...[
ReadingValueContainer.singleValue( ReadingValueContainer.singleValue(
value: ReadingValue( value: ReadingValue(
label: S.of(context).equipment, label: S.of(context).equipment,
value: 'Parktica + Zenitar', value: EquipmentProfile.of(context)!.name,
), ),
), ),
const _InnerPadding(), const _InnerPadding(),
@ -87,39 +89,6 @@ class _InnerPadding extends SizedBox {
const _InnerPadding() : super(height: Dimens.grid8, width: Dimens.grid8); const _InnerPadding() : super(height: Dimens.grid8, width: Dimens.grid8);
} }
class _EquipmentProfileDataTile extends StatelessWidget {
final List<IsoValue> values;
final IsoValue selectedValue;
final ValueChanged<IsoValue> onChanged;
const _EquipmentProfileDataTile({
required this.selectedValue,
required this.values,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return AnimatedDialogPicker<IsoValue>(
title: S.of(context).iso,
subtitle: S.of(context).filmSpeed,
selectedValue: selectedValue,
values: values,
itemTitleBuilder: (_, value) => Text(value.value.toString()),
// using ascending order, because increase in film speed rises EV
evDifferenceBuilder: (selected, other) => selected.toStringDifference(other),
onChanged: onChanged,
closedChild: ReadingValueContainer.singleValue(
value: ReadingValue(
label: S.of(context).iso,
value: selectedValue.value.toString(),
),
),
);
}
}
class _IsoValueTile extends StatelessWidget { class _IsoValueTile extends StatelessWidget {
final List<IsoValue> values; final List<IsoValue> values;
final IsoValue selectedValue; final IsoValue selectedValue;

View file

@ -6,6 +6,7 @@ import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/permissions_service.dart'; import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -39,6 +40,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
context.read<MeteringCommunicationBloc>(), context.read<MeteringCommunicationBloc>(),
context.read<UserPreferencesService>(), context.read<UserPreferencesService>(),
context.read<MeteringInteractor>(), context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false)!,
context.read<StopType>(), context.read<StopType>(),
), ),
), ),