chore: Better design chat list items

krille/redesign-login
Christian Pauly 3 years ago
parent e744e7eef1
commit 361f8385a9

@ -21,8 +21,8 @@ class ChatListItem extends StatelessWidget {
final bool activeChat; final bool activeChat;
final bool selected; final bool selected;
final Function? onForget; final Function? onForget;
final Function? onTap; final void Function()? onTap;
final Function? onLongPress; final void Function()? onLongPress;
const ChatListItem( const ChatListItem(
this.room, { this.room, {
@ -34,85 +34,85 @@ class ChatListItem extends StatelessWidget {
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
dynamic clickAction(BuildContext context) async { void clickAction(BuildContext context) async {
if (onTap != null) return onTap!(); if (onTap != null) return onTap!();
if (!activeChat) { if (activeChat) return;
if (room.membership == Membership.invite && if (room.membership == Membership.invite) {
(await showFutureLoadingDialog( final joinResult = await showFutureLoadingDialog(
context: context, context: context,
future: () async { future: () async {
final joinedFuture = room.client.onSync.stream final waitForRoom = room.client.waitForRoomInSync(
.where((u) => room.id,
u.rooms?.join?.containsKey(room.id) ?? false) join: true,
.first; );
await room.join(); await room.join();
await joinedFuture; await waitForRoom;
})) });
.error != if (joinResult.error != null) return;
null) { }
return;
}
if (room.membership == Membership.ban) { if (room.membership == Membership.ban) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text(L10n.of(context)!.youHaveBeenBannedFromThisChat), content: Text(L10n.of(context)!.youHaveBeenBannedFromThisChat),
),
);
return;
}
if (room.membership == Membership.leave) {
final action = await showModalActionSheet<ArchivedRoomAction>(
context: context,
title: L10n.of(context)!.archivedRoom,
message: L10n.of(context)!.thisRoomHasBeenArchived,
actions: [
SheetAction(
label: L10n.of(context)!.rejoin,
key: ArchivedRoomAction.rejoin,
), ),
); SheetAction(
return; label: L10n.of(context)!.delete,
key: ArchivedRoomAction.delete,
isDestructiveAction: true,
),
],
);
if (action != null) {
switch (action) {
case ArchivedRoomAction.delete:
await archiveAction(context);
break;
case ArchivedRoomAction.rejoin:
await showFutureLoadingDialog(
context: context,
future: () => room.join(),
);
break;
}
} }
}
if (room.membership == Membership.leave) { if (room.membership == Membership.join) {
final action = await showModalActionSheet<ArchivedRoomAction>( // Share content into this room
context: context, final shareContent = Matrix.of(context).shareContent;
title: L10n.of(context)!.archivedRoom, if (shareContent != null) {
message: L10n.of(context)!.thisRoomHasBeenArchived, if (shareContent.tryGet<String>('msgtype') ==
actions: [ 'chat.fluffy.shared_file') {
SheetAction( await showDialog(
label: L10n.of(context)!.rejoin, context: context,
key: ArchivedRoomAction.rejoin, useRootNavigator: false,
), builder: (c) => SendFileDialog(
SheetAction( files: shareContent['file'],
label: L10n.of(context)!.delete, room: room,
key: ArchivedRoomAction.delete,
isDestructiveAction: true,
), ),
], );
); } else {
if (action != null) { room.sendEvent(shareContent);
switch (action) {
case ArchivedRoomAction.delete:
await archiveAction(context);
break;
case ArchivedRoomAction.rejoin:
await showFutureLoadingDialog(
context: context,
future: () => room.join(),
);
break;
}
} }
Matrix.of(context).shareContent = null;
} }
if (room.membership == Membership.join) { VRouter.of(context).toSegments(['rooms', room.id]);
if (Matrix.of(context).shareContent != null) {
if (Matrix.of(context).shareContent!['msgtype'] ==
'chat.fluffy.shared_file') {
await showDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
files: [Matrix.of(context).shareContent!['file']],
room: room,
),
);
} else {
room.sendEvent(Matrix.of(context).shareContent!);
}
Matrix.of(context).shareContent = null;
}
VRouter.of(context).toSegments(['rooms', room.id]);
}
} }
} }
@ -162,7 +162,7 @@ class ChatListItem extends StatelessWidget {
: Colors.transparent, : Colors.transparent,
child: ListTile( child: ListTile(
selected: selected || activeChat, selected: selected || activeChat,
onLongPress: onLongPress as void Function()?, onLongPress: onLongPress,
leading: selected leading: selected
? SizedBox( ? SizedBox(
width: Avatar.defaultSize, width: Avatar.defaultSize,
@ -176,7 +176,7 @@ class ChatListItem extends StatelessWidget {
: Avatar( : Avatar(
mxContent: room.avatar, mxContent: room.avatar,
name: room.displayname, name: room.displayname,
onTap: onLongPress as void Function()?, onTap: onLongPress,
), ),
title: Row( title: Row(
children: <Widget>[ children: <Widget>[
@ -187,10 +187,7 @@ class ChatListItem extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
softWrap: false, softWrap: false,
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: unread ? FontWeight.bold : null,
color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText1!.color,
), ),
), ),
), ),
@ -257,8 +254,9 @@ class ChatListItem extends StatelessWidget {
? Text( ? Text(
typingText, typingText,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.secondary, color: Theme.of(context).colorScheme.primary,
), ),
maxLines: 1,
softWrap: false, softWrap: false,
) )
: FutureBuilder<String>( : FutureBuilder<String>(
@ -293,9 +291,8 @@ class ChatListItem extends StatelessWidget {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
color: unread fontWeight: unread ? FontWeight.w600 : null,
? Theme.of(context).colorScheme.secondary color: Theme.of(context).colorScheme.onBackground,
: Theme.of(context).textTheme.bodyText2!.color,
decoration: room.lastEvent?.redacted == true decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough ? TextDecoration.lineThrough
: null, : null,
@ -316,9 +313,10 @@ class ChatListItem extends StatelessWidget {
room.notificationCount.toString().length + room.notificationCount.toString().length +
9, 9,
decoration: BoxDecoration( decoration: BoxDecoration(
color: room.highlightCount > 0 color: room.highlightCount > 0 ||
room.membership == Membership.invite
? Colors.red ? Colors.red
: room.notificationCount > 0 : room.notificationCount > 0 || room.markedUnread
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.primaryContainer, : Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(AppConfig.borderRadius), borderRadius: BorderRadius.circular(AppConfig.borderRadius),

Loading…
Cancel
Save