Skip to content

Commit

Permalink
ML-58 Metering UX improvements (#63)
Browse files Browse the repository at this point in the history
* indicate EV value error

* allow nullable ev100 in `CameraContainerBloc`

* log exif keys

* wip

* removed `UserPreferencesService` from `MeteringBloc`

* added error toast

* conflicts

* lints

* allow stop metering if `hasError`

* fixed `AnimatedDialogPicker` inability to close

* Update build.gradle
  • Loading branch information
vodemn authored May 16, 2023
1 parent 5602b1e commit ec9ba1a
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 142 deletions.
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"name": "dev (android)",
"request": "launch",
"type": "dart",
//"flutterMode": "profile",
"args": [
"--flavor",
"dev",
Expand All @@ -21,7 +20,6 @@
"name": "dev (ios)",
"request": "launch",
"type": "dart",
//"flutterMode": "release",
"args": [
"--flavor",
"dev",
Expand Down
11 changes: 7 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) {

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
Expand All @@ -33,6 +33,10 @@ apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

gradle.beforeProject({ project->
project.setProperty("target-platform", "android-arm,android-arm64")
})

android {
compileSdkVersion 33
ndkVersion flutter.ndkVersion
Expand All @@ -53,8 +57,7 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
ndk.abiFilters 'arm64-v8a', 'armeabi-v7a'
targetSdkVersion flutter.targetSdkVersion
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a'
/// legacy material-lightmeter ap stopped updating after 60022
/// 7xxxx means that it is a new app
versionCode 70000 + flutterVersionCode.toInteger()
Expand Down Expand Up @@ -92,7 +95,7 @@ android {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
ndk.abiFilters 'arm64-v8a', 'armeabi-v7a'
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
4 changes: 3 additions & 1 deletion lib/data/haptics_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class HapticsService {

Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128);

Future<void> errorVibration() async => _tryVibrate(duration: 100, amplitude: 128);

Future<void> _tryVibrate({required int duration, required int amplitude}) async {
if (await _canVibrate()) {
Vibration.vibrate(
await Vibration.vibrate(
duration: duration,
amplitude: amplitude,
);
Expand Down
24 changes: 19 additions & 5 deletions lib/interactors/metering_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'package:app_settings/app_settings.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:permission_handler/permission_handler.dart';

class MeteringInteractor {
Expand All @@ -30,16 +32,28 @@ class MeteringInteractor {
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
double get lightSensorEvCalibration => _userPreferencesService.lightSensorEvCalibration;

bool get isHapticsEnabled => _userPreferencesService.haptics;
IsoValue get iso => _userPreferencesService.iso;
set iso(IsoValue value) => _userPreferencesService.iso = value;

NdValue get ndFilter => _userPreferencesService.ndFilter;
set ndFilter(NdValue value) => _userPreferencesService.ndFilter = value;

Film get film => _userPreferencesService.film;
set film(Film value) => _userPreferencesService.film = value;

/// Executes vibration if haptics are enabled in settings
Future<void> quickVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
}

/// Executes vibration if haptics are enabled in settings
void quickVibration() {
if (_userPreferencesService.haptics) _hapticsService.quickVibration();
Future<void> responseVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.responseVibration();
}

/// Executes vibration if haptics are enabled in settings
void responseVibration() {
if (_userPreferencesService.haptics) _hapticsService.responseVibration();
Future<void> errorVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.errorVibration();
}

Future<bool> checkCameraPermission() async {
Expand Down
103 changes: 61 additions & 42 deletions lib/screens/metering/bloc_metering.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:math';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/shared_prefs_service.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'
Expand All @@ -17,7 +16,6 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';

class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
final MeteringCommunicationBloc _communicationBloc;
final UserPreferencesService _userPreferencesService;
final MeteringInteractor _meteringInteractor;
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;

Expand All @@ -29,25 +27,25 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
EquipmentProfileData _equipmentProfileData;
StopType stopType;

late IsoValue _iso = _userPreferencesService.iso;
late NdValue _nd = _userPreferencesService.ndFilter;
late Film _film = _userPreferencesService.film;
double _ev100 = 0.0;
late IsoValue _iso = _meteringInteractor.iso;
late NdValue _nd = _meteringInteractor.ndFilter;
late Film _film = _meteringInteractor.film;
double? _ev100 = 0.0;
bool _isMeteringInProgress = false;

MeteringBloc(
this._communicationBloc,
this._userPreferencesService,
this._meteringInteractor,
this._equipmentProfileData,
this.stopType,
) : super(
MeteringEndedState(
MeteringDataState(
ev: 0.0,
film: _userPreferencesService.film,
iso: _userPreferencesService.iso,
nd: _userPreferencesService.ndFilter,
film: _meteringInteractor.film,
iso: _meteringInteractor.iso,
nd: _meteringInteractor.ndFilter,
exposurePairs: const [],
continuousMetering: false,
),
) {
_communicationSubscription = _communicationBloc.stream
Expand All @@ -62,6 +60,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
on<NdChangedEvent>(_onNdChanged);
on<MeasureEvent>(_onMeasure);
on<MeasuredEvent>(_onMeasured);
on<MeasureErrorEvent>(_onMeasureError);
}

@override
Expand All @@ -73,13 +72,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
void _onCommunicationState(communication_states.ScreenState communicationState) {
if (communicationState is communication_states.MeasuredState) {
_isMeteringInProgress = communicationState is communication_states.MeteringInProgressState;
add(MeasuredEvent(communicationState.ev100));
_handleEv100(communicationState.ev100);
}
}

void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
stopType = event.stopType;
_emitMeasuredState(emit);
_updateMeasurements();
}

void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
Expand All @@ -88,17 +87,17 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
/// Update selected ISO value, if selected equipment profile
/// doesn't contain currently selected value
if (!event.equipmentProfileData.isoValues.any((v) => _iso.value == v.value)) {
_userPreferencesService.iso = event.equipmentProfileData.isoValues.first;
_meteringInteractor.iso = event.equipmentProfileData.isoValues.first;
_iso = event.equipmentProfileData.isoValues.first;
}

/// The same for ND filter
if (!event.equipmentProfileData.ndValues.any((v) => _nd.value == v.value)) {
_userPreferencesService.ndFilter = event.equipmentProfileData.ndValues.first;
_meteringInteractor.ndFilter = event.equipmentProfileData.ndValues.first;
_nd = event.equipmentProfileData.ndValues.first;
}

_emitMeasuredState(emit);
_updateMeasurements();
}

void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
Expand All @@ -110,56 +109,76 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
add(IsoChangedEvent(newIso));
}
_film = event.data;
_userPreferencesService.film = event.data;
_emitMeasuredState(emit);
_meteringInteractor.film = event.data;
_updateMeasurements();
}

void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
if (event.isoValue.value != _film.iso) {
_film = Film.values.first;
}
_userPreferencesService.iso = event.isoValue;
_meteringInteractor.iso = event.isoValue;
_iso = event.isoValue;
_emitMeasuredState(emit);
_updateMeasurements();
}

void _onNdChanged(NdChangedEvent event, Emitter emit) {
_userPreferencesService.ndFilter = event.ndValue;
_meteringInteractor.ndFilter = event.ndValue;
_nd = event.ndValue;
_emitMeasuredState(emit);
_updateMeasurements();
}

void _onMeasure(_, Emitter emit) {
void _onMeasure(MeasureEvent _, Emitter emit) {
_meteringInteractor.quickVibration();
_communicationBloc.add(const communication_events.MeasureEvent());
_isMeteringInProgress = true;
emit(const LoadingState());
emit(
LoadingState(
film: _film,
iso: _iso,
nd: _nd,
),
);
}

void _updateMeasurements() => _handleEv100(_ev100);

void _handleEv100(double? ev100) {
if (ev100 == null || ev100.isNaN || ev100.isInfinite) {
add(const MeasureErrorEvent());
} else {
add(MeasuredEvent(ev100));
}
}

void _onMeasured(MeasuredEvent event, Emitter emit) {
_meteringInteractor.responseVibration();
_ev100 = event.ev100;
_emitMeasuredState(emit);
final ev = event.ev100 + log2(_iso.value / 100) - _nd.stopReduction;
emit(
MeteringDataState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
continuousMetering: _isMeteringInProgress,
),
);
}

void _emitMeasuredState(Emitter emit) {
final ev = _ev100 + log2(_iso.value / 100) - _nd.stopReduction;
void _onMeasureError(MeasureErrorEvent _, Emitter emit) {
_meteringInteractor.errorVibration();
_ev100 = null;
emit(
_isMeteringInProgress
? MeteringInProgressState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
)
: MeteringEndedState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
),
MeteringDataState(
ev: null,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: const [],
continuousMetering: _isMeteringInProgress,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MeasureEvent extends ScreenEvent {
}

abstract class MeasuredEvent extends SourceEvent {
final double ev100;
final double? ev100;

const MeasuredEvent(this.ev100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MeasureState extends SourceState {
}

abstract class MeasuredState extends ScreenState {
final double ev100;
final double? ev100;

const MeasuredState(this.ev100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dar
class MeteringMeasureButton extends StatefulWidget {
final double? ev;
final bool isMetering;
final bool hasError;
final VoidCallback onTap;

const MeteringMeasureButton({
required this.ev,
required this.isMetering,
required this.hasError,
required this.onTap,
super.key,
});
Expand All @@ -33,7 +35,7 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
@override
Widget build(BuildContext context) {
return IgnorePointer(
ignoring: widget.isMetering && widget.ev == null,
ignoring: widget.isMetering && widget.ev == null && !widget.hasError,
child: GestureDetector(
onTap: widget.onTap,
onTapDown: (_) {
Expand Down Expand Up @@ -63,7 +65,13 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
color: Theme.of(context).colorScheme.onSurface,
size: Dimens.grid72 - Dimens.grid8,
child: Center(
child: widget.ev != null ? _EvValueText(ev: widget.ev!) : null,
child: widget.hasError
? Icon(
Icons.error_outline,
color: Theme.of(context).colorScheme.surface,
size: Dimens.grid24,
)
: (widget.ev != null ? _EvValueText(ev: widget.ev!) : null),
),
),
),
Expand Down Expand Up @@ -91,13 +99,6 @@ class _EvValueText extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (ev.isNaN || ev.isInfinite) {
return Icon(
Icons.error,
color: Theme.of(context).colorScheme.surface,
);
}

final theme = Theme.of(context);
return Text(
'${ev.toStringAsFixed(1)}\n${S.of(context).ev}',
Expand Down
Loading

0 comments on commit ec9ba1a

Please sign in to comment.