π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Clarify live image long press routing
Neeraj Guptac0fd74a5af32
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex 9616a52587..45d83e127b 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -422,7 +422,7 @@ class _BodyState extends State<_Body> {},backgroundDecoration: const BoxDecoration(color: Colors.black),qrDetectionsNotifier: _qrHelper?.qrDetectionsNotifier,- onLongPressStart:+ onTextSelectionStart:flagService.ocrOverlayEnabled &&widget.config.mode != DetailPageMode.minimalistic &&!file.isLiveOrMotionPhotodiff --git a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dartindex c528a8b23c..05231ebcb9 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart@@ -17,7 +17,7 @@ class FileWidget extends StatelessWidget {final bool? isFromMemories;final Function({required int memoryDuration})? onFinalFileLoad;final ValueNotifier<List<QrDetection>>? qrDetectionsNotifier;- final GestureLongPressStartCallback? onLongPressStart;+ final GestureLongPressStartCallback? onTextSelectionStart;const FileWidget(this.file, {@@ -29,7 +29,7 @@ class FileWidget extends StatelessWidget {this.isFromMemories = false,this.onFinalFileLoad,this.qrDetectionsNotifier,- this.onLongPressStart,+ this.onTextSelectionStart,super.key,});@@ -50,7 +50,7 @@ class FileWidget extends StatelessWidget {key: key ?? ValueKey(fileKey),onFinalFileLoad: onFinalFileLoad,qrDetectionsNotifier: qrDetectionsNotifier,- onLongPressStart: onLongPressStart,+ onTextSelectionStart: onTextSelectionStart,);} else if (file.fileType == FileType.video) {// use old video widget on iOS simulator as the new one crashes whilediff --git a/mobile/apps/photos/lib/ui/viewer/file/live_image_long_press_router.dart b/mobile/apps/photos/lib/ui/viewer/file/live_image_long_press_router.dartnew file mode 100644index 0000000000..347c8eb88b--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/file/live_image_long_press_router.dart@@ -0,0 +1,26 @@+enum MotionPhotoAvailability { unknown, absent, present }++enum LiveImageLongPressAction { playback, textSelection }++class LiveImageLongPressRouter {+ LiveImageLongPressRouter({+ required MotionPhotoAvailability initialAvailability,+ required Future<MotionPhotoAvailability> Function() probeMotionPhoto,+ }) : _availability = initialAvailability,+ _probeMotionPhoto = probeMotionPhoto;++ MotionPhotoAvailability _availability;+ final Future<MotionPhotoAvailability> Function() _probeMotionPhoto;++ Future<LiveImageLongPressAction> resolve() async {+ if (_availability == MotionPhotoAvailability.unknown) {+ final availability = await _probeMotionPhoto();+ if (availability != MotionPhotoAvailability.unknown) {+ _availability = availability;+ }+ }+ return _availability == MotionPhotoAvailability.present+ ? LiveImageLongPressAction.playback+ : LiveImageLongPressAction.textSelection;+ }+}diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dartindex 6267010439..8dfe2ab806 100644--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart@@ -18,6 +18,7 @@ import "package:photos/services/file_magic_service.dart";import "package:photos/src/rust/api/motion_photo_api.dart";import "package:photos/states/detail_page_state.dart";import 'package:photos/ui/notification/toast.dart';+import "package:photos/ui/viewer/file/live_image_long_press_router.dart";import 'package:photos/ui/viewer/file/zoomable_image.dart';class ZoomableLiveImageNew extends StatefulWidget {@@ -28,7 +29,7 @@ class ZoomableLiveImageNew extends StatefulWidget {final bool isFromMemories;final Function({required int memoryDuration})? onFinalFileLoad;final ValueNotifier<List<QrDetection>>? qrDetectionsNotifier;- final GestureLongPressStartCallback? onLongPressStart;+ final GestureLongPressStartCallback? onTextSelectionStart;const ZoomableLiveImageNew(this.enteFile, {@@ -39,7 +40,7 @@ class ZoomableLiveImageNew extends StatefulWidget {this.isFromMemories = false,this.onFinalFileLoad,this.qrDetectionsNotifier,- this.onLongPressStart,+ this.onTextSelectionStart,});@override@@ -161,7 +162,7 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>void _onLongPressStart(LongPressStartDetails details) {if (_isLongPressInVisibleQrRegion(details.localPosition)) return;- final onTextSelectionStart = widget.onLongPressStart;+ final onTextSelectionStart = widget.onTextSelectionStart;if (onTextSelectionStart == null || _enteFile.isLivePhoto) {_setPlaybackPressed(true);_playOrLoadVideo();@@ -431,43 +432,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>}}-enum MotionPhotoAvailability { unknown, absent, present }--enum LiveImageLongPressAction { playback, textSelection }--class LiveImageLongPressRouter {- LiveImageLongPressRouter({- required MotionPhotoAvailability initialAvailability,- required Future<MotionPhotoAvailability> Function() probeMotionPhoto,- }) : _availability = initialAvailability,- _probeMotionPhoto = probeMotionPhoto;-- MotionPhotoAvailability _availability;- final Future<MotionPhotoAvailability> Function() _probeMotionPhoto;- Future<MotionPhotoAvailability>? _activeProbe;-- Future<LiveImageLongPressAction> resolve() async {- var availability = _availability;- if (availability == MotionPhotoAvailability.unknown) {- final probe = _activeProbe ?? _probeMotionPhoto();- _activeProbe = probe;- try {- availability = await probe;- if (availability != MotionPhotoAvailability.unknown) {- _availability = availability;- }- } finally {- if (identical(_activeProbe, probe)) {- _activeProbe = null;- }- }- }- return availability == MotionPhotoAvailability.present- ? LiveImageLongPressAction.playback- : LiveImageLongPressAction.textSelection;- }-}-class _MotionPhotoVideoResult {final MotionPhotoAvailability availability;final File? videoFile;diff --git a/mobile/apps/photos/test/ui/viewer/file/live_image_long_press_router_test.dart b/mobile/apps/photos/test/ui/viewer/file/live_image_long_press_router_test.dartnew file mode 100644index 0000000000..bc8a3badc1--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/file/live_image_long_press_router_test.dart@@ -0,0 +1,34 @@+import "package:flutter_test/flutter_test.dart";+import "package:photos/ui/viewer/file/live_image_long_press_router.dart";++void main() {+ test("untagged motion photos retain playback after probing", () async {+ var probes = 0;+ final router = LiveImageLongPressRouter(+ initialAvailability: MotionPhotoAvailability.unknown,+ probeMotionPhoto: () async {+ probes++;+ return MotionPhotoAvailability.present;+ },+ );++ expect(await router.resolve(), LiveImageLongPressAction.playback);+ expect(await router.resolve(), LiveImageLongPressAction.playback);+ expect(probes, 1);+ });++ test("untagged still photos fall back to text selection", () async {+ var probes = 0;+ final router = LiveImageLongPressRouter(+ initialAvailability: MotionPhotoAvailability.unknown,+ probeMotionPhoto: () async {+ probes++;+ return MotionPhotoAvailability.absent;+ },+ );++ expect(await router.resolve(), LiveImageLongPressAction.textSelection);+ expect(await router.resolve(), LiveImageLongPressAction.textSelection);+ expect(probes, 1);+ });+}diff --git a/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dart b/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dartindex 660ee96074..51de3f9db6 100644--- a/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dart+++ b/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dart@@ -11,50 +11,20 @@ void main() {final file = EnteFile()..generatedID = 1..fileType = FileType.image;- void onLongPressStart(LongPressStartDetails _) {}+ void onTextSelectionStart(LongPressStartDetails _) {}final built = FileWidget(file,tagPrefix: "test",- onLongPressStart: onLongPressStart,+ onTextSelectionStart: onTextSelectionStart,).build(_MockBuildContext());expect(built, isA<ZoomableLiveImageNew>());expect(- (built as ZoomableLiveImageNew).onLongPressStart,- same(onLongPressStart),+ (built as ZoomableLiveImageNew).onTextSelectionStart,+ same(onTextSelectionStart),);});-- test("untagged motion photos retain playback after probing", () async {- var probes = 0;- final router = LiveImageLongPressRouter(- initialAvailability: MotionPhotoAvailability.unknown,- probeMotionPhoto: () async {- probes++;- return MotionPhotoAvailability.present;- },- );-- expect(await router.resolve(), LiveImageLongPressAction.playback);- expect(await router.resolve(), LiveImageLongPressAction.playback);- expect(probes, 1);- });-- test("untagged still photos fall back to text selection", () async {- var probes = 0;- final router = LiveImageLongPressRouter(- initialAvailability: MotionPhotoAvailability.unknown,- probeMotionPhoto: () async {- probes++;- return MotionPhotoAvailability.absent;- },- );-- expect(await router.resolve(), LiveImageLongPressAction.textSelection);- expect(await router.resolve(), LiveImageLongPressAction.textSelection);- expect(probes, 1);- });}class _MockBuildContext extends Mock implements BuildContext {}