diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..ba40f08
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,30 @@
+---
+name: Bug report
+about: Create a bug report to help improve the app
+title: ''
+labels: bug
+assignees: vodemn
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Device:**
+ - Device: [e.g. Pixel 6]
+ - OS: [e.g. Android 12]
+
+**App version**
diff --git a/.github/ISSUE_TEMPLATE/feature-request-or-improvement.md b/.github/ISSUE_TEMPLATE/feature-request-or-improvement.md
new file mode 100644
index 0000000..381e939
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature-request-or-improvement.md
@@ -0,0 +1,20 @@
+---
+name: Feature request or improvement
+about: Suggest an idea for this project
+title: ''
+labels: feature
+assignees: vodemn
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
diff --git a/README.md b/README.md
index c801a9c..0b4dae8 100644
--- a/README.md
+++ b/README.md
@@ -1,58 +1,48 @@
-
-
-
-
- Material Lightmeter
-
+
# Table of contents
- [Table of contents](#table-of-contents)
- [Backstory](#backstory)
-- [Legacy features](#legacy-features)
+- [Screenshots](#screenshots)
- [Build](#build)
- [Contribution](#contribution)
+- [iOS Limitations](#ios-limitations)
# Backstory
Some time ago I've started developing the [Material Lightmeter](https://play.google.com/store/apps/details?id=com.vodemn.lightmeter&hl=en&gl=US) app. Unfortunately, the last update of this app was almost a year prior to creation of this repo. So after reading some positive review on Google Play saying that "this is an excellent app, too bad it is no longer updated", I've decided to make an update and also make this app open source. Maybe someone sometime will decide to contribute to this project.
-But as the existing repo contained some sensitive data, that I've pushed due to lack of experience, I had to make a new one. And if creating a new repo, why not rewrite the app from scratch?)
+But as the existing repo contained some sensitive data, that I've pushed due to lack of experience, I had to make a new one. And if creating a new repo, why not rewrite the app from scratch?
Without further delay behold my new Lightmeter app inspired by Material You (a.k.a. M3)
-# Legacy features
+# Screenshots
-The list of features that the old lightmeter app has and that have to be implemeneted in the M3 lightmeter.
+
+
+
+
+
+
+
-### Metering
-- [x] ISO selecting
-- [x] Reciprocity for different films
-- [x] Reflected light metering
-- [x] Incident light metering
-
-### Adjust
-- [x] Light sources EV calibration
-- [ ] Customizable aperture range
-- [ ] Customizable shutter speed range
-- [x] ND filter select
-
-### General
-- [x] Caffeine
-- [x] Vibration
-- [ ] Volume button actions
-
-### Theme
-- [x] Dark theme
-- [x] Picking primary color
-- [x] Russian language
-
-## Build
+# Build
As part of this project is private, you will be able to run this app from the _main_dev.dart_ file (i.e. --flavor dev). Also to avoid fatal errors the _main_prod.dart_ file is excluded from analysis.
-## Contribution
+# Contribution
To report a bug or suggest a new feature open a new [issue](https://github.com/vodemn/m3_lightmeter/issues).
In case you want to help develop this project you need to follow this [style guide](doc/style_guide.md).
+
+# iOS Limitations
+
+A list of features, that Android version of the app has and that iOS does not.
+
+## Incident light metering
+Apple does not provide API for reading Lux stream form the ambient light sensor. Lux can be calculated based on front camera image stream, but this would be a reflected light. So there is no way incident light metering can be implemented on iOS.
+
+## Volume buttons action
+This can be [implemented](https://stackoverflow.com/questions/70161271/ios-override-hardware-volume-buttons-same-as-zello) but the app will be rejected due to [2.5.9](https://developer.apple.com/app-store/review/guidelines/#software-requirements)
\ No newline at end of file
diff --git a/android/app/src/main/kotlin/com/vodemn/lightmeter/MainActivity.kt b/android/app/src/main/kotlin/com/vodemn/lightmeter/MainActivity.kt
index ea040d6..af458c4 100644
--- a/android/app/src/main/kotlin/com/vodemn/lightmeter/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/vodemn/lightmeter/MainActivity.kt
@@ -1,13 +1,22 @@
package com.vodemn.lightmeter
import android.os.Bundle
+import android.view.KeyEvent
import android.view.WindowManager
import androidx.core.view.WindowCompat
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
+import io.flutter.plugin.common.EventChannel
+import io.flutter.plugin.common.EventChannel.EventSink
import io.flutter.plugin.common.MethodChannel
class MainActivity : FlutterActivity() {
+ private lateinit var keepScreenOnChannel: MethodChannel
+ private lateinit var volumeHandlingChannel: MethodChannel
+ private lateinit var volumeEventChannel: EventChannel
+ private var volumeEventsEmitter: EventSink? = null
+ private var handleVolume = false
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
@@ -15,10 +24,11 @@ class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
- MethodChannel(
+ keepScreenOnChannel = MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"com.vodemn.lightmeter/keepScreenOn"
- ).setMethodCallHandler { call, result ->
+ )
+ keepScreenOnChannel.setMethodCallHandler { call, result ->
when (call.method) {
"isKeepScreenOn" -> result.success((window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0)
"setKeepScreenOn" -> {
@@ -33,5 +43,53 @@ class MainActivity : FlutterActivity() {
else -> result.notImplemented()
}
}
+
+ volumeHandlingChannel = MethodChannel(
+ flutterEngine.dartExecutor.binaryMessenger,
+ "com.vodemn.lightmeter/volumeHandling"
+ )
+ volumeHandlingChannel.setMethodCallHandler { call, result ->
+ when (call.method) {
+ "setVolumeHandling" -> {
+ handleVolume = call.arguments as Boolean
+ result.success(handleVolume)
+ }
+ else -> result.notImplemented()
+ }
+ }
+
+ volumeEventChannel = EventChannel(
+ flutterEngine.dartExecutor.binaryMessenger,
+ "com.vodemn.lightmeter/volumeEvents"
+ )
+ volumeEventChannel.setStreamHandler(object : EventChannel.StreamHandler {
+ override fun onListen(listener: Any?, eventSink: EventSink) {
+ volumeEventsEmitter = eventSink
+ }
+ override fun onCancel(listener: Any?) {
+ volumeEventsEmitter = null
+ }
+ })
+ }
+
+ override fun onDestroy() {
+ keepScreenOnChannel.setMethodCallHandler(null)
+ volumeHandlingChannel.setMethodCallHandler(null)
+ volumeEventChannel.setStreamHandler(null)
+ super.onDestroy()
+ }
+
+ override fun onKeyDown(code: Int, event: KeyEvent): Boolean {
+ return when (val keyCode: Int = event.keyCode) {
+ KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
+ if (handleVolume) {
+ volumeEventsEmitter?.success(keyCode)
+ true
+ } else {
+ super.onKeyDown(code, event)
+ }
+ }
+ else -> super.onKeyDown(code, event)
+ }
}
}
diff --git a/lib/data/light_sensor_service.dart b/lib/data/light_sensor_service.dart
index 69b55c5..c837dde 100644
--- a/lib/data/light_sensor_service.dart
+++ b/lib/data/light_sensor_service.dart
@@ -1,9 +1,15 @@
import 'package:light_sensor/light_sensor.dart';
+import 'package:platform/platform.dart';
class LightSensorService {
- const LightSensorService();
+ final LocalPlatform localPlatform;
+
+ const LightSensorService(this.localPlatform);
Future hasSensor() async {
+ if (!localPlatform.isAndroid) {
+ return false;
+ }
try {
return await LightSensor.hasSensor ?? false;
} catch (_) {
@@ -11,5 +17,10 @@ class LightSensorService {
}
}
- Stream luxStream() => LightSensor.lightSensorStream;
+ Stream luxStream() {
+ if (!localPlatform.isAndroid) {
+ return const Stream.empty();
+ }
+ return LightSensor.lightSensorStream;
+ }
}
diff --git a/lib/data/models/volume_action.dart b/lib/data/models/volume_action.dart
new file mode 100644
index 0000000..b28f9dc
--- /dev/null
+++ b/lib/data/models/volume_action.dart
@@ -0,0 +1,3 @@
+enum VolumeAction { shutter, none }
+
+enum VolumeKey { up, down }
diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart
index 8fbb6af..76f9045 100644
--- a/lib/data/shared_prefs_service.dart
+++ b/lib/data/shared_prefs_service.dart
@@ -6,6 +6,7 @@ import 'package:lightmeter/data/models/film.dart';
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/models/theme_type.dart';
+import 'package:lightmeter/data/models/volume_action.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -22,6 +23,7 @@ class UserPreferencesService {
static const caffeineKey = "caffeine";
static const hapticsKey = "haptics";
+ static const volumeActionKey = "volumeAction";
static const localeKey = "locale";
static const themeTypeKey = "themeType";
@@ -82,9 +84,6 @@ class UserPreferencesService {
EvSourceType.values[_sharedPreferences.getInt(evSourceTypeKey) ?? 0];
set evSourceType(EvSourceType value) => _sharedPreferences.setInt(evSourceTypeKey, value.index);
- bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false;
- set caffeine(bool value) => _sharedPreferences.setBool(caffeineKey, value);
-
StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2];
set stopType(StopType value) => _sharedPreferences.setInt(stopTypeKey, value.index);
@@ -105,9 +104,19 @@ class UserPreferencesService {
set meteringScreenLayout(MeteringScreenLayoutConfig value) =>
_sharedPreferences.setString(meteringScreenLayoutKey, json.encode(value.toJson()));
+ bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false;
+ set caffeine(bool value) => _sharedPreferences.setBool(caffeineKey, value);
+
bool get haptics => _sharedPreferences.getBool(hapticsKey) ?? true;
set haptics(bool value) => _sharedPreferences.setBool(hapticsKey, value);
+ VolumeAction get volumeAction => VolumeAction.values.firstWhere(
+ (e) => e.toString() == _sharedPreferences.getString(volumeActionKey),
+ orElse: () => VolumeAction.shutter,
+ );
+ set volumeAction(VolumeAction value) =>
+ _sharedPreferences.setString(volumeActionKey, value.toString());
+
SupportedLocale get locale => SupportedLocale.values.firstWhere(
(e) => e.toString() == _sharedPreferences.getString(localeKey),
orElse: () => SupportedLocale.en,
diff --git a/lib/data/volume_events_service.dart b/lib/data/volume_events_service.dart
new file mode 100644
index 0000000..d57936a
--- /dev/null
+++ b/lib/data/volume_events_service.dart
@@ -0,0 +1,40 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
+import 'package:platform/platform.dart';
+
+class VolumeEventsService {
+ final LocalPlatform localPlatform;
+
+ @visibleForTesting
+ static const volumeHandlingChannel = MethodChannel("com.vodemn.lightmeter/volumeHandling");
+
+ @visibleForTesting
+ static const volumeEventsChannel = EventChannel("com.vodemn.lightmeter/volumeEvents");
+
+ const VolumeEventsService(this.localPlatform);
+
+ /// If set to `false` we allow system to handle key events.
+ /// Returns current status of volume handling.
+ Future setVolumeHandling(bool enableHandling) async {
+ if (!localPlatform.isAndroid) {
+ return false;
+ }
+ return volumeHandlingChannel
+ .invokeMethod("setVolumeHandling", enableHandling)
+ .then((value) => value!);
+ }
+
+ /// Emits new events on
+ /// KEYCODE_VOLUME_UP = 24;
+ /// KEYCODE_VOLUME_DOWN = 25;
+ /// pressed
+ Stream volumeButtonsEventStream() {
+ if (!localPlatform.isAndroid) {
+ return const Stream.empty();
+ }
+ return volumeEventsChannel
+ .receiveBroadcastStream()
+ .cast()
+ .where((event) => event == 24 || event == 25);
+ }
+}
diff --git a/lib/environment.dart b/lib/environment.dart
index c2e43c7..69ba143 100644
--- a/lib/environment.dart
+++ b/lib/environment.dart
@@ -19,14 +19,14 @@ class Environment {
const Environment.dev()
: buildType = BuildType.dev,
sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter',
- issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues',
+ issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues/new/choose',
contactEmail = 'contact.vodemn@gmail.com',
hasLightSensor = false;
const Environment.prod()
: buildType = BuildType.prod,
sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter',
- issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues',
+ issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues/new/choose',
contactEmail = 'contact.vodemn@gmail.com',
hasLightSensor = false;
diff --git a/lib/interactors/metering_interactor.dart b/lib/interactors/metering_interactor.dart
index ca94f8e..34b03ec 100644
--- a/lib/interactors/metering_interactor.dart
+++ b/lib/interactors/metering_interactor.dart
@@ -1,12 +1,12 @@
-import 'dart:io';
-
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/models/volume_action.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:permission_handler/permission_handler.dart';
@@ -16,6 +16,7 @@ class MeteringInteractor {
final HapticsService _hapticsService;
final PermissionsService _permissionsService;
final LightSensorService _lightSensorService;
+ final VolumeEventsService _volumeEventsService;
MeteringInteractor(
this._userPreferencesService,
@@ -23,10 +24,13 @@ class MeteringInteractor {
this._hapticsService,
this._permissionsService,
this._lightSensorService,
+ this._volumeEventsService,
) {
if (_userPreferencesService.caffeine) {
_caffeineService.keepScreenOn(true);
}
+ _volumeEventsService
+ .setVolumeHandling(_userPreferencesService.volumeAction != VolumeAction.none);
}
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
@@ -42,6 +46,8 @@ class MeteringInteractor {
Film get film => _userPreferencesService.film;
set film(Film value) => _userPreferencesService.film = value;
+ VolumeAction get volumeAction => _userPreferencesService.volumeAction;
+
/// Executes vibration if haptics are enabled in settings
Future quickVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
@@ -73,13 +79,7 @@ class MeteringInteractor {
AppSettings.openAppSettings();
}
- Future hasAmbientLightSensor() async {
- if (Platform.isAndroid) {
- return _lightSensorService.hasSensor();
- } else {
- return false;
- }
- }
+ Future hasAmbientLightSensor() async => _lightSensorService.hasSensor();
Stream luxStream() => _lightSensorService.luxStream();
}
diff --git a/lib/interactors/settings_interactor.dart b/lib/interactors/settings_interactor.dart
index db99a7a..4eeb8b9 100644
--- a/lib/interactors/settings_interactor.dart
+++ b/lib/interactors/settings_interactor.dart
@@ -1,16 +1,20 @@
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
+import 'package:lightmeter/data/models/volume_action.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
class SettingsInteractor {
final UserPreferencesService _userPreferencesService;
final CaffeineService _caffeineService;
final HapticsService _hapticsService;
+ final VolumeEventsService _volumeEventsService;
const SettingsInteractor(
this._userPreferencesService,
this._caffeineService,
this._hapticsService,
+ this._volumeEventsService,
);
double get cameraEvCalibration => _userPreferencesService.cameraEvCalibration;
@@ -27,6 +31,20 @@ class SettingsInteractor {
});
}
+ Future disableVolumeHandling() async {
+ await _volumeEventsService.setVolumeHandling(false);
+ }
+ Future restoreVolumeHandling() async {
+ await _volumeEventsService
+ .setVolumeHandling(_userPreferencesService.volumeAction != VolumeAction.none);
+ }
+
+ VolumeAction get volumeAction => _userPreferencesService.volumeAction;
+ Future setVolumeAction(VolumeAction value) async {
+ await _volumeEventsService.setVolumeHandling(value != VolumeAction.none);
+ _userPreferencesService.volumeAction = value;
+ }
+
bool get isHapticsEnabled => _userPreferencesService.haptics;
void enableHaptics(bool enable) {
_userPreferencesService.haptics = enable;
diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb
index c404d33..39700b8 100644
--- a/lib/l10n/intl_en.arb
+++ b/lib/l10n/intl_en.arb
@@ -56,6 +56,7 @@
"general": "General",
"keepScreenOn": "Keep screen on",
"haptics": "Haptics",
+ "volumeKeysAction": "Shutter by volume keys",
"language": "Language",
"chooseLanguage": "Choose language",
"theme": "Theme",
diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb
index 5102a59..5957d0d 100644
--- a/lib/l10n/intl_fr.arb
+++ b/lib/l10n/intl_fr.arb
@@ -56,6 +56,7 @@
"general": "Général",
"keepScreenOn": "Garder l'écran allumé",
"haptics": "Haptiques",
+ "volumeKeysAction": "Obturateur par boutons de volume",
"language": "Langue",
"chooseLanguage": "Choisissez la langue",
"theme": "Thème",
diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb
index ca746dd..f6b3833 100644
--- a/lib/l10n/intl_ru.arb
+++ b/lib/l10n/intl_ru.arb
@@ -56,6 +56,7 @@
"general": "Общие",
"keepScreenOn": "Запрет блокировки",
"haptics": "Вибрация",
+ "volumeKeysAction": "Затвор по кнопкам громкости",
"language": "Язык",
"chooseLanguage": "Выберите язык",
"theme": "Тема",
diff --git a/lib/main_prod.dart b/lib/main_prod.dart
index bf02374..a47d421 100644
--- a/lib/main_prod.dart
+++ b/lib/main_prod.dart
@@ -6,6 +6,5 @@ import 'package:lightmeter/firebase.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeFirebase();
-
runApp(const Application(Environment.prod()));
}
diff --git a/lib/providers.dart b/lib/providers.dart
index 7805e69..d7907ab 100644
--- a/lib/providers.dart
+++ b/lib/providers.dart
@@ -1,11 +1,10 @@
-import 'dart:io';
-
import 'package:flutter/material.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/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/providers/ev_source_type_provider.dart';
@@ -14,6 +13,7 @@ import 'package:lightmeter/providers/stop_type_provider.dart';
import 'package:lightmeter/providers/supported_locale_provider.dart';
import 'package:lightmeter/providers/theme_provider.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
+import 'package:platform/platform.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LightmeterProviders extends StatelessWidget {
@@ -27,7 +27,7 @@ class LightmeterProviders extends StatelessWidget {
return FutureBuilder(
future: Future.wait([
SharedPreferences.getInstance(),
- if (Platform.isAndroid) const LightSensorService().hasSensor() else Future.value(false),
+ const LightSensorService(LocalPlatform()).hasSensor(),
]),
builder: (_, snapshot) {
if (snapshot.data != null) {
@@ -36,21 +36,24 @@ class LightmeterProviders extends StatelessWidget {
child: InheritedWidgetBase(
data: UserPreferencesService(snapshot.data![0] as SharedPreferences),
child: InheritedWidgetBase(
- data: const LightSensorService(),
+ data: const LightSensorService(LocalPlatform()),
child: InheritedWidgetBase(
data: const CaffeineService(),
child: InheritedWidgetBase(
data: const HapticsService(),
- child: InheritedWidgetBase(
- data: const PermissionsService(),
- child: MeteringScreenLayoutProvider(
- child: StopTypeProvider(
- child: EquipmentProfileProvider(
- child: EvSourceTypeProvider(
- child: SupportedLocaleProvider(
- child: ThemeProvider(
- child: Builder(
- builder: (context) => builder(context, true),
+ child: InheritedWidgetBase(
+ data: const VolumeEventsService(LocalPlatform()),
+ child: InheritedWidgetBase(
+ data: const PermissionsService(),
+ child: MeteringScreenLayoutProvider(
+ child: StopTypeProvider(
+ child: EquipmentProfileProvider(
+ child: EvSourceTypeProvider(
+ child: SupportedLocaleProvider(
+ child: ThemeProvider(
+ child: Builder(
+ builder: (context) => builder(context, true),
+ ),
),
),
),
diff --git a/lib/screens/metering/bloc_metering.dart b/lib/screens/metering/bloc_metering.dart
index 042991a..8e4a2f6 100644
--- a/lib/screens/metering/bloc_metering.dart
+++ b/lib/screens/metering/bloc_metering.dart
@@ -4,23 +4,27 @@ import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/film.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/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
import 'package:lightmeter/screens/metering/event_metering.dart';
import 'package:lightmeter/screens/metering/state_metering.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class MeteringBloc extends Bloc {
final MeteringInteractor _meteringInteractor;
+ final VolumeKeysNotifier _volumeKeysNotifier;
final MeteringCommunicationBloc _communicationBloc;
late final StreamSubscription _communicationSubscription;
MeteringBloc(
this._meteringInteractor,
+ this._volumeKeysNotifier,
this._communicationBloc,
) : super(
MeteringDataState(
@@ -31,6 +35,7 @@ class MeteringBloc extends Bloc {
isMetering: false,
),
) {
+ _volumeKeysNotifier.addListener(onVolumeKey);
_communicationSubscription = _communicationBloc.stream
.where((state) => state is communication_states.ScreenState)
.map((state) => state as communication_states.ScreenState)
@@ -43,6 +48,8 @@ class MeteringBloc extends Bloc {
on(_onMeasure, transformer: droppable());
on(_onMeasured);
on(_onMeasureError);
+ on(_onSettingsOpened);
+ on(_onSettingsClosed);
}
@override
@@ -64,6 +71,7 @@ class MeteringBloc extends Bloc {
@override
Future close() async {
+ _volumeKeysNotifier.removeListener(onVolumeKey);
await _communicationSubscription.cancel();
return super.close();
}
@@ -220,4 +228,19 @@ class MeteringBloc extends Bloc {
),
);
}
+
+ @visibleForTesting
+ void onVolumeKey() {
+ if (_meteringInteractor.volumeAction == VolumeAction.shutter) {
+ add(const MeasureEvent());
+ }
+ }
+
+ void _onSettingsOpened(SettingsOpenedEvent _, Emitter __) {
+ _communicationBloc.add(const communication_events.SettingsOpenedEvent());
+ }
+
+ void _onSettingsClosed(SettingsClosedEvent _, Emitter __) {
+ _communicationBloc.add(const communication_events.SettingsClosedEvent());
+ }
}
diff --git a/lib/screens/metering/communication/bloc_communication_metering.dart b/lib/screens/metering/communication/bloc_communication_metering.dart
index 1c54dc3..11ebe37 100644
--- a/lib/screens/metering/communication/bloc_communication_metering.dart
+++ b/lib/screens/metering/communication/bloc_communication_metering.dart
@@ -11,5 +11,7 @@ class MeteringCommunicationBloc
on((_, emit) => emit(MeasureState()));
on((event, emit) => emit(MeteringInProgressState(event.ev100)));
on((event, emit) => emit(MeteringEndedState(event.ev100)));
+ on((_, emit) => emit(const SettingsOpenedState()));
+ on((_, emit) => emit(const SettingsClosedState()));
}
}
diff --git a/lib/screens/metering/communication/event_communication_metering.dart b/lib/screens/metering/communication/event_communication_metering.dart
index ac63b57..c7e0fd8 100644
--- a/lib/screens/metering/communication/event_communication_metering.dart
+++ b/lib/screens/metering/communication/event_communication_metering.dart
@@ -47,3 +47,11 @@ class MeteringEndedEvent extends MeasuredEvent {
@override
int get hashCode => Object.hash(ev100, runtimeType);
}
+
+class SettingsOpenedEvent extends ScreenEvent {
+ const SettingsOpenedEvent();
+}
+
+class SettingsClosedEvent extends ScreenEvent {
+ const SettingsClosedEvent();
+}
diff --git a/lib/screens/metering/communication/state_communication_metering.dart b/lib/screens/metering/communication/state_communication_metering.dart
index 2923cf1..2d3991e 100644
--- a/lib/screens/metering/communication/state_communication_metering.dart
+++ b/lib/screens/metering/communication/state_communication_metering.dart
@@ -51,3 +51,11 @@ class MeteringEndedState extends MeasuredState {
@override
int get hashCode => Object.hash(ev100, runtimeType);
}
+
+class SettingsOpenedState extends SourceState {
+ const SettingsOpenedState();
+}
+
+class SettingsClosedState extends SourceState {
+ const SettingsClosedState();
+}
diff --git a/lib/screens/metering/components/camera_container/bloc_container_camera.dart b/lib/screens/metering/components/camera_container/bloc_container_camera.dart
index 2bb8ed1..7f00256 100644
--- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart
+++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart
@@ -23,6 +23,7 @@ import 'package:lightmeter/utils/log_2.dart';
class CameraContainerBloc extends EvSourceBlocBase {
final MeteringInteractor _meteringInteractor;
late final _WidgetsBindingObserver _observer;
+
CameraController? _cameraController;
static const _maxZoom = 7.0;
@@ -36,6 +37,8 @@ class CameraContainerBloc extends EvSourceBlocBase _onDeinitialize(DeinitializeEvent _, Emitter emit) async {
- emit(const CameraLoadingState());
- unawaited(_cameraController?.dispose().then((_) => _cameraController = null));
+ emit(const CameraInitState());
+ communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
+ await _cameraController?.dispose().then((_) => _cameraController = null);
}
Future _onZoomChanged(ZoomChangedEvent event, Emitter emit) async {
- if (_cameraController != null) {
+ if (_cameraController != null &&
+ event.value >= _zoomRange!.start &&
+ event.value <= _zoomRange!.end) {
_cameraController!.setZoomLevel(event.value);
_currentZoom = event.value;
_emitActiveState(emit);
@@ -215,13 +229,15 @@ class CameraContainerBloc extends EvSourceBlocBase _appLifecycleStateObserver(AppLifecycleState state) async {
- switch (state) {
- case AppLifecycleState.resumed:
- add(const InitializeEvent());
- case AppLifecycleState.paused:
- case AppLifecycleState.detached:
- add(const DeinitializeEvent());
- default:
+ if (!_settingsOpened) {
+ switch (state) {
+ case AppLifecycleState.resumed:
+ add(const InitializeEvent());
+ case AppLifecycleState.paused:
+ case AppLifecycleState.detached:
+ add(const DeinitializeEvent());
+ default:
+ }
}
}
}
diff --git a/lib/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart b/lib/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart
index d0e4031..23cd796 100644
--- a/lib/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart
+++ b/lib/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart
@@ -25,37 +25,44 @@ class LightSensorContainerBloc
communicationBloc,
const LightSensorContainerState(null),
) {
+ on(_onStartLuxMeteringEvent);
on(_onLuxMeteringEvent);
+ on(_onCancelLuxMeteringEvent);
}
@override
void onCommunicationState(communication_states.SourceState communicationState) {
- if (communicationState is communication_states.MeasureState) {
- if (_luxSubscriptions == null) {
- _startMetering();
- } else {
- _cancelMetering();
- }
+ switch (communicationState) {
+ case communication_states.MeasureState():
+ if (_luxSubscriptions == null) {
+ add(const StartLuxMeteringEvent());
+ } else {
+ add(const CancelLuxMeteringEvent());
+ }
+ case communication_states.SettingsOpenedState():
+ add(const CancelLuxMeteringEvent());
+ default:
}
}
@override
Future close() async {
- _cancelMetering();
+ communicationBloc.add(communication_event.MeteringEndedEvent(state.ev100));
+ _luxSubscriptions?.cancel().then((_) => _luxSubscriptions = null);
return super.close();
}
+ void _onStartLuxMeteringEvent(StartLuxMeteringEvent event, _) {
+ _luxSubscriptions = _meteringInteractor.luxStream().listen((lux) => add(LuxMeteringEvent(lux)));
+ }
+
void _onLuxMeteringEvent(LuxMeteringEvent event, Emitter emit) {
final ev100 = log2(event.lux.toDouble() / 2.5) + _meteringInteractor.lightSensorEvCalibration;
emit(LightSensorContainerState(ev100));
communicationBloc.add(communication_event.MeteringInProgressEvent(ev100));
}
- void _startMetering() {
- _luxSubscriptions = _meteringInteractor.luxStream().listen((lux) => add(LuxMeteringEvent(lux)));
- }
-
- void _cancelMetering() {
+ void _onCancelLuxMeteringEvent(CancelLuxMeteringEvent event, _) {
communicationBloc.add(communication_event.MeteringEndedEvent(state.ev100));
_luxSubscriptions?.cancel().then((_) => _luxSubscriptions = null);
}
diff --git a/lib/screens/metering/components/light_sensor_container/event_container_light_sensor.dart b/lib/screens/metering/components/light_sensor_container/event_container_light_sensor.dart
index 8db83b3..bffcadd 100644
--- a/lib/screens/metering/components/light_sensor_container/event_container_light_sensor.dart
+++ b/lib/screens/metering/components/light_sensor_container/event_container_light_sensor.dart
@@ -2,8 +2,16 @@ abstract class LightSensorContainerEvent {
const LightSensorContainerEvent();
}
+class StartLuxMeteringEvent extends LightSensorContainerEvent {
+ const StartLuxMeteringEvent();
+}
+
class LuxMeteringEvent extends LightSensorContainerEvent {
final int lux;
const LuxMeteringEvent(this.lux);
}
+
+class CancelLuxMeteringEvent extends LightSensorContainerEvent {
+ const CancelLuxMeteringEvent();
+}
diff --git a/lib/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart b/lib/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart
new file mode 100644
index 0000000..df64fdf
--- /dev/null
+++ b/lib/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart
@@ -0,0 +1,32 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:lightmeter/data/models/volume_action.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
+
+class VolumeKeysNotifier extends ChangeNotifier with RouteAware {
+ final VolumeEventsService volumeEventsService;
+ late final StreamSubscription _volumeKeysSubscription;
+ VolumeKey _value = VolumeKey.up;
+
+ VolumeKeysNotifier(this.volumeEventsService) {
+ _volumeKeysSubscription = volumeEventsService
+ .volumeButtonsEventStream()
+ .map((event) => event == 24 ? VolumeKey.up : VolumeKey.down)
+ .listen((event) {
+ value = event;
+ });
+ }
+
+ VolumeKey get value => _value;
+ set value(VolumeKey newValue) {
+ _value = newValue;
+ notifyListeners();
+ }
+
+ @override
+ Future dispose() async {
+ await _volumeKeysSubscription.cancel();
+ super.dispose();
+ }
+}
diff --git a/lib/screens/metering/event_metering.dart b/lib/screens/metering/event_metering.dart
index e12ba35..852b5e4 100644
--- a/lib/screens/metering/event_metering.dart
+++ b/lib/screens/metering/event_metering.dart
@@ -45,3 +45,11 @@ class MeasureErrorEvent extends MeteringEvent {
const MeasureErrorEvent({required this.isMetering});
}
+
+class SettingsOpenedEvent extends MeteringEvent {
+ const SettingsOpenedEvent();
+}
+
+class SettingsClosedEvent extends MeteringEvent {
+ const SettingsClosedEvent();
+}
diff --git a/lib/screens/metering/flow_metering.dart b/lib/screens/metering/flow_metering.dart
index ac6cb0d..780f537 100644
--- a/lib/screens/metering/flow_metering.dart
+++ b/lib/screens/metering/flow_metering.dart
@@ -5,9 +5,11 @@ import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
+import 'package:lightmeter/data/volume_events_service.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/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
import 'package:lightmeter/screens/metering/screen_metering.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
@@ -28,18 +30,23 @@ class _MeteringFlowState extends State {
context.get(),
context.get(),
context.get(),
+ context.get(),
),
- child: MultiBlocProvider(
- providers: [
- BlocProvider(create: (_) => MeteringCommunicationBloc()),
- BlocProvider(
- create: (context) => MeteringBloc(
- context.get(),
- context.read(),
+ child: InheritedWidgetBase(
+ data: VolumeKeysNotifier(context.get()),
+ child: MultiBlocProvider(
+ providers: [
+ BlocProvider(create: (_) => MeteringCommunicationBloc()),
+ BlocProvider(
+ create: (context) => MeteringBloc(
+ context.get(),
+ context.get(),
+ context.read(),
+ ),
),
- ),
- ],
- child: const MeteringScreen(),
+ ],
+ child: const MeteringScreen(),
+ ),
),
);
}
diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart
index 134d789..4fb1e85 100644
--- a/lib/screens/metering/screen_metering.dart
+++ b/lib/screens/metering/screen_metering.dart
@@ -50,7 +50,12 @@ class MeteringScreen extends StatelessWidget {
? EvSourceTypeProvider.of(context).toggleType
: null,
onMeasure: () => context.read().add(const MeasureEvent()),
- onSettings: () => Navigator.pushNamed(context, 'settings'),
+ onSettings: () {
+ context.read().add(const SettingsOpenedEvent());
+ Navigator.pushNamed(context, 'settings').then((value) {
+ context.read().add(const SettingsClosedEvent());
+ });
+ },
),
),
],
diff --git a/lib/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart b/lib/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart
index 7de7450..ee0483d 100644
--- a/lib/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart
+++ b/lib/screens/settings/components/general/components/caffeine/widget_list_tile_caffeine.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/generated/l10n.dart';
+import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/settings/components/general/components/caffeine/bloc_list_tile_caffeine.dart';
@@ -15,6 +16,7 @@ class CaffeineListTile extends StatelessWidget {
title: Text(S.of(context).keepScreenOn),
value: state,
onChanged: context.read().onCaffeineChanged,
+ contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
),
);
}
diff --git a/lib/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart b/lib/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart
index a33b1ce..ec7ec60 100644
--- a/lib/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart
+++ b/lib/screens/settings/components/general/components/haptics/widget_list_tile_haptics.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/generated/l10n.dart';
+import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/settings/components/general/components/haptics/bloc_list_tile_haptics.dart';
@@ -15,6 +16,7 @@ class HapticsListTile extends StatelessWidget {
title: Text(S.of(context).haptics),
value: state,
onChanged: context.read().onHapticsChanged,
+ contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
),
);
}
diff --git a/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart b/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart
new file mode 100644
index 0000000..a8b8e3e
--- /dev/null
+++ b/lib/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart
@@ -0,0 +1,20 @@
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:lightmeter/data/models/volume_action.dart';
+import 'package:lightmeter/interactors/settings_interactor.dart';
+
+class VolumeActionsListTileBloc extends Cubit {
+ final SettingsInteractor _settingsInteractor;
+
+ VolumeActionsListTileBloc(
+ this._settingsInteractor,
+ ) : super(_settingsInteractor.volumeAction == VolumeAction.shutter);
+
+ void onVolumeActionChanged(bool value) {
+ _settingsInteractor.setVolumeAction(value ? VolumeAction.shutter : VolumeAction.none);
+
+ // while in settings we allow system to handle volume
+ // so that volume keys action works only when necessary - on the metering screen
+ _settingsInteractor.disableVolumeHandling();
+ emit(value);
+ }
+}
diff --git a/lib/screens/settings/components/general/components/volume_actions/provider_list_tile_volume_actions.dart b/lib/screens/settings/components/general/components/volume_actions/provider_list_tile_volume_actions.dart
new file mode 100644
index 0000000..790ad4f
--- /dev/null
+++ b/lib/screens/settings/components/general/components/volume_actions/provider_list_tile_volume_actions.dart
@@ -0,0 +1,19 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:lightmeter/interactors/settings_interactor.dart';
+
+import 'package:lightmeter/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart';
+import 'package:lightmeter/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart';
+import 'package:lightmeter/utils/inherited_generics.dart';
+
+class VolumeActionsListTileProvider extends StatelessWidget {
+ const VolumeActionsListTileProvider({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocProvider(
+ create: (context) => VolumeActionsListTileBloc(context.get()),
+ child: const VolumeActionsListTile(),
+ );
+ }
+}
diff --git a/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart b/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart
new file mode 100644
index 0000000..0502b60
--- /dev/null
+++ b/lib/screens/settings/components/general/components/volume_actions/widget_list_tile_volume_actions.dart
@@ -0,0 +1,22 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:lightmeter/generated/l10n.dart';
+import 'package:lightmeter/res/dimens.dart';
+import 'package:lightmeter/screens/settings/components/general/components/volume_actions/bloc_list_tile_volume_actions.dart';
+
+class VolumeActionsListTile extends StatelessWidget {
+ const VolumeActionsListTile({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocBuilder(
+ builder: (context, state) => SwitchListTile(
+ secondary: const Icon(Icons.volume_up),
+ title: Text(S.of(context).volumeKeysAction),
+ value: state,
+ onChanged: context.read().onVolumeActionChanged,
+ contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
+ ),
+ );
+ }
+}
diff --git a/lib/screens/settings/components/general/widget_settings_section_general.dart b/lib/screens/settings/components/general/widget_settings_section_general.dart
index b873d3f..bc123d7 100644
--- a/lib/screens/settings/components/general/widget_settings_section_general.dart
+++ b/lib/screens/settings/components/general/widget_settings_section_general.dart
@@ -1,8 +1,11 @@
+import 'dart:io';
+
import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/screens/settings/components/general/components/caffeine/provider_list_tile_caffeine.dart';
import 'package:lightmeter/screens/settings/components/general/components/haptics/provider_list_tile_haptics.dart';
import 'package:lightmeter/screens/settings/components/general/components/language/widget_list_tile_language.dart';
+import 'package:lightmeter/screens/settings/components/general/components/volume_actions/provider_list_tile_volume_actions.dart';
import 'package:lightmeter/screens/settings/components/shared/settings_section/widget_settings_section.dart';
class GeneralSettingsSection extends StatelessWidget {
@@ -12,10 +15,11 @@ class GeneralSettingsSection extends StatelessWidget {
Widget build(BuildContext context) {
return SettingsSection(
title: S.of(context).general,
- children: const [
- CaffeineListTileProvider(),
- HapticsListTileProvider(),
- LanguageListTile(),
+ children: [
+ const CaffeineListTileProvider(),
+ const HapticsListTileProvider(),
+ if (Platform.isAndroid) const VolumeActionsListTileProvider(),
+ const LanguageListTile(),
],
);
}
diff --git a/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart b/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart
index f15186e..d230f63 100644
--- a/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart
+++ b/lib/screens/settings/components/theme/components/dynamic_color/widget_list_tile_dynamic_color.dart
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/theme_provider.dart';
+import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
class DynamicColorListTile extends StatelessWidget {
@@ -14,6 +15,7 @@ class DynamicColorListTile extends StatelessWidget {
title: Text(S.of(context).dynamicColor),
value: context.listen() == DynamicColorState.enabled,
onChanged: ThemeProvider.of(context).enableDynamicColor,
+ contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
);
}
}
diff --git a/lib/screens/settings/flow_settings.dart b/lib/screens/settings/flow_settings.dart
index 5b9d5b3..3195c25 100644
--- a/lib/screens/settings/flow_settings.dart
+++ b/lib/screens/settings/flow_settings.dart
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/interactors/settings_interactor.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
@@ -16,6 +17,7 @@ class SettingsFlow extends StatelessWidget {
context.get(),
context.get(),
context.get(),
+ context.get(),
),
child: const SettingsScreen(),
);
diff --git a/lib/screens/settings/screen_settings.dart b/lib/screens/settings/screen_settings.dart
index 2adf906..3c745bd 100644
--- a/lib/screens/settings/screen_settings.dart
+++ b/lib/screens/settings/screen_settings.dart
@@ -1,14 +1,33 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.dart';
+import 'package:lightmeter/interactors/settings_interactor.dart';
import 'package:lightmeter/screens/settings/components/about/widget_settings_section_about.dart';
import 'package:lightmeter/screens/settings/components/general/widget_settings_section_general.dart';
import 'package:lightmeter/screens/settings/components/metering/widget_settings_section_metering.dart';
import 'package:lightmeter/screens/settings/components/theme/widget_settings_section_theme.dart';
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
+import 'package:lightmeter/utils/inherited_generics.dart';
-class SettingsScreen extends StatelessWidget {
+class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key});
+ @override
+ State createState() => _SettingsScreenState();
+}
+
+class _SettingsScreenState extends State {
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ context.get().disableVolumeHandling();
+ }
+
+ @override
+ void deactivate() {
+ context.get().restoreVolumeHandling();
+ super.deactivate();
+ }
+
@override
Widget build(BuildContext context) {
return ScaffoldMessenger(
diff --git a/pubspec.yaml b/pubspec.yaml
index 8a230c8..222ac3c 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,7 @@
name: lightmeter
description: A new Flutter project.
publish_to: "none"
-version: 0.11.8+30
+version: 0.12.0+31
environment:
sdk: ">=3.0.0 <4.0.0"
@@ -30,6 +30,7 @@ dependencies:
material_color_utilities: 0.2.0
package_info_plus: 4.0.1
permission_handler: 10.2.0
+ platform: 3.1.0
shared_preferences: 2.1.1
url_launcher: 6.1.11
uuid: 3.0.7
diff --git a/resources/social_preview.png b/resources/social_preview.png
new file mode 100644
index 0000000..90dc77b
Binary files /dev/null and b/resources/social_preview.png differ
diff --git a/test/data/light_sensor_service_test.dart b/test/data/light_sensor_service_test.dart
index 1256e18..d29b50f 100644
--- a/test/data/light_sensor_service_test.dart
+++ b/test/data/light_sensor_service_test.dart
@@ -1,10 +1,15 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
+import 'package:mocktail/mocktail.dart';
+import 'package:platform/platform.dart';
+
+class _MockLocalPlatform extends Mock implements LocalPlatform {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
+ late _MockLocalPlatform localPlatform;
late LightSensorService service;
const methodChannel = MethodChannel('system_feature');
@@ -12,7 +17,8 @@ void main() {
//const eventChannel = EventChannel('light.eventChannel');
setUp(() {
- service = const LightSensorService();
+ localPlatform = _MockLocalPlatform();
+ service = LightSensorService(localPlatform);
});
tearDown(() {
@@ -23,7 +29,8 @@ void main() {
group(
'hasSensor()',
() {
- test('true', () async {
+ test('true - Android', () async {
+ when(() => localPlatform.isAndroid).thenReturn(true);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
@@ -38,7 +45,8 @@ void main() {
expectLater(service.hasSensor(), completion(true));
});
- test('false', () async {
+ test('false - Android', () async {
+ when(() => localPlatform.isAndroid).thenReturn(true);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
@@ -52,7 +60,9 @@ void main() {
});
expectLater(service.hasSensor(), completion(false));
});
- test('null', () async {
+
+ test('null - Android', () async {
+ when(() => localPlatform.isAndroid).thenReturn(true);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
@@ -66,6 +76,23 @@ void main() {
});
expectLater(service.hasSensor(), completion(false));
});
+
+ test('false - iOS', () async {
+ when(() => localPlatform.isAndroid).thenReturn(false);
+ expectLater(service.hasSensor(), completion(false));
+ });
},
);
+
+ group('luxStream', () {
+ // test('Android', () async {
+ // when(() => localPlatform.isAndroid).thenReturn(true);
+ // expect(service.luxStream(), const Stream.empty());
+ // });
+
+ test('iOS', () async {
+ when(() => localPlatform.isAndroid).thenReturn(false);
+ expect(service.luxStream(), const Stream.empty());
+ });
+ });
}
diff --git a/test/data/volume_events_service_test.dart b/test/data/volume_events_service_test.dart
new file mode 100644
index 0000000..f9ef3d6
--- /dev/null
+++ b/test/data/volume_events_service_test.dart
@@ -0,0 +1,73 @@
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:lightmeter/data/volume_events_service.dart';
+import 'package:mocktail/mocktail.dart';
+import 'package:platform/platform.dart';
+
+class _MockLocalPlatform extends Mock implements LocalPlatform {}
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ late _MockLocalPlatform localPlatform;
+ late VolumeEventsService service;
+
+ Future? methodCallSuccessHandler(MethodCall methodCall) async {
+ switch (methodCall.method) {
+ case "setVolumeHandling":
+ return methodCall.arguments as bool;
+ default:
+ throw UnimplementedError();
+ }
+ }
+
+ setUp(() {
+ localPlatform = _MockLocalPlatform();
+ service = VolumeEventsService(localPlatform);
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
+ VolumeEventsService.volumeHandlingChannel,
+ methodCallSuccessHandler,
+ );
+ });
+
+ tearDown(() {
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
+ VolumeEventsService.volumeHandlingChannel,
+ null,
+ );
+ });
+
+ group('setVolumeHandling', () {
+ test('true - Android', () async {
+ when(() => localPlatform.isAndroid).thenReturn(true);
+ expectLater(service.setVolumeHandling(true), completion(true));
+ });
+
+ test('true - iOS', () async {
+ when(() => localPlatform.isAndroid).thenReturn(false);
+ expectLater(service.setVolumeHandling(true), completion(false));
+ });
+
+ test('false - Android', () async {
+ when(() => localPlatform.isAndroid).thenReturn(true);
+ expectLater(service.setVolumeHandling(false), completion(false));
+ });
+
+ test('false - iOS', () async {
+ when(() => localPlatform.isAndroid).thenReturn(false);
+ expectLater(service.setVolumeHandling(false), completion(false));
+ });
+ });
+
+ group('volumeButtonsEventStream', () {
+ // test('Android', () async {
+ // when(() => localPlatform.isAndroid).thenReturn(true);
+ // expect(service.volumeButtonsEventStream(), const Stream.empty());
+ // });
+
+ test('iOS', () async {
+ when(() => localPlatform.isAndroid).thenReturn(false);
+ expect(service.volumeButtonsEventStream(), const Stream.empty());
+ });
+ });
+}
diff --git a/test/screens/metering/bloc_metering_test.dart b/test/screens/metering/bloc_metering_test.dart
index 7e87a27..3593c91 100644
--- a/test/screens/metering/bloc_metering_test.dart
+++ b/test/screens/metering/bloc_metering_test.dart
@@ -1,5 +1,6 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:lightmeter/data/models/film.dart';
+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';
@@ -7,20 +8,24 @@ import 'package:lightmeter/screens/metering/communication/event_communication_me
as communication_events;
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart'
as communication_states;
+import 'package:lightmeter/screens/metering/components/shared/volume_keys_notifier/notifier_volume_keys.dart';
import 'package:lightmeter/screens/metering/event_metering.dart';
import 'package:lightmeter/screens/metering/state_metering.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
+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 _MockMeteringInteractor extends Mock implements MeteringInteractor {}
-
void main() {
late _MockMeteringInteractor meteringInteractor;
+ late _MockVolumeKeysNotifier volumeKeysNotifier;
late _MockMeteringCommunicationBloc communicationBloc;
late MeteringBloc bloc;
const iso100 = IsoValue(100, StopType.full);
@@ -34,16 +39,19 @@ void main() {
when(meteringInteractor.responseVibration).thenAnswer((_) async {});
when(meteringInteractor.errorVibration).thenAnswer((_) async {});
+ volumeKeysNotifier = _MockVolumeKeysNotifier();
communicationBloc = _MockMeteringCommunicationBloc();
-
+
bloc = MeteringBloc(
meteringInteractor,
+ volumeKeysNotifier,
communicationBloc,
);
});
tearDown(() {
bloc.close();
+ //volumeKeysNotifier.dispose();
communicationBloc.close();
});
@@ -606,4 +614,66 @@ void main() {
);
},
);
+
+ group(
+ '`Volume keys shutter action`',
+ () {
+ blocTest(
+ 'Add/remove listener',
+ build: () => bloc,
+ verify: (_) {
+ verify(() => volumeKeysNotifier.addListener(bloc.onVolumeKey)).called(1);
+ verify(() => volumeKeysNotifier.removeListener(bloc.onVolumeKey)).called(1);
+ },
+ expect: () => [],
+ );
+
+ blocTest(
+ 'onVolumeKey & VolumeAction.shutter',
+ build: () => bloc,
+ act: (bloc) async {
+ bloc.onVolumeKey();
+ },
+ setUp: () {
+ when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.shutter);
+ },
+ verify: (_) {},
+ expect: () => [isA()],
+ );
+
+ blocTest(
+ 'onVolumeKey & VolumeAction.none',
+ build: () => bloc,
+ act: (bloc) async {
+ bloc.onVolumeKey();
+ },
+ setUp: () {
+ when(() => meteringInteractor.volumeAction).thenReturn(VolumeAction.none);
+ },
+ verify: (_) {},
+ expect: () => [],
+ );
+ },
+ );
+
+ group(
+ '`SettingOpenedEvent`/`SettingsClosedEvent`',
+ () {
+ blocTest(
+ 'Settings opened & closed',
+ build: () => bloc,
+ act: (bloc) async {
+ bloc.add(const SettingsOpenedEvent());
+ bloc.add(const SettingsClosedEvent());
+ },
+ verify: (_) {
+ verify(() => communicationBloc.add(const communication_events.SettingsOpenedEvent()))
+ .called(1);
+ verify(() => communicationBloc.add(const communication_events.SettingsClosedEvent()))
+ .called(1);
+ },
+ expect: () => [],
+ );
+ },
+ );
}
diff --git a/test/screens/metering/communication/bloc_communication_metering_test.dart b/test/screens/metering/communication/bloc_communication_metering_test.dart
index 604de75..a04aab7 100644
--- a/test/screens/metering/communication/bloc_communication_metering_test.dart
+++ b/test/screens/metering/communication/bloc_communication_metering_test.dart
@@ -98,4 +98,30 @@ void main() {
);
},
);
+
+ group(
+ '`SettingsOpenedEvent`/`SettingsClosedEvent`',
+ () {
+ blocTest(
+ '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());
+ },
+ expect: () => [
+ isA(),
+ isA(),
+ isA(),
+ isA(),
+ ],
+ );
+ },
+ );
}
diff --git a/test/screens/metering/components/camera/bloc_container_camera_test.dart b/test/screens/metering/components/camera/bloc_container_camera_test.dart
index e720ef5..fa08edf 100644
--- a/test/screens/metering/components/camera/bloc_container_camera_test.dart
+++ b/test/screens/metering/components/camera/bloc_container_camera_test.dart
@@ -14,12 +14,12 @@ import 'package:lightmeter/screens/metering/components/camera_container/models/c
import 'package:lightmeter/screens/metering/components/camera_container/state_container_camera.dart';
import 'package:mocktail/mocktail.dart';
+class _MockMeteringInteractor extends Mock implements MeteringInteractor {}
+
class _MockMeteringCommunicationBloc extends MockBloc<
communication_events.MeteringCommunicationEvent,
communication_states.MeteringCommunicationState> implements MeteringCommunicationBloc {}
-class _MockMeteringInteractor extends Mock implements MeteringInteractor {}
-
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
@@ -310,6 +310,30 @@ void main() {
},
expect: () => [
...initializedStateSequence,
+ const CameraInitState(),
+ ...initializedStateSequence,
+ ],
+ );
+
+ blocTest(
+ 'onCommunicationState',
+ setUp: () {
+ when(() => meteringInteractor.checkCameraPermission()).thenAnswer((_) async => true);
+ },
+ build: () => bloc,
+ act: (bloc) async {
+ bloc.add(const InitializeEvent());
+ await Future.delayed(Duration.zero);
+ bloc.onCommunicationState(const communication_states.SettingsOpenedState());
+ await Future.delayed(Duration.zero);
+ bloc.onCommunicationState(const communication_states.SettingsClosedState());
+ },
+ verify: (_) {
+ verify(() => meteringInteractor.checkCameraPermission()).called(2);
+ },
+ expect: () => [
+ ...initializedStateSequence,
+ const CameraInitState(),
...initializedStateSequence,
],
);
diff --git a/test/screens/metering/components/light_sensor/bloc_container_light_sensor_test.dart b/test/screens/metering/components/light_sensor/bloc_container_light_sensor_test.dart
index f60a79e..70dd31d 100644
--- a/test/screens/metering/components/light_sensor/bloc_container_light_sensor_test.dart
+++ b/test/screens/metering/components/light_sensor/bloc_container_light_sensor_test.dart
@@ -78,4 +78,67 @@ void main() {
);
},
);
+
+ group(
+ '`communication_states.SettingsOpenedState()`',
+ () {
+ const List luxIterable = [1, 2, 2, 2, 3];
+ final List resultList = luxIterable.map((lux) => log2(lux / 2.5)).toList();
+ blocTest(
+ 'Metering is already canceled',
+ build: () => bloc,
+ setUp: () {
+ when(() => meteringInteractor.luxStream())
+ .thenAnswer((_) => Stream.fromIterable(luxIterable));
+ when(() => meteringInteractor.lightSensorEvCalibration).thenReturn(0.0);
+ },
+ act: (bloc) async {
+ bloc.onCommunicationState(const communication_states.SettingsOpenedState());
+ },
+ verify: (_) {
+ verifyNever(() => meteringInteractor.luxStream().listen((_) {}));
+ verifyNever(() => meteringInteractor.lightSensorEvCalibration);
+ verify(() {
+ communicationBloc.add(const communication_events.MeteringEndedEvent(null));
+ }).called(2); // +1 from dispose
+ },
+ expect: () => [],
+ );
+
+ blocTest(
+ 'Metering is in progress',
+ build: () => bloc,
+ setUp: () {
+ when(() => meteringInteractor.luxStream())
+ .thenAnswer((_) => Stream.fromIterable(luxIterable));
+ when(() => meteringInteractor.lightSensorEvCalibration).thenReturn(0.0);
+ },
+ act: (bloc) async {
+ bloc.onCommunicationState(const communication_states.MeasureState());
+ await Future.delayed(Duration.zero);
+ bloc.onCommunicationState(const communication_states.SettingsOpenedState());
+ bloc.onCommunicationState(const communication_states.SettingsClosedState());
+ },
+ verify: (_) {
+ verify(() => meteringInteractor.luxStream().listen((_) {})).called(1);
+ verify(() => meteringInteractor.lightSensorEvCalibration).called(5);
+ verify(() {
+ communicationBloc.add(communication_events.MeteringInProgressEvent(resultList.first));
+ }).called(1);
+ verify(() {
+ communicationBloc.add(communication_events.MeteringInProgressEvent(resultList[1]));
+ }).called(3);
+ verify(() {
+ communicationBloc.add(communication_events.MeteringInProgressEvent(resultList.last));
+ }).called(1);
+ verify(() {
+ communicationBloc.add(communication_events.MeteringEndedEvent(resultList.last));
+ }).called(3); // +1 from settings closed, +1 from dispose
+ },
+ expect: () => resultList.map(
+ (e) => isA().having((state) => state.ev100, 'ev100', e),
+ ),
+ );
+ },
+ );
}