diff --git a/lib/data/model/download_file_response.dart b/lib/data/model/download_file_response.dart index c91e534e8c..2c3fbed7d9 100644 --- a/lib/data/model/download_file_response.dart +++ b/lib/data/model/download_file_response.dart @@ -21,13 +21,13 @@ class DownloadFileResponse extends Response with EquatableMixin { @override List get props => [ - super.statusCode, - super.statusMessage, - super.data, - super.extra, - super.headers, - super.isRedirect, - super.requestOptions, + statusCode, + statusMessage, + data, + extra, + headers, + isRedirect, + requestOptions, savePath, onReceiveProgress, requestOptions, diff --git a/lib/pages/chat/events/event_video_player.dart b/lib/pages/chat/events/event_video_player.dart index 431d1a2293..1c0aa55f0a 100644 --- a/lib/pages/chat/events/event_video_player.dart +++ b/lib/pages/chat/events/event_video_player.dart @@ -2,6 +2,7 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/chat/events/download_video_state.dart'; import 'package:fluffychat/pages/chat/events/message_content_style.dart'; import 'package:fluffychat/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart'; +import 'package:fluffychat/presentation/mixins/handle_video_download_mixin.dart'; import 'package:fluffychat/presentation/mixins/play_video_action_mixin.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; import 'package:fluffychat/utils/twake_snackbar.dart'; @@ -29,8 +30,6 @@ class EventVideoPlayer extends StatefulWidget { final bool showDuration; - final DownloadVideoEventCallback? handleDownloadVideoEvent; - final String? thumbnailCacheKey; final Map? thumbnailCacheMap; @@ -43,7 +42,6 @@ class EventVideoPlayer extends StatefulWidget { Key? key, this.width, this.height, - this.handleDownloadVideoEvent, this.rounded = true, this.showDuration = false, this.thumbnailCacheMap, @@ -56,14 +54,25 @@ class EventVideoPlayer extends StatefulWidget { } class EventVideoPlayerState extends State - with PlayVideoActionMixin { + with HandleVideoDownloadMixin, PlayVideoActionMixin { final _downloadStateNotifier = ValueNotifier(DownloadVideoState.initial); String? path; + final downloadProgressNotifier = ValueNotifier(0.0); void _downloadAction() async { _downloadStateNotifier.value = DownloadVideoState.loading; try { - path = await widget.handleDownloadVideoEvent?.call(widget.event); + path = await handleDownloadVideoEvent( + event: widget.event, + playVideoAction: (path) => playVideoAction( + context, + path, + eventId: widget.event.eventId, + ), + progressCallback: (count, total) { + downloadProgressNotifier.value = count / total; + }, + ); _downloadStateNotifier.value = DownloadVideoState.done; } on MatrixConnectionException catch (e) { _downloadStateNotifier.value = DownloadVideoState.failed; @@ -130,10 +139,16 @@ class EventVideoPlayerState extends State SizedBox( width: MessageContentStyle.videoCenterButtonSize, height: MessageContentStyle.videoCenterButtonSize, - child: CircularProgressIndicator( - strokeWidth: 2, - color: - LinagoraRefColors.material().primary[100], + child: ValueListenableBuilder( + valueListenable: downloadProgressNotifier, + builder: (context, progress, child) { + return CircularProgressIndicator( + strokeWidth: 2, + color: LinagoraRefColors.material() + .primary[100], + value: progress, + ); + }, ), ), ], diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index d9d1cc4a2d..ccee404e54 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -8,7 +8,6 @@ import 'package:fluffychat/pages/chat/events/redacted_content.dart'; import 'package:fluffychat/pages/chat/events/sending_image_info_widget.dart'; import 'package:fluffychat/pages/chat/events/sending_video_widget.dart'; import 'package:fluffychat/pages/chat/events/unknown_content.dart'; -import 'package:fluffychat/presentation/mixins/play_video_action_mixin.dart'; import 'package:fluffychat/presentation/model/file/display_image_info.dart'; import 'package:fluffychat/utils/extension/image_size_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; @@ -29,7 +28,7 @@ import 'map_bubble.dart'; import 'message_download_content.dart'; import 'sticker.dart'; -class MessageContent extends StatelessWidget with PlayVideoActionMixin { +class MessageContent extends StatelessWidget { final Event event; final Color textColor; final Widget endOfBubbleWidget; @@ -92,16 +91,6 @@ class MessageContent extends StatelessWidget with PlayVideoActionMixin { return _MessageVideoBuilder( event: event, onFileTapped: controller.onFileTapped, - handleDownloadVideoEvent: (event) { - return controller.handleDownloadVideoEvent( - event: event, - playVideoAction: (path) => playVideoAction( - context, - path, - eventId: event.eventId, - ), - ); - }, ); case MessageTypes.File: return Column( @@ -328,12 +317,9 @@ class _MessageVideoBuilder extends StatelessWidget { final void Function(Event event) onFileTapped; - final DownloadVideoEventCallback handleDownloadVideoEvent; - const _MessageVideoBuilder({ required this.event, required this.onFileTapped, - required this.handleDownloadVideoEvent, }); @override @@ -365,7 +351,6 @@ class _MessageVideoBuilder extends StatelessWidget { } return EventVideoPlayer( event, - handleDownloadVideoEvent: handleDownloadVideoEvent, width: displayImageInfo.size.width, height: displayImageInfo.size.height, ); diff --git a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart index 2e63fa9925..a14e546c20 100644 --- a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart +++ b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart @@ -96,7 +96,6 @@ class _VideoItem extends StatelessWidget { Widget build(BuildContext context) { return EventVideoPlayer( event, - handleDownloadVideoEvent: handleDownloadVideoEvent, rounded: false, showDuration: true, thumbnailCacheKey: event.eventId, diff --git a/lib/utils/string_extension.dart b/lib/utils/string_extension.dart index ddd1fcc1db..b55a62eaaf 100644 --- a/lib/utils/string_extension.dart +++ b/lib/utils/string_extension.dart @@ -297,7 +297,7 @@ extension StringCasingExtension on String { if (length < maxCharacters) return this; return substring(0, maxCharacters); } - + String substringToHighlight(String highlightText, {int prefixLength = 0}) { if (prefixLength < 0) return this; final index = toLowerCase().indexOf(highlightText.toLowerCase()); @@ -306,8 +306,4 @@ extension StringCasingExtension on String { } return this; } - - String getFileNameFromPath() { - return split('/').last; - } } diff --git a/lib/widgets/mxc_image.dart b/lib/widgets/mxc_image.dart index 619364725d..33f846c574 100644 --- a/lib/widgets/mxc_image.dart +++ b/lib/widgets/mxc_image.dart @@ -271,40 +271,67 @@ class _MxcImageState extends State borderRadius: widget.rounded ? BorderRadius.circular(12.0) : BorderRadius.zero, - child: filePath != null && filePath!.isNotEmpty - ? Image.file( - File(filePath!), - width: widget.width, - height: widget.height, - cacheWidth: needResize ? widget.width?.toInt() : null, - cacheHeight: needResize ? widget.height?.toInt() : null, - fit: widget.fit, - filterQuality: FilterQuality.medium, - errorBuilder: (context, __, ___) { - _isCached = false; - filePath = null; - WidgetsBinding.instance.addPostFrameCallback(_tryLoad); - return placeholder(context); - }, - ) - : data != null - ? Image.memory( - data, - width: widget.width, - height: widget.height, - cacheWidth: needResize ? widget.width?.toInt() : null, - cacheHeight: needResize ? widget.height?.toInt() : null, - fit: widget.fit, - filterQuality: FilterQuality.medium, - errorBuilder: (context, __, ___) { - _isCached = false; - _imageData = null; - WidgetsBinding.instance - .addPostFrameCallback(_tryLoad); - return placeholder(context); - }, - ) - : const SizedBox.shrink(), + child: _ImageWidget( + filePath: filePath, + data: data, + width: widget.width, + height: widget.height, + fit: widget.fit, + needResize: needResize, + imageErrorWidgetBuilder: (context, __, ___) { + _isCached = false; + _imageData = null; + WidgetsBinding.instance.addPostFrameCallback(_tryLoad); + return placeholder(context); + }, + ), ); } } + +class _ImageWidget extends StatelessWidget { + final String? filePath; + final Uint8List? data; + final double? width; + final double? height; + final bool needResize; + final BoxFit? fit; + final ImageErrorWidgetBuilder imageErrorWidgetBuilder; + + const _ImageWidget({ + this.filePath, + this.data, + this.width, + this.height, + required this.needResize, + this.fit, + required this.imageErrorWidgetBuilder, + }); + + @override + Widget build(BuildContext context) { + return filePath != null && filePath!.isNotEmpty + ? Image.file( + File(filePath!), + width: width, + height: height, + cacheWidth: needResize ? width?.toInt() : null, + cacheHeight: needResize ? height?.toInt() : null, + fit: fit, + filterQuality: FilterQuality.medium, + errorBuilder: imageErrorWidgetBuilder, + ) + : data != null + ? Image.memory( + data!, + width: width, + height: height, + cacheWidth: needResize ? width?.toInt() : null, + cacheHeight: needResize ? height?.toInt() : null, + fit: fit, + filterQuality: FilterQuality.medium, + errorBuilder: imageErrorWidgetBuilder, + ) + : const SizedBox.shrink(); + } +} diff --git a/pubspec.lock b/pubspec.lock index 3d23bba149..d1cc95866f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1566,8 +1566,8 @@ packages: dependency: "direct main" description: path: "." - ref: "feat/support-get-store-fileEntity" - resolved-ref: c4d139570f8126d4cd8b6f24fcae5f09f70a1329 + ref: "twake-supported-0.22.4" + resolved-ref: "1cb0e2d896f9adf8787398a7bebd5c0f6e7345e5" url: "git@github.com:linagora/matrix-dart-sdk.git" source: git version: "0.22.4" diff --git a/pubspec.yaml b/pubspec.yaml index 7ac44fa289..0f55bdbeb2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -68,7 +68,7 @@ dependencies: matrix: git: url: git@github.com:linagora/matrix-dart-sdk.git - ref: feat/support-get-store-fileEntity + ref: twake-supported-0.22.4 matrix_homeserver_recommendations: ^0.3.0 matrix_link_text: ^2.0.0 native_imaging: ^0.1.0