π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add onFileLoad callback to file_widget for better loading of progress animation
AmanRajSinghMourya27932679dd5f
diff --git a/mobile/lib/ui/home/memories/full_screen_memory.dart b/mobile/lib/ui/home/memories/full_screen_memory.dartindex 4d3f27f3c4..4559c789c9 100644--- a/mobile/lib/ui/home/memories/full_screen_memory.dart+++ b/mobile/lib/ui/home/memories/full_screen_memory.dart@@ -135,7 +135,8 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {PageController? _pageController;final _showTitle = ValueNotifier<bool>(true);AnimationController? _progressAnimationController;- Duration duration = const Duration(seconds: 5);+ final ValueNotifier<Duration> durationNotifier =+ ValueNotifier(const Duration(seconds: 5));@overridevoid initState() {@@ -153,6 +154,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {void dispose() {_pageController?.dispose();_showTitle.dispose();+ durationNotifier.dispose();super.dispose();}@@ -169,7 +171,6 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {void _resetProgressAnimation() {if (_progressAnimationController != null) {_progressAnimationController!.reset();- _progressAnimationController!.forward();}}@@ -224,14 +225,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {crossAxisAlignment: CrossAxisAlignment.start,children: [showStepProgressIndicator- ? FutureBuilder<Duration>(- future: _getVideoDuration(),- builder: (context, snapshot) {- final isLoading =- snapshot.connectionState != ConnectionState.done;- final duration =- snapshot.data ?? const Duration(seconds: 5);-+ ? ValueListenableBuilder<Duration>(+ valueListenable: durationNotifier,+ builder: (context, duration, _) {return NewProgressIndicator(totalSteps: inheritedData.memories.length,currentIndex: value,@@ -240,9 +236,6 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {duration: duration,animationController: (controller) {_progressAnimationController = controller;- if (!isLoading) {- _progressAnimationController!.forward();- }},onComplete: () {final currentIndex =@@ -335,12 +328,12 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {},onLongPress: () {if (!isVideo) {- _toggleProgressAnimation(true);+ _toggleProgressAnimation(true);}},onLongPressUp: () {if (!isVideo) {- _toggleProgressAnimation(false);+ _toggleProgressAnimation(false);}},child: FileWidget(@@ -351,11 +344,15 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {color: Colors.transparent,),isFromMemories: true,- playbackCallback: (isPlaying) {- if (isPlaying) {- _toggleProgressAnimation(false);+ onFileLoad: (isLoaded, duration) {+ if (isLoaded) {+ durationNotifier.value = Duration(seconds: duration);+ _progressAnimationController!.reset();+ _progressAnimationController!.duration =+ durationNotifier.value;+ _progressAnimationController!.forward();} else {- _toggleProgressAnimation(true);+ _progressAnimationController!.stop();}},),diff --git a/mobile/lib/ui/viewer/file/file_widget.dart b/mobile/lib/ui/viewer/file/file_widget.dartindex e690d8f93f..83bfcbbd23 100644--- a/mobile/lib/ui/viewer/file/file_widget.dart+++ b/mobile/lib/ui/viewer/file/file_widget.dart@@ -13,6 +13,7 @@ class FileWidget extends StatelessWidget {final BoxDecoration? backgroundDecoration;final bool? autoPlay;final bool? isFromMemories;+ final Function(bool, int)? onFileLoad;const FileWidget(this.file, {@@ -22,6 +23,7 @@ class FileWidget extends StatelessWidget {required this.tagPrefix,this.backgroundDecoration,this.isFromMemories = false,+ this.onFileLoad,super.key,});@@ -41,6 +43,7 @@ class FileWidget extends StatelessWidget {backgroundDecoration: backgroundDecoration,isFromMemories: isFromMemories ?? false,key: key ?? ValueKey(fileKey),+ onFileLoad: onFileLoad,);} else if (file.fileType == FileType.video) {// use old video widget on iOS simulator as the new one crashes while@@ -57,6 +60,7 @@ class FileWidget extends StatelessWidget {file,tagPrefix: tagPrefix,playbackCallback: playbackCallback,+ onFileLoad: onFileLoad,key: key ?? ValueKey(fileKey),);} else {diff --git a/mobile/lib/ui/viewer/file/video_widget.dart b/mobile/lib/ui/viewer/file/video_widget.dartindex 5d9b1b847b..5cb861d56c 100644--- a/mobile/lib/ui/viewer/file/video_widget.dart+++ b/mobile/lib/ui/viewer/file/video_widget.dart@@ -24,10 +24,12 @@ class VideoWidget extends StatefulWidget {final EnteFile file;final String? tagPrefix;final Function(bool)? playbackCallback;+ final Function(bool, int)? onFileLoad;const VideoWidget(this.file, {this.tagPrefix,this.playbackCallback,+ this.onFileLoad,super.key,});@@ -164,6 +166,7 @@ class _VideoWidgetState extends State<VideoWidget> {);});},+ onFileLoad: widget.onFileLoad,);}return VideoWidgetMediaKitNew(@@ -186,6 +189,7 @@ class _VideoWidgetState extends State<VideoWidget> {);});},+ onFileLoad: widget.onFileLoad,);}}diff --git a/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart b/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dartindex 97fb663577..b16982a016 100644--- a/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart+++ b/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart@@ -34,6 +34,7 @@ class VideoWidgetMediaKitNew extends StatefulWidget {final void Function() onStreamChange;final File? preview;final bool selectedPreview;+ final Function(bool, int)? onFileLoad;const VideoWidgetMediaKitNew(this.file, {@@ -43,6 +44,7 @@ class VideoWidgetMediaKitNew extends StatefulWidget {required this.onStreamChange,this.preview,required this.selectedPreview,+ this.onFileLoad,super.key,});@@ -260,6 +262,8 @@ class _VideoWidgetMediaKitNewState extends State<VideoWidgetMediaKitNew>}player.open(Media(url), play: _isAppInFG);});+ final duration = controller!.player.state.duration.inSeconds;+ widget.onFileLoad?.call(true, duration);}}}diff --git a/mobile/lib/ui/viewer/file/video_widget_native.dart b/mobile/lib/ui/viewer/file/video_widget_native.dartindex b84cdc0e3c..93243a8a7a 100644--- a/mobile/lib/ui/viewer/file/video_widget_native.dart+++ b/mobile/lib/ui/viewer/file/video_widget_native.dart@@ -45,6 +45,7 @@ class VideoWidgetNative extends StatefulWidget {final void Function()? onStreamChange;final PlaylistData? playlistData;final bool selectedPreview;+ final Function(bool, int)? onFileLoad;const VideoWidgetNative(this.file, {@@ -54,6 +55,7 @@ class VideoWidgetNative extends StatefulWidget {required this.onStreamChange,super.key,this.playlistData,+ this.onFileLoad,required this.selectedPreview,});@@ -506,6 +508,8 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>Future<void> _onPlaybackReady() async {if (_isPlaybackReady.value) return;await _controller!.play();+ final durationInSeconds = durationToSeconds(duration) ?? 0;+ widget.onFileLoad?.call(true, durationInSeconds);unawaited(_controller!.setVolume(1));_isPlaybackReady.value = true;}diff --git a/mobile/lib/ui/viewer/file/zoomable_image.dart b/mobile/lib/ui/viewer/file/zoomable_image.dartindex 9300b8cacc..8d6a3018c0 100644--- a/mobile/lib/ui/viewer/file/zoomable_image.dart+++ b/mobile/lib/ui/viewer/file/zoomable_image.dart@@ -31,6 +31,7 @@ class ZoomableImage extends StatefulWidget {final Decoration? backgroundDecoration;final bool shouldCover;final bool isGuestView;+ final Function(bool, int)? onFileLoad;const ZoomableImage(this.photo, {@@ -40,6 +41,7 @@ class ZoomableImage extends StatefulWidget {this.backgroundDecoration,this.shouldCover = false,this.isGuestView = false,+ this.onFileLoad,});@override@@ -292,6 +294,11 @@ class _ZoomableImageState extends State<ZoomableImage> {}});}+ if (_imageProvider == null) {+ widget.onFileLoad?.call(false, 5);+ } else {+ widget.onFileLoad?.call(true, 5);+ }}void _loadLocalImage(BuildContext context) {@@ -348,6 +355,11 @@ class _ZoomableImageState extends State<ZoomableImage> {}});}+ if (_imageProvider == null) {+ widget.onFileLoad?.call(false, 5);+ } else {+ widget.onFileLoad?.call(true, 5);+ }}void _onLargeThumbnailLoaded(diff --git a/mobile/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/lib/ui/viewer/file/zoomable_live_image_new.dartindex 9c482b77fc..739238097e 100644--- a/mobile/lib/ui/viewer/file/zoomable_live_image_new.dart+++ b/mobile/lib/ui/viewer/file/zoomable_live_image_new.dart@@ -24,6 +24,7 @@ class ZoomableLiveImageNew extends StatefulWidget {final String? tagPrefix;final Decoration? backgroundDecoration;final bool isFromMemories;+ final Function(bool, int)? onFileLoad;const ZoomableLiveImageNew(this.enteFile, {@@ -32,6 +33,7 @@ class ZoomableLiveImageNew extends StatefulWidget {required this.tagPrefix,this.backgroundDecoration,this.isFromMemories = false,+ this.onFileLoad,});@override@@ -96,15 +98,16 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>shouldDisableScroll: widget.shouldDisableScroll,backgroundDecoration: widget.backgroundDecoration,isGuestView: isGuestView,+ onFileLoad: widget.onFileLoad,+ );+ }+ if (!widget.isFromMemories) {+ return GestureDetector(+ onLongPressStart: (_) => _onLongPressEvent(true),+ onLongPressEnd: (_) => _onLongPressEvent(false),+ child: content,);}- if (!widget.isFromMemories) {- return GestureDetector(- onLongPressStart: (_) => _onLongPressEvent(true),- onLongPressEnd: (_) => _onLongPressEvent(false),- child: content,- );- }return content;}