Minor tweaks

This commit is contained in:
Christian Pauly 2020-03-13 21:58:48 +01:00
parent 01b1b56852
commit 4900137e2a
3 changed files with 59 additions and 61 deletions

View File

@ -59,65 +59,45 @@ class MessageContent extends StatelessWidget {
), ),
); );
case MessageTypes.Audio: case MessageTypes.Audio:
return Container(
width: 200,
child: RaisedButton(
color: Colors.blueGrey,
child: Row(
children: <Widget>[
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: case MessageTypes.Video:
return Container(
width: 200,
child: RaisedButton(
color: Colors.blueGrey,
child: Row(
children: <Widget>[
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: case MessageTypes.File:
return Container( return Container(
width: 200, child: Column(
child: RaisedButton( crossAxisAlignment: CrossAxisAlignment.start,
color: Colors.blueGrey, mainAxisSize: MainAxisSize.min,
child: Text( children: <Widget>[
I18n.of(context).download(event.body), RaisedButton(
overflow: TextOverflow.fade, color: Colors.blueGrey,
softWrap: false, child: Text(
maxLines: 1, I18n.of(context).downloadFile,
style: TextStyle(color: Colors.white), overflow: TextOverflow.fade,
), softWrap: false,
onPressed: () => launch( maxLines: 1,
MxContent(event.content["url"]) style: TextStyle(color: Colors.white),
.getDownloadLink(Matrix.of(context).client), ),
), 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: case MessageTypes.BadEncrypted:

View File

@ -272,11 +272,7 @@ class I18n {
String get displaynameHasBeenChanged => String get displaynameHasBeenChanged =>
Intl.message("Displayname has been changed"); Intl.message("Displayname has been changed");
String download(String fileName) => Intl.message( String get downloadFile => Intl.message("Download file");
"Download $fileName",
name: "download",
args: [fileName],
);
String get editDisplayname => Intl.message("Edit displayname"); String get editDisplayname => Intl.message("Edit displayname");
@ -296,6 +292,10 @@ class I18n {
String get enterAUsername => Intl.message("Enter a username"); 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 fluffychat => Intl.message("FluffyChat");
String get forward => Intl.message('Forward'); String get forward => Intl.message('Forward');

View File

@ -260,4 +260,22 @@ extension LocalizedBody on Event {
return Icons.done; return Icons.done;
} }
} }
String get sizeString {
if (content["info"] is Map<String, dynamic> &&
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;
}
} }