Design improvements

This commit is contained in:
Christian Pauly 2020-05-15 17:57:53 +00:00
commit ec9e8fe5d4
10 changed files with 278 additions and 159 deletions

View file

@ -0,0 +1,72 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
import 'package:fluffychat/utils/presence_extension.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceDialog extends StatelessWidget {
final Uri avatarUrl;
final String displayname;
final Presence presence;
const PresenceDialog(
this.presence, {
this.avatarUrl,
this.displayname,
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: ListTile(
contentPadding: EdgeInsets.zero,
leading: Avatar(avatarUrl, displayname),
title: Text(displayname),
subtitle: Text(presence.sender),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)),
if (presence.presence != null)
Text(
presence.presence.toString().split('.').last,
style: TextStyle(
color: presence.currentlyActive == true
? Colors.green
: Theme.of(context).primaryColor,
),
)
],
),
actions: <Widget>[
if (presence.sender != Matrix.of(context).client.userID)
FlatButton(
child: Text(L10n.of(context).sendAMessage),
onPressed: () async {
final roomId = await User(
presence.sender,
room: Room(id: '', client: Matrix.of(context).client),
).startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
},
),
FlatButton(
child: Text(L10n.of(context).close),
onPressed: () => Navigator.of(context).pop(),
),
],
);
}
}

View file

@ -9,6 +9,7 @@ import 'package:fluffychat/utils/event_extension.dart';
import 'package:fluffychat/utils/string_color.dart';
import 'package:flutter/material.dart';
import '../adaptive_page_layout.dart';
import '../avatar.dart';
import '../matrix.dart';
import 'state_message.dart';
@ -74,74 +75,78 @@ class Message extends StatelessWidget {
margin: BubbleEdges.symmetric(horizontal: 4),
color: color,
nip: nip,
child: Stack(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (event.isReply)
FutureBuilder<Event>(
future: event.getReplyEvent(timeline),
builder: (BuildContext context, snapshot) {
final replyEvent = snapshot.hasData
? snapshot.data
: Event(
eventId: event.content['m.relates_to']
['m.in_reply_to']['event_id'],
content: {'msgtype': 'm.text', 'body': '...'},
senderId: event.senderId,
typeKey: 'm.room.message',
room: event.room,
roomId: event.roomId,
status: 1,
time: DateTime.now(),
);
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0),
child:
ReplyContent(replyEvent, lightText: ownMessage),
);
},
),
MessageContent(
event,
textColor: textColor,
),
if (event.type == EventTypes.Encrypted &&
event.messageType == MessageTypes.BadEncrypted &&
event.content['body'] == DecryptError.UNKNOWN_SESSION)
RaisedButton(
color: color.withAlpha(100),
child: Text(
L10n.of(context).requestPermission,
style: TextStyle(color: textColor),
child: Container(
constraints:
BoxConstraints(maxWidth: AdaptivePageLayout.defaultMinWidth),
child: Stack(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (event.isReply)
FutureBuilder<Event>(
future: event.getReplyEvent(timeline),
builder: (BuildContext context, snapshot) {
final replyEvent = snapshot.hasData
? snapshot.data
: Event(
eventId: event.content['m.relates_to']
['m.in_reply_to']['event_id'],
content: {'msgtype': 'm.text', 'body': '...'},
senderId: event.senderId,
typeKey: 'm.room.message',
room: event.room,
roomId: event.roomId,
status: 1,
time: DateTime.now(),
);
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0),
child:
ReplyContent(replyEvent, lightText: ownMessage),
);
},
),
onPressed: () => SimpleDialogs(context)
.tryRequestWithLoadingDialog(event.requestKey()),
),
SizedBox(height: 4),
Opacity(
opacity: 0,
child: _MetaRow(
MessageContent(
event,
ownMessage,
textColor,
textColor: textColor,
),
),
],
),
Positioned(
bottom: 0,
right: ownMessage ? 0 : null,
left: !ownMessage ? 0 : null,
child: _MetaRow(
event,
ownMessage,
textColor,
if (event.type == EventTypes.Encrypted &&
event.messageType == MessageTypes.BadEncrypted &&
event.content['body'] == DecryptError.UNKNOWN_SESSION)
RaisedButton(
color: color.withAlpha(100),
child: Text(
L10n.of(context).requestPermission,
style: TextStyle(color: textColor),
),
onPressed: () => SimpleDialogs(context)
.tryRequestWithLoadingDialog(event.requestKey()),
),
SizedBox(height: 4),
Opacity(
opacity: 0,
child: _MetaRow(
event,
ownMessage,
textColor,
),
),
],
),
),
],
Positioned(
bottom: 0,
right: ownMessage ? 0 : null,
left: !ownMessage ? 0 : null,
child: _MetaRow(
event,
ownMessage,
textColor,
),
),
],
),
),
),
),

View file

@ -1,12 +1,9 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
import '../matrix.dart';
import 'package:fluffychat/utils/presence_extension.dart';
class PresenceListItem extends StatelessWidget {
final Presence presence;
@ -36,68 +33,27 @@ class PresenceListItem extends StatelessWidget {
return InkWell(
onTap: () => showDialog(
context: context,
builder: (c) => AlertDialog(
title: ListTile(
contentPadding: EdgeInsets.zero,
leading: Avatar(avatarUrl, displayname),
title: Text(displayname),
subtitle: Text(presence.sender),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
builder: (c) => PresenceDialog(
presence,
avatarUrl: avatarUrl,
displayname: displayname,
),
child: Container(
width: 80,
child: Column(
children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)),
if (presence.presence != null)
Text(
presence.presence.toString().split('.').last,
style: TextStyle(
color: presence.currentlyActive == true
? Colors.green
: Theme.of(context).primaryColor,
),
)
SizedBox(height: 9),
Avatar(avatarUrl, displayname),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
displayname,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
actions: <Widget>[
if (presence.sender != Matrix.of(context).client.userID)
FlatButton(
child: Text(L10n.of(context).sendAMessage),
onPressed: () async {
final roomId = await User(
presence.sender,
room: Room(id: '', client: Matrix.of(context).client),
).startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
},
),
FlatButton(
child: Text(L10n.of(context).close),
onPressed: () => Navigator.of(context).pop(),
),
],
),
),
child: Container(
width: 80,
child: Column(
children: <Widget>[
SizedBox(height: 9),
Avatar(avatarUrl, displayname),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
displayname,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
);