diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index e2bfc17e11f..0090344ebda 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -1315,14 +1315,5 @@ "add_photo_button_label": "Add photo", "@add_photo_button_label": { "description": "Label for the add photo button" - }, - "camera_paused_dialog_title": "Camera paused", - "camera_paused_dialog_content": "To save energy, the scanner has been automatically turned off after {min} min of inactivity", - "@camera_paused_dialog_content": { - "placeholders": { - "min": {} - } - }, - "camera_paused_dialog_positive_label": "Restart camera", - "camera_paused_dialog_negative_label": "Stay paused" -} + } +} \ No newline at end of file diff --git a/packages/smooth_app/lib/pages/scan/camera_controller.dart b/packages/smooth_app/lib/pages/scan/camera_controller.dart index e971dddc401..dafdecd4d35 100644 --- a/packages/smooth_app/lib/pages/scan/camera_controller.dart +++ b/packages/smooth_app/lib/pages/scan/camera_controller.dart @@ -103,7 +103,6 @@ class SmoothCameraController extends CameraController { } _isPaused = true; - notifyListeners(); } } @@ -125,7 +124,6 @@ class SmoothCameraController extends CameraController { await _resumeFlash(); await refocus(); _isPaused = false; - notifyListeners(); } Future _resumeFlash() async { diff --git a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart index 56bef10f20c..f2328562c8b 100644 --- a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:math' as math; -import 'dart:ui'; import 'package:audioplayers/audioplayers.dart'; import 'package:camera/camera.dart'; @@ -8,13 +7,11 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:matomo_tracker/matomo_tracker.dart'; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; import 'package:smooth_app/data_models/continuous_scan_model.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; -import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; import 'package:smooth_app/helpers/camera_helper.dart'; import 'package:smooth_app/helpers/collections_helper.dart'; import 'package:smooth_app/pages/page_manager.dart'; @@ -55,9 +52,6 @@ class MLKitScannerPageState extends LifecycleAwareState /// Minimal processing windows between two decodings static const int _processingTimeWindows = 5; - /// Period after which the camera will be paused - static const Duration _inactivityPeriod = Duration(minutes: 1); - /// A time window is the average time decodings took final AverageList _averageProcessingTime = AverageList(); final AudioCache _musicPlayer = AudioCache(prefix: 'assets/audio/'); @@ -90,8 +84,6 @@ class MLKitScannerPageState extends LifecycleAwareState /// The next time this tab is visible, we will force relaunching the camera. bool pendingResume = false; - Timer? _inactivityTimeout; - @override void initState() { super.initState(); @@ -153,17 +145,13 @@ class MLKitScannerPageState extends LifecycleAwareState return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { _computePreviewScale(constraints); - final double blur = (_controller?.isPaused == true) ? 5.0 : 0.0; return Transform.scale( scale: _previewScale, child: Center( key: ValueKey(stoppingCamera), - child: ImageFiltered( - imageFilter: ImageFilter.blur(sigmaY: blur, sigmaX: blur), - child: CameraPreview( - _controller!, - ), + child: CameraPreview( + _controller!, ), ), ); @@ -302,8 +290,6 @@ class MLKitScannerPageState extends LifecycleAwareState } Future _onNewBarcodeDetected(List barcodes) async { - bool barcodeAdded = false; - for (final String barcode in barcodes) { if (await _model.onScan(barcode)) { // Both are Future methods, but it doesn't matter to wait here @@ -317,13 +303,8 @@ class MLKitScannerPageState extends LifecycleAwareState ); } _userPreferences.setFirstScanAchieved(); - barcodeAdded = true; } } - - if (barcodeAdded) { - _startTimerForInactivity(); - } } void _cameraListener() { @@ -338,8 +319,6 @@ class MLKitScannerPageState extends LifecycleAwareState // TODO(M123): Handle errors better debugPrint(_controller!.value.errorDescription); } - } else if (_controller?.isPaused != true) { - _startTimerForInactivity(); } } @@ -352,7 +331,6 @@ class MLKitScannerPageState extends LifecycleAwareState _controller!.isPauseResumePreviewSupported != true) { await _stopImageStream(autoRestart: false); } else { - _stopTimerForInactivity(); _streamSubscription?.pause(); await _controller?.pausePreview(); } @@ -391,7 +369,6 @@ class MLKitScannerPageState extends LifecycleAwareState if (_controller?.isPauseResumePreviewSupported == true) { await _controller?.resumePreviewIfNecessary(); - _startTimerForInactivity(); } stoppingCamera = false; } @@ -403,13 +380,10 @@ class MLKitScannerPageState extends LifecycleAwareState stoppingCamera = true; - _stopTimerForInactivity(); if (_controller?.isPauseResumePreviewSupported == true) { await _controller?.pausePreview(); } - await _controller?.pausePreview(); - _redrawScreen(); _controller?.removeListener(_cameraListener); @@ -506,43 +480,6 @@ class MLKitScannerPageState extends LifecycleAwareState SmoothCameraController? get _controller => CameraHelper.controller; - /// Starts (or restarts) the timer for inactivity - void _startTimerForInactivity() { - _stopTimerForInactivity(); - - _inactivityTimeout = Timer(_inactivityPeriod, () async { - await CameraHelper.controller?.pausePreview(); - _stopTimerForInactivity(); - - showDialog( - context: context, - builder: (BuildContext context) { - final AppLocalizations localizations = AppLocalizations.of(context); - - return SmoothAlertDialog( - title: localizations.camera_paused_dialog_title, - body: Text(localizations - .camera_paused_dialog_content(_inactivityPeriod.inMinutes)), - positiveAction: SmoothActionButton( - text: localizations.camera_paused_dialog_positive_label, - onPressed: () async { - Navigator.of(context).pop(); - CameraHelper.controller?.resumePreviewIfNecessary(); - }), - negativeAction: SmoothActionButton( - text: localizations.camera_paused_dialog_negative_label, - onPressed: () { - Navigator.of(context).pop(); - }), - ); - }); - }); - } - - void _stopTimerForInactivity() { - _inactivityTimeout?.cancel(); - } - @override String get traceTitle => 'ml_kit_scan_page'; } diff --git a/packages/smooth_app/lib/pages/scan/scan_visor.dart b/packages/smooth_app/lib/pages/scan/scan_visor.dart index 51f784019f3..2d302636cd7 100644 --- a/packages/smooth_app/lib/pages/scan/scan_visor.dart +++ b/packages/smooth_app/lib/pages/scan/scan_visor.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:provider/provider.dart'; -import 'package:smooth_app/helpers/camera_helper.dart'; import 'package:smooth_app/pages/scan/scan_flash_toggle.dart'; /// This Widget is a [StatefulWidget], as it uses a [GlobalKey] to allow an @@ -20,42 +19,21 @@ class ScannerVisorWidget extends StatefulWidget { } class ScannerVisorWidgetState extends State { - @override - void initState() { - super.initState(); - - if (mounted) { - CameraHelper.controller?.addListener(onCameraChanged); - } - } - @override Widget build(BuildContext context) { - final bool isPaused = CameraHelper.controller?.isPaused ?? false; - return Stack( key: Provider.of>(context), children: [ - GestureDetector( - onTap: isPaused - ? () { - CameraHelper.controller?.resumePreviewIfNecessary(); - } - : null, + SizedBox.fromSize( + size: ScannerVisorWidget.getSize(context), child: CustomPaint( painter: ScanVisorPainter(), child: Center( - child: isPaused - ? const Icon( - Icons.pause_circle_outline, - color: Colors.white, - size: 40.0, - ) - : SvgPicture.asset( - 'assets/icons/visor_icon.svg', - width: 35.0, - height: 32.0, - ), + child: SvgPicture.asset( + 'assets/icons/visor_icon.svg', + width: 35.0, + height: 32.0, + ), ), ), ), @@ -63,24 +41,11 @@ class ScannerVisorWidgetState extends State { textDirection: Directionality.of(context), end: 0.0, bottom: 0.0, - child: Offstage( - offstage: isPaused, - child: const ScannerFlashToggleWidget(), - ), + child: const ScannerFlashToggleWidget(), ) ], ); } - - void onCameraChanged() { - setState(() {}); - } - - @override - void dispose() { - CameraHelper.controller?.removeListener(onCameraChanged); - super.dispose(); - } } class ScanVisorPainter extends CustomPainter {