chore: Better design chat list items

This commit is contained in:
Christian Pauly 2022-10-15 09:23:17 +02:00
parent 376d5704fa
commit b4bf23cd34

View File

@ -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,
future: () async {
final joinedFuture = room.client.onSync.stream
.where((u) =>
u.rooms?.join?.containsKey(room.id) ?? false)
.first;
await room.join();
await joinedFuture;
}))
.error !=
null) {
return;
}
if (room.membership == Membership.ban) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(L10n.of(context)!.youHaveBeenBannedFromThisChat),
),
);
return;
}
if (room.membership == Membership.leave) {
final action = await showModalActionSheet<ArchivedRoomAction>(
context: context, context: context,
title: L10n.of(context)!.archivedRoom, future: () async {
message: L10n.of(context)!.thisRoomHasBeenArchived, final waitForRoom = room.client.waitForRoomInSync(
actions: [ room.id,
SheetAction( join: true,
label: L10n.of(context)!.rejoin, );
key: ArchivedRoomAction.rejoin, await room.join();
), await waitForRoom;
SheetAction( });
label: L10n.of(context)!.delete, if (joinResult.error != null) return;
key: ArchivedRoomAction.delete, }
isDestructiveAction: true,
), if (room.membership == Membership.ban) {
], ScaffoldMessenger.of(context).showSnackBar(
); SnackBar(
if (action != null) { content: Text(L10n.of(context)!.youHaveBeenBannedFromThisChat),
switch (action) { ),
case ArchivedRoomAction.delete: );
await archiveAction(context); return;
break; }
case ArchivedRoomAction.rejoin:
await showFutureLoadingDialog( if (room.membership == Membership.leave) {
context: context, final action = await showModalActionSheet<ArchivedRoomAction>(
future: () => room.join(), context: context,
); title: L10n.of(context)!.archivedRoom,
break; message: L10n.of(context)!.thisRoomHasBeenArchived,
} actions: [
SheetAction(
label: L10n.of(context)!.rejoin,
key: ArchivedRoomAction.rejoin,
),
SheetAction(
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.join) {
// Share content into this room
final shareContent = Matrix.of(context).shareContent;
if (shareContent != null) {
if (shareContent.tryGet<String>('msgtype') ==
'chat.fluffy.shared_file') {
await showDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
files: shareContent['file'],
room: room,
),
);
} else {
room.sendEvent(shareContent);
}
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),