Merge branch 'krille/fix-chat-list-item-context-menu' into 'master'

Fix chatlistitem context menu

See merge request ChristianPauly/fluffychat-flutter!127
This commit is contained in:
Christian Pauly 2020-08-03 11:19:51 +00:00
commit 269d38aa9b
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,13 +169,12 @@ class ChatListItem extends StatelessWidget {
),
],
actionPane: SlidableDrawerActionPane(),
dismissal: SlidableDismissal(
child: SlidableDrawerDismissal(),
onWillDismiss: (actionType) => archiveAction(context),
),
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>[
@ -154,21 +186,36 @@ class ChatListItem extends StatelessWidget {
softWrap: false,
),
),
SizedBox(width: 4),
room.pushRuleState == PushRuleState.notify
? Container()
: Icon(
room.isFavourite
? Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Icon(
Icons.favorite,
color: Colors.grey[400],
size: 16,
),
)
: Container(),
isMuted
? Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Icon(
Icons.notifications_off,
color: Colors.grey[400],
size: 16,
),
Text(
)
: Container(),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
room.timeCreated.localizedTimeShort(context),
style: TextStyle(
color: Color(0xFF555555),
fontSize: 13,
),
),
),
],
),
subtitle: Row(
@ -224,6 +271,7 @@ class ChatListItem extends StatelessWidget {
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: