refactor: Select chat list item logic

This commit is contained in:
Christian Pauly 2021-07-31 23:49:30 +02:00
parent 19fc1378fb
commit cd1f8cc386
1 changed files with 151 additions and 154 deletions

View File

@ -146,171 +146,168 @@ class ChatListItem extends StatelessWidget {
? 20.0 ? 20.0
: 14.0 : 14.0
: 0.0; : 0.0;
return Center( return ListTile(
child: Material( selected: selected,
color: FluffyThemes.chatListItemColor(context, activeChat, selected), selectedTileColor:
child: ListTile( FluffyThemes.chatListItemColor(context, activeChat, selected),
onLongPress: onLongPress, onLongPress: onLongPress,
leading: selected leading: selected
? Container( ? Container(
width: Avatar.defaultSize, width: Avatar.defaultSize,
height: Avatar.defaultSize, height: Avatar.defaultSize,
child: Material( child: Material(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(Avatar.defaultSize), borderRadius: BorderRadius.circular(Avatar.defaultSize),
child: Icon(Icons.check, color: Colors.white), child: Icon(Icons.check, color: Colors.white),
),
)
: Avatar(room.avatar, room.displayname, onTap: onLongPress),
title: Row(
children: <Widget>[
Expanded(
child: Text(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
),
), ),
if (isMuted) )
Padding( : Avatar(room.avatar, room.displayname, onTap: onLongPress),
padding: const EdgeInsets.only(left: 4.0), title: Row(
child: Icon( children: <Widget>[
Icons.notifications_off_outlined, Expanded(
size: 16, child: Text(
), room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
), maxLines: 1,
if (room.isFavourite) overflow: TextOverflow.ellipsis,
Padding( softWrap: false,
padding: EdgeInsets.only( ),
right: room.notificationCount > 0 ? 4.0 : 0.0),
child: Icon(
Icons.push_pin_outlined,
size: 16,
color: Theme.of(context).colorScheme.secondary,
),
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
room.timeCreated.localizedTimeShort(context),
style: TextStyle(
fontSize: 13,
color: room.notificationCount > 0
? Theme.of(context).colorScheme.secondary
: null,
),
),
),
],
), ),
subtitle: Row( if (isMuted)
mainAxisAlignment: MainAxisAlignment.center, Padding(
children: <Widget>[ padding: const EdgeInsets.only(left: 4.0),
if (typingText.isEmpty && ownMessage) ...{ child: Icon(
Icon( Icons.notifications_off_outlined,
room.lastEvent.statusIcon, size: 16,
size: 14,
),
SizedBox(width: 4),
},
AnimatedContainer(
width: typingText.isEmpty ? 0 : 18,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(),
duration: Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: EdgeInsets.only(right: 4),
child: Icon(
Icons.edit_outlined,
color: Theme.of(context).colorScheme.secondary,
size: 14,
),
), ),
if (typingText.isEmpty && ),
!ownMessage && if (room.isFavourite)
!room.isDirectChat && Padding(
room.lastEvent != null && padding: EdgeInsets.only(
room.lastEvent.type == EventTypes.Message && right: room.notificationCount > 0 ? 4.0 : 0.0),
{MessageTypes.Text, MessageTypes.Notice} child: Icon(
.contains(room.lastEvent.messageType)) Icons.push_pin_outlined,
Text( size: 16,
'${room.lastEvent.sender.calcDisplayname()}: ', color: Theme.of(context).colorScheme.secondary,
style: TextStyle( ),
color: Theme.of(context).textTheme.bodyText1.color, ),
), Padding(
), padding: const EdgeInsets.only(left: 4.0),
Expanded( child: Text(
child: typingText.isNotEmpty room.timeCreated.localizedTimeShort(context),
style: TextStyle(
fontSize: 13,
color: room.notificationCount > 0
? Theme.of(context).colorScheme.secondary
: null,
),
),
),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (typingText.isEmpty && ownMessage) ...{
Icon(
room.lastEvent.statusIcon,
size: 14,
),
SizedBox(width: 4),
},
AnimatedContainer(
width: typingText.isEmpty ? 0 : 18,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(),
duration: Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: EdgeInsets.only(right: 4),
child: Icon(
Icons.edit_outlined,
color: Theme.of(context).colorScheme.secondary,
size: 14,
),
),
if (typingText.isEmpty &&
!ownMessage &&
!room.isDirectChat &&
room.lastEvent != null &&
room.lastEvent.type == EventTypes.Message &&
{MessageTypes.Text, MessageTypes.Notice}
.contains(room.lastEvent.messageType))
Text(
'${room.lastEvent.sender.calcDisplayname()}: ',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
Expanded(
child: typingText.isNotEmpty
? Text(
typingText,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
softWrap: false,
)
: room.membership == Membership.invite
? Text( ? Text(
typingText, L10n.of(context).youAreInvitedToThisChat,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.secondary, color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
), ),
softWrap: false, softWrap: false,
) )
: room.membership == Membership.invite : Text(
? Text( room.lastEvent?.getLocalizedBody(
L10n.of(context).youAreInvitedToThisChat, MatrixLocals(L10n.of(context)),
style: TextStyle( hideReply: true,
color: Theme.of(context).colorScheme.secondary, ) ??
fontWeight: FontWeight.bold, '',
), softWrap: false,
softWrap: false, maxLines: 1,
) overflow: TextOverflow.ellipsis,
: Text( style: TextStyle(
room.lastEvent?.getLocalizedBody( color: room.isUnread
MatrixLocals(L10n.of(context)), ? Theme.of(context).colorScheme.secondary
hideReply: true, : null,
) ?? fontWeight: room.isUnread ? FontWeight.bold : null,
'', decoration: room.lastEvent?.redacted == true
softWrap: false, ? TextDecoration.lineThrough
maxLines: 1, : null,
overflow: TextOverflow.ellipsis, ),
style: TextStyle( ),
color: room.isUnread
? Theme.of(context).colorScheme.secondary
: null,
fontWeight:
room.isUnread ? FontWeight.bold : null,
decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
),
),
SizedBox(width: 8),
AnimatedContainer(
duration: Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width: room.notificationCount == 0 && !room.isUnread
? 0
: unreadBubbleSize,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Center(
child: room.notificationCount > 0
? Text(
room.notificationCount.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 13,
),
)
: Container(),
),
),
],
), ),
onTap: () => clickAction(context), SizedBox(width: 8),
), AnimatedContainer(
duration: Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width: room.notificationCount == 0 && !room.isUnread
? 0
: unreadBubbleSize,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Center(
child: room.notificationCount > 0
? Text(
room.notificationCount.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 13,
),
)
: Container(),
),
),
],
), ),
onTap: () => clickAction(context),
); );
} }
} }