mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +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/interactors/metering_interactor.dart';
|
||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
|
||||
as communication_events;
|
||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
||||
as communication_states;
|
||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events;
|
||||
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/state_metering.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<MeasuredEvent>(_onMeasured);
|
||||
on<MeasureErrorEvent>(_onMeasureError);
|
||||
on<SettingsOpenedEvent>(_onSettingsOpened);
|
||||
on<SettingsClosedEvent>(_onSettingsClosed);
|
||||
on<ScreenOnTopOpenedEvent>(_onSettingsOpened);
|
||||
on<ScreenOnTopClosedEvent>(_onSettingsClosed);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -191,11 +189,11 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSettingsOpened(SettingsOpenedEvent _, Emitter __) {
|
||||
_communicationBloc.add(const communication_events.SettingsOpenedEvent());
|
||||
void _onSettingsOpened(ScreenOnTopOpenedEvent _, Emitter __) {
|
||||
_communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent());
|
||||
}
|
||||
|
||||
void _onSettingsClosed(SettingsClosedEvent _, Emitter __) {
|
||||
_communicationBloc.add(const communication_events.SettingsClosedEvent());
|
||||
void _onSettingsClosed(ScreenOnTopClosedEvent _, Emitter __) {
|
||||
_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/state_communication_metering.dart';
|
||||
|
||||
class MeteringCommunicationBloc
|
||||
extends Bloc<MeteringCommunicationEvent, MeteringCommunicationState> {
|
||||
class MeteringCommunicationBloc extends Bloc<MeteringCommunicationEvent, MeteringCommunicationState> {
|
||||
MeteringCommunicationBloc() : super(const InitState()) {
|
||||
// `MeasureState` is not const, so that `Bloc` treats each state as new and updates state stream
|
||||
// ignore: prefer_const_constructors
|
||||
on<MeasureEvent>((_, emit) => emit(MeasureState()));
|
||||
on<MeteringInProgressEvent>((event, emit) => emit(MeteringInProgressState(event.ev100)));
|
||||
on<MeteringEndedEvent>((event, emit) => emit(MeteringEndedState(event.ev100)));
|
||||
on<SettingsOpenedEvent>((_, emit) => emit(const SettingsOpenedState()));
|
||||
on<SettingsClosedEvent>((_, emit) => emit(const SettingsClosedState()));
|
||||
on<ScreenOnTopOpenedEvent>((_, emit) => emit(const SettingsOpenedState()));
|
||||
on<ScreenOnTopClosedEvent>((_, emit) => emit(const SettingsClosedState()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ class MeteringEndedEvent extends MeasuredEvent {
|
|||
int get hashCode => Object.hash(ev100, runtimeType);
|
||||
}
|
||||
|
||||
class SettingsOpenedEvent extends ScreenEvent {
|
||||
const SettingsOpenedEvent();
|
||||
class ScreenOnTopOpenedEvent extends ScreenEvent {
|
||||
const ScreenOnTopOpenedEvent();
|
||||
}
|
||||
|
||||
class SettingsClosedEvent extends ScreenEvent {
|
||||
const SettingsClosedEvent();
|
||||
class ScreenOnTopClosedEvent extends ScreenEvent {
|
||||
const ScreenOnTopClosedEvent();
|
||||
}
|
||||
|
|
|
@ -39,10 +39,10 @@ class MeasureErrorEvent extends MeteringEvent {
|
|||
const MeasureErrorEvent({required this.isMetering});
|
||||
}
|
||||
|
||||
class SettingsOpenedEvent extends MeteringEvent {
|
||||
const SettingsOpenedEvent();
|
||||
class ScreenOnTopOpenedEvent extends MeteringEvent {
|
||||
const ScreenOnTopOpenedEvent();
|
||||
}
|
||||
|
||||
class SettingsClosedEvent extends MeteringEvent {
|
||||
const SettingsClosedEvent();
|
||||
class ScreenOnTopClosedEvent extends MeteringEvent {
|
||||
const ScreenOnTopClosedEvent();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class MeteringScreen extends StatelessWidget {
|
|||
nd: state.nd,
|
||||
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(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
|
||||
: null,
|
||||
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||
onSettings: () {
|
||||
context.read<MeteringBloc>().add(const SettingsOpenedEvent());
|
||||
Navigator.pushNamed(context, 'settings').then((_) {
|
||||
context.read<MeteringBloc>().add(const SettingsClosedEvent());
|
||||
});
|
||||
},
|
||||
onSettings: () => pushNamed(context, 'settings'),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -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 {
|
||||
|
|
|
@ -3,10 +3,8 @@ import 'package:lightmeter/data/models/volume_action.dart';
|
|||
import 'package:lightmeter/interactors/metering_interactor.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/event_communication_metering.dart'
|
||||
as communication_events;
|
||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
|
||||
as communication_states;
|
||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events;
|
||||
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/state_metering.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 _MockMeteringCommunicationBloc extends MockBloc<
|
||||
communication_events.MeteringCommunicationEvent,
|
||||
communication_states.MeteringCommunicationState> implements MeteringCommunicationBloc {}
|
||||
class _MockMeteringCommunicationBloc
|
||||
extends MockBloc<communication_events.MeteringCommunicationEvent, communication_states.MeteringCommunicationState>
|
||||
implements MeteringCommunicationBloc {}
|
||||
|
||||
void main() {
|
||||
late _MockMeteringInteractor meteringInteractor;
|
||||
|
@ -515,20 +513,18 @@ void main() {
|
|||
);
|
||||
|
||||
group(
|
||||
'`SettingOpenedEvent`/`SettingsClosedEvent`',
|
||||
'`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`',
|
||||
() {
|
||||
blocTest<MeteringBloc, MeteringState>(
|
||||
'Settings opened & closed',
|
||||
build: () => bloc,
|
||||
act: (bloc) async {
|
||||
bloc.add(const SettingsOpenedEvent());
|
||||
bloc.add(const SettingsClosedEvent());
|
||||
bloc.add(const ScreenOnTopOpenedEvent());
|
||||
bloc.add(const ScreenOnTopClosedEvent());
|
||||
},
|
||||
verify: (_) {
|
||||
verify(() => communicationBloc.add(const communication_events.SettingsOpenedEvent()))
|
||||
.called(1);
|
||||
verify(() => communicationBloc.add(const communication_events.SettingsClosedEvent()))
|
||||
.called(1);
|
||||
verify(() => communicationBloc.add(const communication_events.ScreenOnTopOpenedEvent())).called(1);
|
||||
verify(() => communicationBloc.add(const communication_events.ScreenOnTopClosedEvent())).called(1);
|
||||
},
|
||||
expect: () => [],
|
||||
);
|
||||
|
|
|
@ -100,20 +100,20 @@ void main() {
|
|||
);
|
||||
|
||||
group(
|
||||
'`SettingsOpenedEvent`/`SettingsClosedEvent`',
|
||||
'`ScreenOnTopOpenedEvent`/`ScreenOnTopClosedEvent`',
|
||||
() {
|
||||
blocTest<MeteringCommunicationBloc, MeteringCommunicationState>(
|
||||
'Multiple consequtive settings events',
|
||||
build: () => bloc,
|
||||
act: (bloc) async {
|
||||
bloc.add(const SettingsOpenedEvent());
|
||||
bloc.add(const SettingsOpenedEvent());
|
||||
bloc.add(const SettingsOpenedEvent());
|
||||
bloc.add(const SettingsClosedEvent());
|
||||
bloc.add(const SettingsClosedEvent());
|
||||
bloc.add(const SettingsClosedEvent());
|
||||
bloc.add(const SettingsOpenedEvent());
|
||||
bloc.add(const SettingsClosedEvent());
|
||||
bloc.add(const ScreenOnTopOpenedEvent());
|
||||
bloc.add(const ScreenOnTopOpenedEvent());
|
||||
bloc.add(const ScreenOnTopOpenedEvent());
|
||||
bloc.add(const ScreenOnTopClosedEvent());
|
||||
bloc.add(const ScreenOnTopClosedEvent());
|
||||
bloc.add(const ScreenOnTopClosedEvent());
|
||||
bloc.add(const ScreenOnTopOpenedEvent());
|
||||
bloc.add(const ScreenOnTopClosedEvent());
|
||||
},
|
||||
expect: () => [
|
||||
isA<SettingsOpenedState>(),
|
||||
|
|
Loading…
Reference in a new issue