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,23 +34,21 @@ 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) {
@ -95,26 +93,28 @@ class ChatListItem extends StatelessWidget {
} }
if (room.membership == Membership.join) { if (room.membership == Membership.join) {
if (Matrix.of(context).shareContent != null) { // Share content into this room
if (Matrix.of(context).shareContent!['msgtype'] == final shareContent = Matrix.of(context).shareContent;
if (shareContent != null) {
if (shareContent.tryGet<String>('msgtype') ==
'chat.fluffy.shared_file') { 'chat.fluffy.shared_file') {
await showDialog( await showDialog(
context: context, context: context,
useRootNavigator: false, useRootNavigator: false,
builder: (c) => SendFileDialog( builder: (c) => SendFileDialog(
files: [Matrix.of(context).shareContent!['file']], files: shareContent['file'],
room: room, room: room,
), ),
); );
} else { } else {
room.sendEvent(Matrix.of(context).shareContent!); room.sendEvent(shareContent);
} }
Matrix.of(context).shareContent = null; Matrix.of(context).shareContent = null;
} }
VRouter.of(context).toSegments(['rooms', room.id]); VRouter.of(context).toSegments(['rooms', room.id]);
} }
} }
}
Future<void> archiveAction(BuildContext context) async { Future<void> archiveAction(BuildContext context) async {
{ {
@ -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),