Add image viewer

This commit is contained in:
Christian Pauly 2020-01-03 09:20:30 +01:00
parent 3099520239
commit 55ce5dd28e
4 changed files with 28 additions and 15 deletions

View file

@ -1,6 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/message_content.dart'; import 'package:fluffychat/components/message_content.dart';
import 'package:fluffychat/utils/ChatTime.dart'; import 'package:fluffychat/utils/chat_time.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';

View file

@ -2,7 +2,7 @@ import 'package:bubble/bubble.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/redact_message_dialog.dart'; import 'package:fluffychat/components/dialogs/redact_message_dialog.dart';
import 'package:fluffychat/components/message_content.dart'; import 'package:fluffychat/components/message_content.dart';
import 'package:fluffychat/utils/ChatTime.dart'; import 'package:fluffychat/utils/chat_time.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../avatar.dart'; import '../avatar.dart';

View file

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:bubble/bubble.dart'; import 'package:bubble/bubble.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
@ -19,8 +17,19 @@ class MessageContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final int maxLines = textOnly ? 1 : null; final int maxLines = textOnly ? 1 : null;
switch (event.type) { switch (event.type) {
case EventTypes.Image: case EventTypes.Image:
if (textOnly) {
return Text(
"${event.sender.calcDisplayname()} has sent an image",
maxLines: maxLines,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
}
final int size = 400; final int size = 400;
final String src = MxContent(event.content["url"]).getThumbnail( final String src = MxContent(event.content["url"]).getThumbnail(
Matrix.of(context).client, Matrix.of(context).client,
@ -30,7 +39,7 @@ class MessageContent extends StatelessWidget {
); );
return Bubble( return Bubble(
padding: BubbleEdges.all(0), padding: BubbleEdges.all(0),
radius: Radius.circular(50), radius: Radius.circular(10),
elevation: 0, elevation: 0,
child: InkWell( child: InkWell(
onTap: () => launch( onTap: () => launch(
@ -70,8 +79,12 @@ class MessageContent extends StatelessWidget {
case EventTypes.Text: case EventTypes.Text:
case EventTypes.Reply: case EventTypes.Reply:
case EventTypes.Notice: case EventTypes.Notice:
String senderPrefix = event.senderId == Matrix.of(context).client.userID
? "You: "
: "${event.sender.calcDisplayname()}: ";
return Text( return Text(
event.getBody(), senderPrefix + event.getBody(),
maxLines: maxLines,
style: TextStyle( style: TextStyle(
color: textColor, color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null, decoration: event.redacted ? TextDecoration.lineThrough : null,

View file

@ -56,24 +56,24 @@ class ChatTime {
} else if (sameWeek) { } else if (sameWeek) {
switch (dateTime.weekday) { switch (dateTime.weekday) {
case 1: case 1:
return "Montag"; return "Monday";
case 2: case 2:
return "Dienstag"; return "Tuesday";
case 3: case 3:
return "Mittwoch"; return "Wednesday";
case 4: case 4:
return "Donnerstag"; return "Donnerstag";
case 5: case 5:
return "Freitag"; return "Thursday";
case 6: case 6:
return "Samstag"; return "Saturday";
case 7: case 7:
return "Sonntag"; return "Sunday";
} }
} else if (sameYear) { } else if (sameYear) {
return "${_z(dateTime.day)}.${_z(dateTime.month)}"; return "${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')}";
} }
return "${_z(dateTime.day)}.${_z(dateTime.month)}.${_z(dateTime.year)}"; return "${dateTime.year.toString()}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')}";
} }
/// Returns the milliseconds since the Unix epoch. /// Returns the milliseconds since the Unix epoch.
@ -111,7 +111,7 @@ class ChatTime {
/// Returns a simple time String. /// Returns a simple time String.
String toTimeString() { String toTimeString() {
return "${_z(dateTime.hour)}:${_z(dateTime.minute)}"; return "${_z(dateTime.hour % 12)}:${_z(dateTime.minute)} ${dateTime.hour > 11 ? 'pm' : 'am'}";
} }
/// If the ChatTime is today, this returns [toTimeString()], if not it also /// If the ChatTime is today, this returns [toTimeString()], if not it also