From 4900137e2ad961af3e1226642b482109e8b7694f Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 13 Mar 2020 21:58:48 +0100 Subject: [PATCH] Minor tweaks --- lib/components/message_content.dart | 92 +++++++++++------------------ lib/i18n/i18n.dart | 10 ++-- lib/utils/event_extension.dart | 18 ++++++ 3 files changed, 59 insertions(+), 61 deletions(-) diff --git a/lib/components/message_content.dart b/lib/components/message_content.dart index 60d9f99..a59c172 100644 --- a/lib/components/message_content.dart +++ b/lib/components/message_content.dart @@ -59,65 +59,45 @@ class MessageContent extends StatelessWidget { ), ); case MessageTypes.Audio: - return Container( - width: 200, - child: RaisedButton( - color: Colors.blueGrey, - child: Row( - children: [ - Icon(Icons.play_arrow, color: Colors.white), - Text( - I18n.of(context).play(event.body), - overflow: TextOverflow.fade, - softWrap: false, - maxLines: 1, - style: TextStyle(color: Colors.white), - ), - ], - ), - onPressed: () => launch(MxContent(event.content["url"]) - .getDownloadLink(event.room.client)), - ), - ); case MessageTypes.Video: - return Container( - width: 200, - child: RaisedButton( - color: Colors.blueGrey, - child: Row( - children: [ - Icon(Icons.play_arrow, color: Colors.white), - Text( - I18n.of(context).play(event.body), - overflow: TextOverflow.fade, - softWrap: false, - maxLines: 1, - style: TextStyle(color: Colors.white), - ), - ], - ), - onPressed: () => launch( - MxContent(event.content["url"]) - .getDownloadLink(event.room.client), - ), - ), - ); case MessageTypes.File: return Container( - width: 200, - child: RaisedButton( - color: Colors.blueGrey, - child: Text( - I18n.of(context).download(event.body), - overflow: TextOverflow.fade, - softWrap: false, - maxLines: 1, - style: TextStyle(color: Colors.white), - ), - onPressed: () => launch( - MxContent(event.content["url"]) - .getDownloadLink(Matrix.of(context).client), - ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + RaisedButton( + color: Colors.blueGrey, + child: Text( + I18n.of(context).downloadFile, + overflow: TextOverflow.fade, + softWrap: false, + maxLines: 1, + style: TextStyle(color: Colors.white), + ), + onPressed: () => launch( + MxContent(event.content["url"]) + .getDownloadLink(event.room.client), + ), + ), + if (event.sizeString != null) + Text( + event.sizeString, + style: TextStyle( + color: textColor, + fontStyle: FontStyle.italic, + ), + ), + Text( + (event.content.containsKey("filename") + ? event.content["filename"] + : event.body), + style: TextStyle( + color: textColor, + fontStyle: FontStyle.italic, + ), + ), + ], ), ); case MessageTypes.BadEncrypted: diff --git a/lib/i18n/i18n.dart b/lib/i18n/i18n.dart index cd41803..c2e2640 100644 --- a/lib/i18n/i18n.dart +++ b/lib/i18n/i18n.dart @@ -272,11 +272,7 @@ class I18n { String get displaynameHasBeenChanged => Intl.message("Displayname has been changed"); - String download(String fileName) => Intl.message( - "Download $fileName", - name: "download", - args: [fileName], - ); + String get downloadFile => Intl.message("Download file"); String get editDisplayname => Intl.message("Edit displayname"); @@ -296,6 +292,10 @@ class I18n { String get enterAUsername => Intl.message("Enter a username"); + String get fileName => Intl.message("File name"); + + String get fileSize => Intl.message("File size"); + String get fluffychat => Intl.message("FluffyChat"); String get forward => Intl.message('Forward'); diff --git a/lib/utils/event_extension.dart b/lib/utils/event_extension.dart index 6289b0e..fd3ea6e 100644 --- a/lib/utils/event_extension.dart +++ b/lib/utils/event_extension.dart @@ -260,4 +260,22 @@ extension LocalizedBody on Event { return Icons.done; } } + + String get sizeString { + if (content["info"] is Map && + content["info"].containsKey("size")) { + num size = content["info"]["size"]; + if (size < 1000000) { + size = size / 1000; + return "${size.toString()}kb"; + } else if (size < 1000000000) { + size = size / 1000000; + return "${size.toString()}mb"; + } else { + size = size / 1000000000; + return "${size.toString()}gb"; + } + } else + return null; + } }