From d8027be729fdcb2f122bf1cdc3f87970c8065668 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 3 Jan 2020 09:09:14 +0100 Subject: [PATCH] Add image viewer --- lib/components/list_items/chat_list_item.dart | 51 ++++++++++++++++--- lib/components/message_content.dart | 44 ++++++++++++---- 2 files changed, 78 insertions(+), 17 deletions(-) diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 7a4930f..d432660 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -19,11 +19,50 @@ class ChatListItem extends StatelessWidget { color: activeChat ? Color(0xFFE8E8E8) : Colors.white, child: ListTile( leading: Avatar(room.avatar), - title: Text( - room.displayname, - maxLines: 1, + title: Row( + children: [ + Expanded( + child: Text( + room.displayname, + maxLines: 1, + ), + ), + Text(ChatTime(room.timeCreated).toEventTimeString()), + ], + ), + subtitle: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded(child: MessageContent(room.lastEvent, textOnly: true)), + SizedBox(width: 8), + room.pushRuleState == PushRuleState.notify + ? Container() + : Icon( + Icons.notifications_off, + color: Colors.grey, + size: 20, + ), + room.notificationCount > 0 + ? Container( + width: 20, + height: 20, + margin: EdgeInsets.only(top: 3), + decoration: BoxDecoration( + color: room.highlightCount > 0 + ? Colors.red + : Color(0xFF5625BA), + borderRadius: BorderRadius.circular(20), + ), + child: Center( + child: Text( + room.notificationCount.toString(), + style: TextStyle(color: Colors.white), + ), + ), + ) + : Text(" "), + ], ), - subtitle: MessageContent(room.lastEvent, textOnly: true), onTap: () { if (activeChat) { Navigator.pushReplacement( @@ -38,7 +77,7 @@ class ChatListItem extends StatelessWidget { } }, onLongPress: () {}, - trailing: Container( + /*trailing: Container( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.end, @@ -65,7 +104,7 @@ class ChatListItem extends StatelessWidget { : Text(" "), ], ), - ), + ),*/ ), ); } diff --git a/lib/components/message_content.dart b/lib/components/message_content.dart index da61ae0..328b0d2 100644 --- a/lib/components/message_content.dart +++ b/lib/components/message_content.dart @@ -1,4 +1,9 @@ +import 'dart:math'; + +import 'package:bubble/bubble.dart'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:famedlysdk/famedlysdk.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -14,19 +19,36 @@ class MessageContent extends StatelessWidget { @override Widget build(BuildContext context) { final int maxLines = textOnly ? 1 : null; - if (textOnly) { - return Text( - event.getBody(), - style: TextStyle( - color: textColor, - decoration: event.redacted ? TextDecoration.lineThrough : null, - ), - maxLines: maxLines, - ); - } switch (event.type) { - case EventTypes.Audio: case EventTypes.Image: + final int size = 400; + final String src = MxContent(event.content["url"]).getThumbnail( + Matrix.of(context).client, + width: size * MediaQuery.of(context).devicePixelRatio, + height: size * MediaQuery.of(context).devicePixelRatio, + method: ThumbnailMethod.scale, + ); + return Bubble( + padding: BubbleEdges.all(0), + radius: Radius.circular(50), + elevation: 0, + child: InkWell( + onTap: () => launch( + MxContent(event.content["url"]) + .getDownloadLink(Matrix.of(context).client), + ), + child: kIsWeb + ? Image.network( + src, + width: size.toDouble(), + ) + : CachedNetworkImage( + imageUrl: src, + width: size.toDouble(), + ), + ), + ); + case EventTypes.Audio: case EventTypes.File: case EventTypes.Video: return Container(