mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
release camera when timer is opened
This commit is contained in:
parent
8765998680
commit
2fc24cccbb
7 changed files with 47 additions and 52 deletions
|
@ -6,10 +6,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/data/models/volume_action.dart';
|
import 'package:lightmeter/data/models/volume_action.dart';
|
||||||
import 'package:lightmeter/interactors/metering_interactor.dart';
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
|
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events;
|
||||||
as communication_events;
|
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' as communication_states;
|
||||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
|
||||||
as communication_states;
|
|
||||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||||
|
@ -45,8 +43,8 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
on<MeasureEvent>(_onMeasure, transformer: droppable());
|
on<MeasureEvent>(_onMeasure, transformer: droppable());
|
||||||
on<MeasuredEvent>(_onMeasured);
|
on<MeasuredEvent>(_onMeasured);
|
||||||
on<MeasureErrorEvent>(_onMeasureError);
|
on<MeasureErrorEvent>(_onMeasureError);
|
||||||
on<SettingsOpenedEvent>(_onSettingsOpened);
|
on<ScreenOnTopOpenedEvent>(_onSettingsOpened);
|
||||||
on<SettingsClosedEvent>(_onSettingsClosed);
|
on<ScreenOnTopClosedEvent>(_onSettingsClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -191,11 +189,11 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSettingsOpened(SettingsOpenedEvent _, Emitter __) {
|
void _onSettingsOpened(ScreenOnTopOpenedEvent _, Emitter __) {
|
||||||
_communicationBloc.add(const communication_events.SettingsOpenedEvent());
|
_communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSettingsClosed(SettingsClosedEvent _, Emitter __) {
|
void _onSettingsClosed(ScreenOnTopClosedEvent _, Emitter __) {
|
||||||
_communicationBloc.add(const communication_events.SettingsClosedEvent());
|
_communicationBloc.add(const communication_events.ScreenOnTopClosedEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,14 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart';
|
||||||
|
|
||||||
class MeteringCommunicationBloc
|
class MeteringCommunicationBloc extends Bloc<MeteringCommunicationEvent, MeteringCommunicationState> {
|
||||||
extends Bloc<MeteringCommunicationEvent, MeteringCommunicationState> {
|
|
||||||
MeteringCommunicationBloc() : super(const InitState()) {
|
MeteringCommunicationBloc() : super(const InitState()) {
|
||||||
// `MeasureState` is not const, so that `Bloc` treats each state as new and updates state stream
|
// `MeasureState` is not const, so that `Bloc` treats each state as new and updates state stream
|
||||||
// ignore: prefer_const_constructors
|
// ignore: prefer_const_constructors
|
||||||
on<MeasureEvent>((_, emit) => emit(MeasureState()));
|
on<MeasureEvent>((_, emit) => emit(MeasureState()));
|
||||||
on<MeteringInProgressEvent>((event, emit) => emit(MeteringInProgressState(event.ev100)));
|
on<MeteringInProgressEvent>((event, emit) => emit(MeteringInProgressState(event.ev100)));
|
||||||
on<MeteringEndedEvent>((event, emit) => emit(MeteringEndedState(event.ev100)));
|
on<MeteringEndedEvent>((event, emit) => emit(MeteringEndedState(event.ev100)));
|
||||||
on<SettingsOpenedEvent>((_, emit) => emit(const SettingsOpenedState()));
|
on<ScreenOnTopOpenedEvent>((_, emit) => emit(const SettingsOpenedState()));
|
||||||
on<SettingsClosedEvent>((_, emit) => emit(const SettingsClosedState()));
|
on<ScreenOnTopClosedEvent>((_, emit) => emit(const SettingsClosedState()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ class MeteringEndedEvent extends MeasuredEvent {
|
||||||
int get hashCode => Object.hash(ev100, runtimeType);
|
int get hashCode => Object.hash(ev100, runtimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsOpenedEvent extends ScreenEvent {
|
class ScreenOnTopOpenedEvent extends ScreenEvent {
|
||||||
const SettingsOpenedEvent();
|
const ScreenOnTopOpenedEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsClosedEvent extends ScreenEvent {
|
class ScreenOnTopClosedEvent extends ScreenEvent {
|
||||||
const SettingsClosedEvent();
|
const ScreenOnTopClosedEvent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,10 @@ class MeasureErrorEvent extends MeteringEvent {
|
||||||
const MeasureErrorEvent({required this.isMetering});
|
const MeasureErrorEvent({required this.isMetering});
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsOpenedEvent extends MeteringEvent {
|
class ScreenOnTopOpenedEvent extends MeteringEvent {
|
||||||
const SettingsOpenedEvent();
|
const ScreenOnTopOpenedEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsClosedEvent extends MeteringEvent {
|
class ScreenOnTopClosedEvent extends MeteringEvent {
|
||||||
const SettingsClosedEvent();
|
const ScreenOnTopClosedEvent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class MeteringScreen extends StatelessWidget {
|
||||||
nd: state.nd,
|
nd: state.nd,
|
||||||
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
||||||
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
|
onNdChanged: (value) => context.read<MeteringBloc>().add(NdChangedEvent(value)),
|
||||||
onExposurePairTap: (value) => Navigator.pushNamed(context, 'timer', arguments: value),
|
onExposurePairTap: (value) => pushNamed(context, 'timer', arguments: value),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -47,12 +47,7 @@ class MeteringScreen extends StatelessWidget {
|
||||||
? UserPreferencesProvider.of(context).toggleEvSourceType
|
? UserPreferencesProvider.of(context).toggleEvSourceType
|
||||||
: null,
|
: null,
|
||||||
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||||
onSettings: () {
|
onSettings: () => pushNamed(context, 'settings'),
|
||||||
context.read<MeteringBloc>().add(const SettingsOpenedEvent());
|
|
||||||
Navigator.pushNamed(context, 'settings').then((_) {
|
|
||||||
context.read<MeteringBloc>().add(const SettingsClosedEvent());
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -60,6 +55,13 @@ class MeteringScreen extends StatelessWidget {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pushNamed(BuildContext context, String routeName, {Object? arguments}) {
|
||||||
|
context.read<MeteringBloc>().add(const ScreenOnTopOpenedEvent());
|
||||||
|
Navigator.pushNamed(context, routeName, arguments: arguments).then((_) {
|
||||||
|
context.read<MeteringBloc>().add(const ScreenOnTopClosedEvent());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _InheritedListeners extends StatelessWidget {
|
class _InheritedListeners extends StatelessWidget {
|
||||||
|
|
|
@ -3,10 +3,8 @@ import 'package:lightmeter/data/models/volume_action.dart';
|
||||||
import 'package:lightmeter/interactors/metering_interactor.dart';
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
|
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events;
|
||||||
as communication_events;
|
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' as communication_states;
|
||||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
|
||||||
as communication_states;
|
|
||||||
import 'package:lightmeter/screens/metering/event_metering.dart';
|
import 'package:lightmeter/screens/metering/event_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/state_metering.dart';
|
import 'package:lightmeter/screens/metering/state_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
||||||
|
@ -18,9 +16,9 @@ class _MockMeteringInteractor extends Mock implements MeteringInteractor {}
|
||||||
|
|
||||||
class _MockVolumeKeysNotifier extends Mock implements VolumeKeysNotifier {}
|
class _MockVolumeKeysNotifier extends Mock implements VolumeKeysNotifier {}
|
||||||
|
|
||||||
class _MockMeteringCommunicationBloc extends MockBloc<
|
class _MockMeteringCommunicationBloc
|
||||||
communication_events.MeteringCommunicationEvent,
|
extends MockBloc<communication_events.MeteringCommunicationEvent, communication_states.MeteringCommunicationState>
|
||||||
communication_states.MeteringCommunicationState> implements MeteringCommunicationBloc {}
|
implements MeteringCommunicationBloc {}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late _MockMeteringInteractor meteringInteractor;
|
late _MockMeteringInteractor meteringInteractor;
|
||||||
|
@ -515,20 +513,18 @@ void main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
group(
|
group(
|
||||||
'`SettingOpenedEvent`/`SettingsClosedEvent`',
|
'`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`',
|
||||||
() {
|
() {
|
||||||
blocTest<MeteringBloc, MeteringState>(
|
blocTest<MeteringBloc, MeteringState>(
|
||||||
'Settings opened & closed',
|
'Settings opened & closed',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
act: (bloc) async {
|
act: (bloc) async {
|
||||||
bloc.add(const SettingsOpenedEvent());
|
bloc.add(const ScreenOnTopOpenedEvent());
|
||||||
bloc.add(const SettingsClosedEvent());
|
bloc.add(const ScreenOnTopClosedEvent());
|
||||||
},
|
},
|
||||||
verify: (_) {
|
verify: (_) {
|
||||||
verify(() => communicationBloc.add(const communication_events.SettingsOpenedEvent()))
|
verify(() => communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent())).called(1);
|
||||||
.called(1);
|
verify(() => communicationBloc.add(const communication_events.ScreenOnTopClosedEvent())).called(1);
|
||||||
verify(() => communicationBloc.add(const communication_events.SettingsClosedEvent()))
|
|
||||||
.called(1);
|
|
||||||
},
|
},
|
||||||
expect: () => [],
|
expect: () => [],
|
||||||
);
|
);
|
||||||
|
|
|
@ -100,20 +100,20 @@ void main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
group(
|
group(
|
||||||
'`SettingsOpenedEvent`/`SettingsClosedEvent`',
|
'`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`',
|
||||||
() {
|
() {
|
||||||
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
|
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
|
||||||
'Multiple consequtive settings events',
|
'Multiple consequtive settings events',
|
||||||
build: () => bloc,
|
build: () => bloc,
|
||||||
act: (bloc) async {
|
act: (bloc) async {
|
||||||
bloc.add(const SettingsOpenedEvent());
|
bloc.add(const ScreenOnTopOpenedEvent());
|
||||||
bloc.add(const SettingsOpenedEvent());
|
bloc.add(const ScreenOnTopOpenedEvent());
|
||||||
bloc.add(const SettingsOpenedEvent());
|
bloc.add(const ScreenOnTopOpenedEvent());
|
||||||
bloc.add(const SettingsClosedEvent());
|
bloc.add(const ScreenOnTopClosedEvent());
|
||||||
bloc.add(const SettingsClosedEvent());
|
bloc.add(const ScreenOnTopClosedEvent());
|
||||||
bloc.add(const SettingsClosedEvent());
|
bloc.add(const ScreenOnTopClosedEvent());
|
||||||
bloc.add(const SettingsOpenedEvent());
|
bloc.add(const ScreenOnTopOpenedEvent());
|
||||||
bloc.add(const SettingsClosedEvent());
|
bloc.add(const ScreenOnTopClosedEvent());
|
||||||
},
|
},
|
||||||
expect: () => [
|
expect: () => [
|
||||||
isA<SettingsOpenedState>(),
|
isA<SettingsOpenedState>(),
|
||||||
|
|
Loading…
Reference in a new issue