From 2fc85e0fe3a6817ce6558fb5e2dd576034bc70c2 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 3 Aug 2020 13:08:44 +0200 Subject: [PATCH] Fix chatlistitem context menu --- CHANGELOG.md | 2 + lib/components/list_items/chat_list_item.dart | 210 +++++++++++------- lib/l10n/l10n.dart | 4 + pubspec.lock | 33 +-- 4 files changed, 155 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2105102..29e5f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 7d54815..9556a49 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -92,6 +92,18 @@ class ChatListItem extends StatelessWidget { } } + Future _toggleFavouriteRoom(BuildContext context) => + SimpleDialogs(context).tryRequestWithLoadingDialog( + room.setFavourite(!room.isFavourite), + ); + + Future _toggleMuted(BuildContext context) => + SimpleDialogs(context).tryRequestWithLoadingDialog( + room.setPushRuleState(room.pushRuleState == PushRuleState.notify + ? PushRuleState.mentions_only + : PushRuleState.notify), + ); + Future 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: [ + 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: [ - 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: [ + 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: [ - 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: [ + 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), ), ), ); diff --git a/lib/l10n/l10n.dart b/lib/l10n/l10n.dart index a9486ab..78a6925 100644 --- a/lib/l10n/l10n.dart +++ b/lib/l10n/l10n.dart @@ -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", diff --git a/pubspec.lock b/pubspec.lock index f83801f..3a82b5e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: