chore: Merge upstream changes --------- Signed-off-by: Krille <c.kussowski@famedly.com> Co-authored-by: krille-chan <christian-kussowski@posteo.de> Co-authored-by: Krille <c.kussowski@famedly.com> Co-authored-by: Linerly <linerly@proton.me> Co-authored-by: Priit Jõerüüt <hwlate@joeruut.com> Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org> Co-authored-by: fadelkon <fadelkon@posteo.net> Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com> Co-authored-by: Edgars Andersons <Edgars+Weblate@gaitenis.id.lv> Co-authored-by: josé m <correoxm@disroot.org> Co-authored-by: Bezruchenko Simon <worcposj44@gmail.com> Co-authored-by: Christian <christian-pauly@posteo.de> Co-authored-by: - <hitekex@yandex.ru> Co-authored-by: Angelo Schirinzi <Odi-3@users.noreply.hosted.weblate.org> Co-authored-by: xabirequejo <xabi.rn@gmail.com> Co-authored-by: Piotr Orzechowski <piotr@orzechowski.tech> Co-authored-by: Rex_sa <rex.sa@pm.me> Co-authored-by: Tewuzij <tenajeza@outlook.com> Co-authored-by: goknarbahceli <goknarbahceli@proton.me> Co-authored-by: தமிழ்நேரம் <anishprabu.t@gmail.com> Co-authored-by: Erin <erin@erindesu.cz> Co-authored-by: EpicKiwi <me@epickiwi.fr> Co-authored-by: Christian Tietze <me@christiantietze.de> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
146 lines
4 KiB
Dart
146 lines
4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
|
import 'package:fluffychat/utils/file_description.dart';
|
|
import 'package:fluffychat/utils/url_launcher.dart';
|
|
import 'package:fluffychat/widgets/mxc_image.dart';
|
|
import '../../../widgets/blur_hash.dart';
|
|
|
|
class ImageBubble extends StatelessWidget {
|
|
final Event event;
|
|
final bool tapToView;
|
|
final BoxFit fit;
|
|
final bool maxSize;
|
|
final Color? backgroundColor;
|
|
final Color? textColor;
|
|
final Color? linkColor;
|
|
final bool thumbnailOnly;
|
|
final bool animated;
|
|
final double width;
|
|
final double height;
|
|
final void Function()? onTap;
|
|
final BorderRadius? borderRadius;
|
|
final Timeline? timeline;
|
|
|
|
const ImageBubble(
|
|
this.event, {
|
|
this.tapToView = true,
|
|
this.maxSize = true,
|
|
this.backgroundColor,
|
|
this.fit = BoxFit.contain,
|
|
this.thumbnailOnly = true,
|
|
this.width = 400,
|
|
this.height = 300,
|
|
this.animated = false,
|
|
this.onTap,
|
|
this.borderRadius,
|
|
this.timeline,
|
|
this.textColor,
|
|
this.linkColor,
|
|
super.key,
|
|
});
|
|
|
|
Widget _buildPlaceholder(BuildContext context) {
|
|
final String blurHashString =
|
|
event.infoMap['xyz.amorgan.blurhash'] is String
|
|
? event.infoMap['xyz.amorgan.blurhash']
|
|
: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
|
|
return SizedBox(
|
|
width: width,
|
|
height: height,
|
|
child: BlurHash(
|
|
blurhash: blurHashString,
|
|
width: width,
|
|
height: height,
|
|
fit: fit,
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onTap(BuildContext context) {
|
|
if (onTap != null) {
|
|
onTap!();
|
|
return;
|
|
}
|
|
if (!tapToView) return;
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) => ImageViewer(
|
|
event,
|
|
timeline: timeline,
|
|
outerContext: context,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
final borderRadius =
|
|
this.borderRadius ?? BorderRadius.circular(AppConfig.borderRadius);
|
|
|
|
final fileDescription = event.fileDescription;
|
|
final textColor = this.textColor;
|
|
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
spacing: 8,
|
|
children: [
|
|
Material(
|
|
color: Colors.transparent,
|
|
clipBehavior: Clip.hardEdge,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: borderRadius,
|
|
side: BorderSide(
|
|
color: event.messageType == MessageTypes.Sticker
|
|
? Colors.transparent
|
|
: theme.dividerColor,
|
|
),
|
|
),
|
|
child: InkWell(
|
|
onTap: () => _onTap(context),
|
|
borderRadius: borderRadius,
|
|
child: Hero(
|
|
tag: event.eventId,
|
|
child: MxcImage(
|
|
event: event,
|
|
width: width,
|
|
height: height,
|
|
fit: fit,
|
|
animated: animated,
|
|
isThumbnail: thumbnailOnly,
|
|
placeholder: event.messageType == MessageTypes.Sticker
|
|
? null
|
|
: _buildPlaceholder,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (fileDescription != null && textColor != null)
|
|
SizedBox(
|
|
width: width,
|
|
child: Linkify(
|
|
text: fileDescription,
|
|
style: TextStyle(
|
|
color: textColor,
|
|
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
|
),
|
|
options: const LinkifyOptions(humanize: false),
|
|
linkStyle: TextStyle(
|
|
color: linkColor,
|
|
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
|
decoration: TextDecoration.underline,
|
|
decorationColor: linkColor,
|
|
),
|
|
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|