π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Revert "Replace QR overlay with auto-popup detection"
Amrithesh Kakkoth Ente80067f88f8e1
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex 488f265f2b..51a63fe0bf 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -15,6 +15,7 @@ import "package:photos/generated/l10n.dart";import "package:photos/models/file/extensions/file_props.dart";import 'package:photos/models/file/file.dart';import "package:photos/models/file/file_type.dart";+import "package:photos/models/file/trash_file.dart";import "package:photos/service_locator.dart";import "package:photos/services/collections_service.dart";import "package:photos/services/local_authentication_service.dart";@@ -27,7 +28,6 @@ import "package:photos/ui/viewer/file/file_app_bar.dart";import "package:photos/ui/viewer/file/file_bottom_bar.dart";import 'package:photos/ui/viewer/file/file_widget.dart';import "package:photos/ui/viewer/file/panorama_viewer_screen.dart";-import "package:photos/ui/viewer/file/qr_code_content_sheet.dart";import "package:photos/ui/viewer/file/qr_code_detection_helper.dart";import "package:photos/ui/viewer/file/qr_code_highlight_overlay.dart";import "package:photos/ui/viewer/file/text_detection_overlay_button.dart";@@ -133,7 +133,6 @@ class _BodyState extends State<_Body> {bool swipeLocked = false;late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;QrCodeDetectionHelper? _qrHelper;- bool _qrSheetOpen = false;@overridevoid initState() {@@ -151,7 +150,6 @@ class _BodyState extends State<_Body> {});if (flagService.qrFeatureEnabled) {_qrHelper = QrCodeDetectionHelper();- _qrHelper!.qrContentNotifier.addListener(_onQrContentChanged);}// Update shared collection state after first frame@@ -163,25 +161,8 @@ class _BodyState extends State<_Body> {});}- void _onQrContentChanged() {- if (!mounted || _qrSheetOpen) return;- final content = _qrHelper?.qrContentNotifier.value;- if (content == null) return;- _qrSheetOpen = true;- WidgetsBinding.instance.addPostFrameCallback((_) {- if (!mounted) {- _qrSheetOpen = false;- return;- }- showQrContentSheet(context, content: content).whenComplete(() {- _qrSheetOpen = false;- });- });- }-@overridevoid dispose() {- _qrHelper?.qrContentNotifier.removeListener(_onQrContentChanged);_guestViewEventSubscription.cancel();_pageController.dispose();_selectedIndexNotifier.dispose();@@ -283,7 +264,29 @@ class _BodyState extends State<_Body> {);},),- if (_qrHelper != null) const QrCodeDetectionOverlay(),+ if (_qrHelper != null)+ ValueListenableBuilder(+ valueListenable: _selectedIndexNotifier,+ builder: (BuildContext context, int selectedIndex, _) {+ if (widget.config.mode == DetailPageMode.minimalistic ||+ isGuestView ||+ _files![selectedIndex] is TrashFile) {+ return const SizedBox.shrink();+ }+ return ValueListenableBuilder(+ valueListenable: _qrHelper!.qrDetectionsNotifier,+ builder: (context, detections, _) {+ return QrCodeHighlightOverlay(+ detections: detections,+ file: _files![selectedIndex],+ enableFullScreenNotifier:+ InheritedDetailPageState.of(context)+ .enableFullScreenNotifier,+ );+ },+ );+ },+ ),ValueListenableBuilder(valueListenable: _selectedIndexNotifier,builder: (BuildContext context, int selectedIndex, _) {diff --git a/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart b/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dartindex 3fefe538f1..3c7850648e 100644--- a/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/qr_code_content_sheet.dart@@ -29,17 +29,6 @@ Future<void> showQrCodeContentSheet();}-Future<void> showQrContentSheet(- BuildContext context, {- required String content,-}) {- return showBaseBottomSheet(- context,- title: AppLocalizations.of(context).qrCode,- child: _QrContentEntry(content: content),- );-}-class _QrContentEntry extends StatelessWidget {final String content;diff --git a/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart b/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dartindex 4adea8b521..c8b6232184 100644--- a/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart@@ -9,14 +9,14 @@ import "package:photos/models/file/file_type.dart";import "package:photos/utils/file_util.dart";class QrCodeDetectionHelper {- static final Map<String, String?> _cache = {};- static const _debounceDuration = Duration(milliseconds: 1500);+ static final Map<String, _DetectionResult> _cache = {};+ static const _debounceDuration = Duration(milliseconds: 500);final Logger _logger = Logger("QrCodeDetectionHelper");final EnteQr _enteQr = EnteQr();- /// null = no QR found, non-null = QR content string- final ValueNotifier<String?> qrContentNotifier = ValueNotifier<String?>(null);+ final ValueNotifier<List<QrDetection>> qrDetectionsNotifier =+ ValueNotifier<List<QrDetection>>(const []);int _requestId = 0;bool _disposed = false;@@ -29,19 +29,20 @@ class QrCodeDetectionHelper {final int requestId = ++_requestId;if (!isEligible) {- qrContentNotifier.value = null;+ qrDetectionsNotifier.value = const [];return;}// Return cached results immediately without debouncefinal String cacheKey = _cacheKey(file);- if (_cache.containsKey(cacheKey)) {+ final _DetectionResult? cachedResult = _cache[cacheKey];+ if (cachedResult != null) {if (_disposed || requestId != _requestId) return;- qrContentNotifier.value = _cache[cacheKey];+ qrDetectionsNotifier.value = cachedResult.detections;return;}- qrContentNotifier.value = null;+ qrDetectionsNotifier.value = const [];// Debounce uncached scans so swiping doesn't trigger work_debounceTimer = Timer(_debounceDuration, () {@@ -60,30 +61,31 @@ class QrCodeDetectionHelper {final File? localFile = await getFile(file);if (_disposed || requestId != _requestId) return;if (localFile == null || !localFile.existsSync()) {- _cache[cacheKey] = null;- qrContentNotifier.value = null;+ _cache[cacheKey] = const _DetectionResult(detections: []);+ qrDetectionsNotifier.value = const [];return;}- String? content;+ List<QrDetection> detections = const [];try {- final result = await _enteQr.scanQrFromImage(localFile.path);- if (result.success && result.content != null) {- content = result.content;+ final result = await _enteQr.scanAllQrFromImage(localFile.path);+ if (result.success && result.detections.isNotEmpty) {+ detections = result.detections;}} catch (error, stackTrace) {- _logger.severe("Failed to scan QR code", error, stackTrace);+ _logger.severe("Failed to scan QR codes", error, stackTrace);}if (_disposed || requestId != _requestId) return;- _cache[cacheKey] = content;- qrContentNotifier.value = content;+ final detectionResult = _DetectionResult(detections: detections);+ _cache[cacheKey] = detectionResult;+ qrDetectionsNotifier.value = detectionResult.detections;} catch (error, stackTrace) {_logger.severe("QR code detection failed", error, stackTrace);if (_disposed || requestId != _requestId) return;- _cache[cacheKey] = null;- qrContentNotifier.value = null;+ _cache[cacheKey] = const _DetectionResult(detections: []);+ qrDetectionsNotifier.value = const [];}}@@ -105,6 +107,12 @@ class QrCodeDetectionHelper {void dispose() {_disposed = true;_debounceTimer?.cancel();- qrContentNotifier.dispose();+ qrDetectionsNotifier.dispose();}}++class _DetectionResult {+ final List<QrDetection> detections;++ const _DetectionResult({required this.detections});+}diff --git a/mobile/apps/photos/lib/ui/viewer/file/qr_code_highlight_overlay.dart b/mobile/apps/photos/lib/ui/viewer/file/qr_code_highlight_overlay.dartindex ff13052533..ef64f2a275 100644--- a/mobile/apps/photos/lib/ui/viewer/file/qr_code_highlight_overlay.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/qr_code_highlight_overlay.dart@@ -1,18 +1,173 @@+import "dart:async";++import "package:ente_qr/ente_qr.dart";+import "package:flutter/foundation.dart";import "package:flutter/material.dart";+import "package:flutter/services.dart";+import "package:photos/models/file/file.dart";+import "package:photos/ui/viewer/file/qr_code_content_sheet.dart";+import "package:url_launcher/url_launcher.dart";++class QrCodeHighlightOverlay extends StatelessWidget {+ final List<QrDetection> detections;+ final EnteFile file;+ final ValueListenable<bool> enableFullScreenNotifier;-class QrCodeDetectionOverlay extends StatelessWidget {- const QrCodeDetectionOverlay({super.key});+ const QrCodeHighlightOverlay({+ required this.detections,+ required this.file,+ required this.enableFullScreenNotifier,+ super.key,+ });@overrideWidget build(BuildContext context) {- return const Center(- child: SizedBox(- width: 48,- height: 48,- child: CircularProgressIndicator(- strokeWidth: 3,- color: Colors.white,- ),+ if (detections.isEmpty || !file.hasDimensions) {+ return const SizedBox.shrink();+ }++ return ValueListenableBuilder<bool>(+ valueListenable: enableFullScreenNotifier,+ builder: (context, isFullScreen, _) {+ if (isFullScreen) {+ return const SizedBox.shrink();+ }++ return LayoutBuilder(+ builder: (context, constraints) {+ final screenWidth = constraints.maxWidth;+ final screenHeight = constraints.maxHeight;+ final imageAspect = file.width / file.height;+ final screenAspect = screenWidth / screenHeight;++ double displayWidth;+ double displayHeight;+ if (imageAspect > screenAspect) {+ displayWidth = screenWidth;+ displayHeight = screenWidth / imageAspect;+ } else {+ displayHeight = screenHeight;+ displayWidth = screenHeight * imageAspect;+ }++ final offsetX = (screenWidth - displayWidth) / 2;+ final offsetY = (screenHeight - displayHeight) / 2;++ return Stack(+ children: [+ for (final detection in detections)+ _QrTapRegion(+ detection: detection,+ offsetX: offsetX,+ offsetY: offsetY,+ displayWidth: displayWidth,+ displayHeight: displayHeight,+ ),+ ],+ );+ },+ );+ },+ );+ }+}++class _QrTapRegion extends StatefulWidget {+ final QrDetection detection;+ final double offsetX;+ final double offsetY;+ final double displayWidth;+ final double displayHeight;++ const _QrTapRegion({+ required this.detection,+ required this.offsetX,+ required this.offsetY,+ required this.displayWidth,+ required this.displayHeight,+ });++ @override+ State<_QrTapRegion> createState() => _QrTapRegionState();+}++class _QrTapRegionState extends State<_QrTapRegion> {+ static const _longPressDuration = Duration(milliseconds: 500);+ static const _moveThreshold = 20.0;+ Timer? _timer;+ Offset? _downPosition;++ @override+ void dispose() {+ _timer?.cancel();+ super.dispose();+ }++ Future<void> _onLongPress() async {+ await HapticFeedback.lightImpact();+ final uri = Uri.tryParse(widget.detection.content);+ final isUpi = uri != null && uri.scheme == "upi";+ if (isUpi) {+ try {+ final launched =+ await launchUrl(uri, mode: LaunchMode.externalApplication);+ if (!launched && mounted) {+ await showQrCodeContentSheet(+ context,+ detections: [widget.detection],+ );+ }+ } catch (_) {+ if (mounted) {+ await showQrCodeContentSheet(+ context,+ detections: [widget.detection],+ );+ }+ }+ } else {+ await showQrCodeContentSheet(+ context,+ detections: [widget.detection],+ );+ }+ }++ @override+ Widget build(BuildContext context) {+ final rawW = widget.detection.width * widget.displayWidth;+ final rawH = widget.detection.height * widget.displayHeight;+ const double minTapTarget = 48.0;+ final screenW = rawW < minTapTarget ? minTapTarget : rawW;+ final screenH = rawH < minTapTarget ? minTapTarget : rawH;+ final screenX = widget.offsetX ++ widget.detection.x * widget.displayWidth -+ (screenW - rawW) / 2;+ final screenY = widget.offsetY ++ widget.detection.y * widget.displayHeight -+ (screenH - rawH) / 2;++ return Positioned(+ left: screenX,+ top: screenY,+ width: screenW,+ height: screenH,+ child: Listener(+ behavior: HitTestBehavior.translucent,+ onPointerDown: (event) {+ _downPosition = event.position;+ _timer?.cancel();+ _timer = Timer(_longPressDuration, _onLongPress);+ },+ onPointerMove: (event) {+ if (_downPosition != null &&+ (event.position - _downPosition!).distance > _moveThreshold) {+ _timer?.cancel();+ }+ },+ onPointerUp: (_) => _timer?.cancel(),+ onPointerCancel: (_) => _timer?.cancel(),+ child: const SizedBox.expand(),),);}