Fix chatlistitem context menu

This commit is contained in:
Christian Pauly 2020-08-03 13:08:44 +02:00
parent 05609314b8
commit 2fc85e0fe3
4 changed files with 155 additions and 94 deletions

View File

@ -1,4 +1,6 @@
# Version 0.17.0 - 2020-08-??
### Features:
- Pin and unpin chats
### Fixes:
- Don't re-render the room list nearly as often, increasing performance

View File

@ -92,6 +92,18 @@ class ChatListItem extends StatelessWidget {
}
}
Future<void> _toggleFavouriteRoom(BuildContext context) =>
SimpleDialogs(context).tryRequestWithLoadingDialog(
room.setFavourite(!room.isFavourite),
);
Future<void> _toggleMuted(BuildContext context) =>
SimpleDialogs(context).tryRequestWithLoadingDialog(
room.setPushRuleState(room.pushRuleState == PushRuleState.notify
? PushRuleState.mentions_only
: PushRuleState.notify),
);
Future<bool> archiveAction(BuildContext context) async {
{
if ([Membership.leave, Membership.ban].contains(room.membership)) {
@ -117,9 +129,30 @@ class ChatListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMuted = room.pushRuleState == PushRuleState.notify;
final slideableKey = GlobalKey();
return Slidable(
key: Key(room.id),
key: slideableKey,
secondaryActions: <Widget>[
if ([Membership.join, Membership.invite].contains(room.membership))
IconSlideAction(
caption: isMuted
? L10n.of(context).unmuteChat
: L10n.of(context).muteChat,
color: Colors.blueGrey,
icon:
isMuted ? Icons.notifications_active : Icons.notifications_off,
onTap: () => _toggleMuted(context),
),
if ([Membership.join, Membership.invite].contains(room.membership))
IconSlideAction(
caption: room.isFavourite
? L10n.of(context).unpin
: L10n.of(context).pin,
color: Colors.blue,
icon: room.isFavourite ? Icons.favorite_border : Icons.favorite,
onTap: () => _toggleFavouriteRoom(context),
),
if ([Membership.join, Membership.invite].contains(room.membership))
IconSlideAction(
caption: L10n.of(context).leave,
@ -136,92 +169,107 @@ class ChatListItem extends StatelessWidget {
),
],
actionPane: SlidableDrawerActionPane(),
dismissal: SlidableDismissal(
child: SlidableDrawerDismissal(),
onWillDismiss: (actionType) => archiveAction(context),
),
child: Material(
color: chatListItemColor(context, activeChat),
child: ListTile(
leading: Avatar(room.avatar, room.displayname),
title: Row(
children: <Widget>[
Expanded(
child: Text(
room.getLocalizedDisplayname(L10n.of(context)),
maxLines: 1,
overflow: TextOverflow.fade,
softWrap: false,
child: Center(
child: Material(
color: chatListItemColor(context, activeChat),
child: ListTile(
onLongPress: () => (slideableKey.currentState as SlidableState)
.open(actionType: SlideActionType.secondary),
leading: Avatar(room.avatar, room.displayname),
title: Row(
children: <Widget>[
Expanded(
child: Text(
room.getLocalizedDisplayname(L10n.of(context)),
maxLines: 1,
overflow: TextOverflow.fade,
softWrap: false,
),
),
),
SizedBox(width: 4),
room.pushRuleState == PushRuleState.notify
? Container()
: Icon(
Icons.notifications_off,
color: Colors.grey[400],
size: 16,
),
Text(
room.timeCreated.localizedTimeShort(context),
style: TextStyle(
color: Color(0xFF555555),
fontSize: 13,
),
),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: room.membership == Membership.invite
? Text(
L10n.of(context).youAreInvitedToThisChat,
style: TextStyle(
color: Theme.of(context).primaryColor,
room.isFavourite
? Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Icon(
Icons.favorite,
color: Colors.grey[400],
size: 16,
),
softWrap: false,
)
: Text(
room.lastEvent?.getLocalizedBody(
L10n.of(context),
withSenderNamePrefix: !room.isDirectChat,
hideReply: true,
) ??
'',
softWrap: false,
maxLines: 1,
overflow: TextOverflow.fade,
style: TextStyle(
decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
: Container(),
isMuted
? Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Icon(
Icons.notifications_off,
color: Colors.grey[400],
size: 16,
),
),
),
SizedBox(width: 8),
room.notificationCount > 0
? Container(
padding: EdgeInsets.symmetric(horizontal: 5),
height: 20,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
)
: Container(),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
room.timeCreated.localizedTimeShort(context),
style: TextStyle(
color: Color(0xFF555555),
fontSize: 13,
),
),
),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: room.membership == Membership.invite
? Text(
L10n.of(context).youAreInvitedToThisChat,
style: TextStyle(
color: Theme.of(context).primaryColor,
),
softWrap: false,
)
: Text(
room.lastEvent?.getLocalizedBody(
L10n.of(context),
withSenderNamePrefix: !room.isDirectChat,
hideReply: true,
) ??
'',
softWrap: false,
maxLines: 1,
overflow: TextOverflow.fade,
style: TextStyle(
decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
),
),
)
: Text(' '),
],
),
SizedBox(width: 8),
room.notificationCount > 0
? Container(
padding: EdgeInsets.symmetric(horizontal: 5),
height: 20,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
),
),
)
: Text(' '),
],
),
onTap: () => clickAction(context),
),
onTap: () => clickAction(context),
),
),
);

View File

@ -617,6 +617,8 @@ class L10n extends MatrixLocalizations {
String get pickImage => Intl.message('Pick image');
String get pin => Intl.message('Pin');
String play(String fileName) => Intl.message(
"Play $fileName",
name: "play",
@ -848,6 +850,8 @@ class L10n extends MatrixLocalizations {
args: [type],
);
String get unpin => Intl.message('Unpin');
String unreadChats(String unreadCount) => Intl.message(
"$unreadCount unread chats",
name: "unreadChats",

View File

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "6.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.39.4"
version: "0.39.15"
archive:
dependency: transitive
description:
@ -85,6 +85,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
clock:
dependency: transitive
description:
@ -148,13 +155,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
famedlysdk:
dependency: "direct main"
description:
@ -547,7 +547,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.6.4"
path_drawing:
dependency: transitive
description:
@ -625,6 +625,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
random_string:
dependency: "direct main"
description:
@ -748,21 +755,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.7"
version: "1.14.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.16"
version: "0.2.15"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.7"
version: "0.3.4"
typed_data:
dependency: transitive
description: