diff --git a/.gitignore b/.gitignore index 3fd9832..703a8b6 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,5 @@ ios/firebase_app_id_file.json ios/Runner/GoogleService-Info.plist /lib/firebase_options.dart -coverage/ \ No newline at end of file +coverage/ +screenshots/ \ No newline at end of file diff --git a/assets/camera_stub_image.jpg b/assets/camera_stub_image.jpg new file mode 100644 index 0000000..70b289f Binary files /dev/null and b/assets/camera_stub_image.jpg differ diff --git a/iap/lib/src/data/models/iap_product.dart b/iap/lib/src/data/models/iap_product.dart index ba24c17..b075ff6 100644 --- a/iap/lib/src/data/models/iap_product.dart +++ b/iap/lib/src/data/models/iap_product.dart @@ -6,8 +6,26 @@ enum IAPProductStatus { enum IAPProductType { paidFeatures } -abstract class IAPProduct { - const IAPProduct._(); +class IAPProduct { + final String storeId; + final IAPProductStatus status; - IAPProductStatus get status => IAPProductStatus.purchasable; + const IAPProduct({ + required this.storeId, + this.status = IAPProductStatus.purchasable, + }); + + IAPProduct copyWith({IAPProductStatus? status}) => IAPProduct( + storeId: storeId, + status: status ?? this.status, + ); +} + +extension IAPProductTypeExtension on IAPProductType { + String get storeId { + switch (this) { + case IAPProductType.paidFeatures: + return ""; + } + } } diff --git a/iap/lib/src/providers/iap_products_provider.dart b/iap/lib/src/providers/iap_products_provider.dart index 3014cd9..4895fdf 100644 --- a/iap/lib/src/providers/iap_products_provider.dart +++ b/iap/lib/src/providers/iap_products_provider.dart @@ -18,7 +18,12 @@ class IAPProductsProviderState extends State { @override Widget build(BuildContext context) { return IAPProducts( - products: const [], + products: [ + IAPProduct( + storeId: IAPProductType.paidFeatures.storeId, + status: IAPProductStatus.purchased, + ) + ], child: widget.child, ); } @@ -35,13 +40,28 @@ class IAPProducts extends InheritedModel { super.key, }); - static IAPProduct? productOf(BuildContext context, IAPProductType type) => null; + static IAPProduct? productOf(BuildContext context, IAPProductType type) { + final IAPProducts? result = InheritedModel.inheritFrom(context, aspect: type); + return result!._findProduct(type); + } - static bool isPurchased(BuildContext context, IAPProductType type) => false; + static bool isPurchased(BuildContext context, IAPProductType type) { + final IAPProducts? result = InheritedModel.inheritFrom(context, aspect: type); + return result!._findProduct(type)?.status == IAPProductStatus.purchased; + } @override bool updateShouldNotify(IAPProducts oldWidget) => false; @override - bool updateShouldNotifyDependent(covariant IAPProducts oldWidget, Set dependencies) => false; + bool updateShouldNotifyDependent(IAPProducts oldWidget, Set dependencies) => + false; + + IAPProduct? _findProduct(IAPProductType type) { + try { + return products.firstWhere((element) => element.storeId == type.storeId); + } catch (_) { + return null; + } + } } diff --git a/integration_test/generate_screenshots.sh b/integration_test/generate_screenshots.sh new file mode 100644 index 0000000..8296e96 --- /dev/null +++ b/integration_test/generate_screenshots.sh @@ -0,0 +1,10 @@ +flutter drive \ + --dart-define="cameraPreviewAspectRatio=240/320" \ + --dart-define="cameraStubImage=assets/camera_stub_image.jpg" \ + --driver=test_driver/screenshot_driver.dart \ + --target=integration_test/generate_screenshots.dart \ + --profile \ + --flavor=dev \ + --no-dds \ + --endless-trace-buffer \ + --purge-persistent-cache diff --git a/lib/application.dart b/lib/application.dart index c76bab7..5f73ed8 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -1,97 +1,48 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.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/supported_locale.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/generated/l10n.dart'; -import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; -import 'package:platform/platform.dart'; -import 'package:shared_preferences/shared_preferences.dart'; class Application extends StatelessWidget { - final Environment env; - - const Application(this.env, {super.key}); + const Application({super.key}); @override Widget build(BuildContext context) { - return FutureBuilder( - future: Future.wait([ - SharedPreferences.getInstance(), - const LightSensorService(LocalPlatform()).hasSensor(), - ]), - builder: (_, snapshot) { - if (snapshot.data != null) { - return IAPProviders( - sharedPreferences: snapshot.data![0] as SharedPreferences, - child: ServicesProvider( - caffeineService: const CaffeineService(), - environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool), - hapticsService: const HapticsService(), - lightSensorService: const LightSensorService(LocalPlatform()), - permissionsService: const PermissionsService(), - userPreferencesService: - UserPreferencesService(snapshot.data![0] as SharedPreferences), - volumeEventsService: const VolumeEventsService(LocalPlatform()), - child: UserPreferencesProvider( - child: Builder( - builder: (context) { - final theme = UserPreferencesProvider.themeOf(context); - final systemIconsBrightness = - ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface); - return AnnotatedRegion( - value: SystemUiOverlayStyle( - statusBarColor: Colors.transparent, - statusBarBrightness: systemIconsBrightness == Brightness.light - ? Brightness.dark - : Brightness.light, - statusBarIconBrightness: systemIconsBrightness, - systemNavigationBarColor: Colors.transparent, - systemNavigationBarIconBrightness: systemIconsBrightness, - ), - child: MaterialApp( - theme: theme, - locale: Locale(UserPreferencesProvider.localeOf(context).intlName), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: S.delegate.supportedLocales, - builder: (context, child) => MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), - child: child!, - ), - initialRoute: "metering", - routes: { - "metering": (context) => const MeteringFlow(), - "settings": (context) => const SettingsFlow(), - }, - ), - ); - }, - ), - ), - ), - ); - } else if (snapshot.error != null) { - return Center(child: Text(snapshot.error!.toString())); - } - - // TODO(@vodemn): maybe user splashscreen instead - return const SizedBox(); - }, + final theme = UserPreferencesProvider.themeOf(context); + final systemIconsBrightness = ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface); + return AnnotatedRegion( + value: SystemUiOverlayStyle( + statusBarColor: Colors.transparent, + statusBarBrightness: + systemIconsBrightness == Brightness.light ? Brightness.dark : Brightness.light, + statusBarIconBrightness: systemIconsBrightness, + systemNavigationBarColor: Colors.transparent, + systemNavigationBarIconBrightness: systemIconsBrightness, + ), + child: MaterialApp( + theme: theme, + locale: Locale(UserPreferencesProvider.localeOf(context).intlName), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, + builder: (context, child) => MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), + child: child!, + ), + initialRoute: "metering", + routes: { + "metering": (context) => const MeteringFlow(), + "settings": (context) => const SettingsFlow(), + }, + ), ); } } diff --git a/lib/application_wrapper.dart b/lib/application_wrapper.dart new file mode 100644 index 0000000..f8627f9 --- /dev/null +++ b/lib/application_wrapper.dart @@ -0,0 +1,55 @@ +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/services_provider.dart'; +import 'package:lightmeter/providers/user_preferences_provider.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; +import 'package:platform/platform.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class ApplicationWrapper extends StatelessWidget { + final Environment env; + final Widget child; + + const ApplicationWrapper(this.env, {required this.child, super.key}); + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: Future.wait([ + SharedPreferences.getInstance(), + const LightSensorService(LocalPlatform()).hasSensor(), + ]), + builder: (_, snapshot) { + if (snapshot.data != null) { + return IAPProviders( + sharedPreferences: snapshot.data![0] as SharedPreferences, + child: ServicesProvider( + caffeineService: const CaffeineService(), + environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool), + hapticsService: const HapticsService(), + lightSensorService: const LightSensorService(LocalPlatform()), + permissionsService: const PermissionsService(), + userPreferencesService: + UserPreferencesService(snapshot.data![0] as SharedPreferences), + volumeEventsService: const VolumeEventsService(LocalPlatform()), + child: UserPreferencesProvider( + child: child, + ), + ), + ); + } else if (snapshot.error != null) { + return Center(child: Text(snapshot.error!.toString())); + } + + // TODO(@vodemn): maybe user splashscreen instead + return const SizedBox(); + }, + ); + } +} diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index 3aab33e..0701781 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -43,7 +43,7 @@ "film": "胶片", "filmPush": "胶片 (push)", "filmPull": "胶片 (pull)", - "filmReciprocityHint": "Applies correction for shutter speeds grater than 1 second", + "filmReciprocityHint": "对快门速度超过 1 秒的情况进行修正", "equipmentProfileName": "设备配置名称", "equipmentProfileNameHint": "Praktica MTL5B", "equipmentProfileAllValues": "全部", @@ -54,12 +54,12 @@ "shutterSpeedValues": "快门速度", "shutterSpeedValuesFilterDescription": "选择要显示的快门速度范围。这通常由您使用的相机机身决定。", "isoValues": "ISO", - "isoValuesFilterDescription": "选择要显示的 ISO。这些值可能是您最常用的值,也可能是相机支持的值。", + "isoValuesFilterDescription": "选择要显示的 ISO 。这些值可能是您最常用的值,也可能是相机支持的值。", "equipmentProfile": "设备配置", "equipmentProfiles": "设备配置", "tapToAdd": "點擊添加", - "filmsInUse": "Films in use", - "filmsInUseDescription": "Select films which you use.", + "filmsInUse": "使用的胶片", + "filmsInUseDescription": "选择你使用的胶片", "general": "通用", "keepScreenOn": "保持屏幕常亮", "haptics": "震动", @@ -92,20 +92,20 @@ } } }, - "buyLightmeterPro": "Buy Lightmeter Pro", + "buyLightmeterPro": "购买 Lightmeter Pro", "lightmeterPro": "Lightmeter Pro", - "lightmeterProDescription": "Unlocks extra features, such as equipment profiles containing filters for aperture, shutter speed, and more; and a list of films with compensation for what's known as reciprocity failure.\n\nThe source code of Lightmeter is available on GitHub. You are welcome to compile it yourself. However, if you want to support the development and receive new features and updates, consider purchasing Lightmeter Pro.", - "buy": "Buy", - "tooltipAdd": "Add", - "tooltipClose": "Close", - "tooltipExpand": "Expand", - "tooltipCollapse": "Collapse", - "tooltipCopy": "Copy", - "tooltipDelete": "Delete", - "tooltipSelectAll": "Select all", - "tooltipDesecelectAll": "Deselect all", - "resetToZero": "Reset to zero", - "tooltipUseLightSensor": "Use lightsensor", - "tooltipUseCamera": "Use camera", - "tooltipOpenSettings": "Open settings" -} \ No newline at end of file + "lightmeterProDescription": "购买以解锁额外功能。例如包含光圈、快门速度等参数的配置文件;以及一个胶卷预设列表来提供倒易率失效时的曝光补偿。\n\n您可以在 GitHub 上获取 Lightmeter 的源代码,欢迎自行编译。不过,如果您想支持开发并获得新功能和更新,请考虑购买 Lightmeter Pro。", + "buy": "购买", + "tooltipAdd": "添加", + "tooltipClose": "关闭", + "tooltipExpand": "展开", + "tooltipCollapse": "崩溃", + "tooltipCopy": "复制", + "tooltipDelete": "删除", + "tooltipSelectAll": "全选", + "tooltipDesecelectAll": "取消全选", + "resetToZero": "重置为零", + "tooltipUseLightSensor": "使用光线传感器", + "tooltipUseCamera": "使用摄像头", + "tooltipOpenSettings": "打开设置" +} diff --git a/lib/main_dev.dart b/lib/main_dev.dart index 52d99bc..f25997e 100644 --- a/lib/main_dev.dart +++ b/lib/main_dev.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:lightmeter/application.dart'; +import 'package:lightmeter/application_wrapper.dart'; import 'package:lightmeter/environment.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - //debugRepaintRainbowEnabled = true; - runApp(const Application(Environment.dev())); + runApp(const ApplicationWrapper(Environment.dev(), child: Application())); } diff --git a/lib/main_prod.dart b/lib/main_prod.dart index 2ccc397..b75513e 100644 --- a/lib/main_prod.dart +++ b/lib/main_prod.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/application.dart'; +import 'package:lightmeter/application_wrapper.dart'; import 'package:lightmeter/environment.dart'; import 'package:lightmeter/firebase.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await initializeFirebase(handleErrors: true); - runApp(const Application(Environment.prod())); + runApp(const ApplicationWrapper(Environment.prod(), child: Application())); } diff --git a/lib/main_release.dart b/lib/main_release.dart index b87dff8..bb6384a 100644 --- a/lib/main_release.dart +++ b/lib/main_release.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/application.dart'; +import 'package:lightmeter/application_wrapper.dart'; import 'package:lightmeter/environment.dart'; import 'package:lightmeter/firebase.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await initializeFirebase(handleErrors: false); - runApp(const Application(Environment.prod())); + runApp(const ApplicationWrapper(Environment.prod(), child: Application())); } diff --git a/lib/platform_config.dart b/lib/platform_config.dart index 7d98a4b..def5a80 100644 --- a/lib/platform_config.dart +++ b/lib/platform_config.dart @@ -5,4 +5,6 @@ class PlatformConfig { final rational = const String.fromEnvironment('cameraPreviewAspectRatio').split('/'); return int.parse(rational[0]) / int.parse(rational[1]); } + + static String get cameraStubImage => const String.fromEnvironment('cameraStubImage'); } 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 0313391..1d7d4b5 100644 --- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart +++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart @@ -2,13 +2,14 @@ import 'dart:async'; import 'dart:developer'; import 'dart:io'; import 'dart:math' as math; -import 'dart:typed_data'; import 'package:camera/camera.dart'; import 'package:exif/exif.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/interactors/metering_interactor.dart'; +import 'package:lightmeter/platform_config.dart'; import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart'; import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_event; @@ -32,7 +33,7 @@ class CameraContainerBloc extends EvSourceBlocBase !(_cameraController == null || - !_cameraController!.value.isInitialized || - _cameraController!.value.isTakingPicture); + bool get _canTakePhoto => + PlatformConfig.cameraStubImage.isNotEmpty || + !(_cameraController == null || + !_cameraController!.value.isInitialized || + _cameraController!.value.isTakingPicture); Future _takePhoto() async { try { // https://github.com/flutter/flutter/issues/84957#issuecomment-1661155095 - await _cameraController!.setFocusMode(FocusMode.locked); - await _cameraController!.setExposureMode(ExposureMode.locked); - final file = await _cameraController!.takePicture(); - await _cameraController!.setFocusMode(FocusMode.auto); - await _cameraController!.setExposureMode(ExposureMode.auto); - final Uint8List bytes = await file.readAsBytes(); - Directory(file.path).deleteSync(recursive: true); + late final Uint8List bytes; + if (PlatformConfig.cameraStubImage.isNotEmpty) { + bytes = (await rootBundle.load(PlatformConfig.cameraStubImage)).buffer.asUint8List(); + } else { + await _cameraController!.setFocusMode(FocusMode.locked); + await _cameraController!.setExposureMode(ExposureMode.locked); + final file = await _cameraController!.takePicture(); + await _cameraController!.setFocusMode(FocusMode.auto); + await _cameraController!.setExposureMode(ExposureMode.auto); + bytes = await file.readAsBytes(); + Directory(file.path).deleteSync(recursive: true); + } final tags = await readExifFromBytes(bytes); final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}"); diff --git a/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart b/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart index 1ae0ca9..3e9538f 100644 --- a/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart +++ b/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart @@ -69,6 +69,9 @@ class _CameraPreviewBuilderState extends State<_CameraPreviewBuilder> { @override Widget build(BuildContext context) { + if (PlatformConfig.cameraStubImage.isNotEmpty) { + return Image.asset(PlatformConfig.cameraStubImage); + } return ValueListenableBuilder( valueListenable: _initializedNotifier, builder: (context, value, child) => value diff --git a/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart b/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart index af2b35d..76cd729 100644 --- a/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart +++ b/lib/screens/settings/components/shared/dialog_filter/widget_dialog_filter.dart @@ -34,6 +34,26 @@ class _DialogFilterState extends State> { bool get _hasAnySelected => checkboxValues.contains(true); bool get _hasAnyUnselected => checkboxValues.contains(false); + late final ScrollController _scrollController; + + @override + void initState() { + super.initState(); + int i = 0; + for (; i < checkboxValues.length; i++) { + if (checkboxValues[i]) { + break; + } + } + _scrollController = ScrollController(initialScrollOffset: Dimens.grid56 * i); + } + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return AlertDialog( @@ -50,6 +70,7 @@ class _DialogFilterState extends State> { const Divider(), Expanded( child: SingleChildScrollView( + controller: _scrollController, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.min, diff --git a/pubspec.yaml b/pubspec.yaml index 6a81741..bd8e81e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,8 @@ dev_dependencies: flutter: uses-material-design: true + assets: + - assets/camera_stub_image.jpg flutter_intl: enabled: true