-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1650: reorganize image_builder folder
- Loading branch information
1 parent
c0e6e7f
commit e99132b
Showing
18 changed files
with
329 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/pages/chat/events/images_builder/image_placeholder.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:fluffychat/config/app_config.dart'; | ||
import 'package:fluffychat/pages/chat/events/message_content_style.dart'; | ||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_blurhash/flutter_blurhash.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class ImagePlaceholder extends StatelessWidget { | ||
const ImagePlaceholder({ | ||
super.key, | ||
required this.event, | ||
required this.width, | ||
required this.height, | ||
required this.fit, | ||
}); | ||
|
||
final Event event; | ||
final double width; | ||
final double height; | ||
final BoxFit fit; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (event.messageType == MessageTypes.Sticker) { | ||
return const Center( | ||
child: CircularProgressIndicator.adaptive(), | ||
); | ||
} | ||
final String blurHashString = | ||
event.blurHash ?? AppConfig.defaultImageBlurHash; | ||
final ratio = event.infoMap['w'] is int && event.infoMap['h'] is int | ||
? event.infoMap['w'] / event.infoMap['h'] | ||
: 1.0; | ||
var width = MessageContentStyle.blurhashSize; | ||
var height = MessageContentStyle.blurhashSize; | ||
if (ratio > 1.0) { | ||
height = (width / ratio).round(); | ||
} else { | ||
width = (height * ratio).round(); | ||
} | ||
return ClipRRect( | ||
borderRadius: BorderRadius.zero, | ||
child: SizedBox( | ||
width: this.width, | ||
height: this.height, | ||
child: BlurHash( | ||
hash: blurHashString, | ||
decodingWidth: width, | ||
decodingHeight: height, | ||
imageFit: fit, | ||
), | ||
), | ||
); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
lib/pages/chat/events/images_builder/message_content_image_builder.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:fluffychat/pages/chat/events/images_builder/image_bubble.dart'; | ||
import 'package:fluffychat/pages/chat/events/message_content_style.dart'; | ||
import 'package:fluffychat/pages/chat/events/images_builder/sending_image_info_widget.dart'; | ||
import 'package:fluffychat/presentation/model/file/display_image_info.dart'; | ||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; | ||
import 'package:fluffychat/utils/platform_infos.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
import 'package:fluffychat/utils/extension/image_size_extension.dart'; | ||
|
||
class MessageImageBuilder extends StatelessWidget { | ||
final Event event; | ||
|
||
final void Function()? onTapPreview; | ||
|
||
final void Function()? onTapSelectMode; | ||
|
||
const MessageImageBuilder({ | ||
super.key, | ||
required this.event, | ||
this.onTapPreview, | ||
this.onTapSelectMode, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final matrixFile = event.getMatrixFile(); | ||
|
||
DisplayImageInfo? displayImageInfo = | ||
event.getOriginalResolution()?.getDisplayImageInfo(context); | ||
|
||
if (isSendingImageInMobile(matrixFile)) { | ||
final file = matrixFile as MatrixImageFile; | ||
displayImageInfo = Size( | ||
file.width?.toDouble() ?? MessageContentStyle.imageWidth(context), | ||
file.height?.toDouble() ?? MessageContentStyle.imageHeight(context), | ||
).getDisplayImageInfo(context); | ||
return SendingImageInfoWidget( | ||
key: ValueKey(event.eventId), | ||
matrixFile: file, | ||
event: event, | ||
onTapPreview: onTapPreview, | ||
displayImageInfo: displayImageInfo, | ||
); | ||
} | ||
displayImageInfo ??= DisplayImageInfo( | ||
size: Size( | ||
MessageContentStyle.imageWidth(context), | ||
MessageContentStyle.imageHeight(context), | ||
), | ||
hasBlur: true, | ||
); | ||
if (isSendingImageInWeb(matrixFile)) { | ||
final file = matrixFile as MatrixImageFile; | ||
displayImageInfo = Size( | ||
file.width?.toDouble() ?? MessageContentStyle.imageWidth(context), | ||
file.height?.toDouble() ?? MessageContentStyle.imageHeight(context), | ||
).getDisplayImageInfo(context); | ||
return SendingImageInfoWidget( | ||
key: ValueKey(event.eventId), | ||
matrixFile: file, | ||
event: event, | ||
onTapPreview: onTapPreview, | ||
displayImageInfo: displayImageInfo, | ||
); | ||
} | ||
return ImageBubble( | ||
event, | ||
width: displayImageInfo.size.width, | ||
height: displayImageInfo.size.height, | ||
fit: BoxFit.cover, | ||
onTapSelectMode: onTapSelectMode, | ||
onTapPreview: onTapPreview, | ||
animated: true, | ||
thumbnailOnly: true, | ||
); | ||
} | ||
|
||
bool isSendingImageInWeb(MatrixFile? matrixFile) { | ||
return matrixFile != null && | ||
matrixFile.bytes != null && | ||
matrixFile is MatrixImageFile; | ||
} | ||
|
||
bool isSendingImageInMobile(MatrixFile? matrixFile) { | ||
return matrixFile != null && | ||
matrixFile.filePath != null && | ||
matrixFile is MatrixImageFile && | ||
!PlatformInfos.isWeb; | ||
} | ||
} |
Oops, something went wrong.