diff --git a/lib/forez/ui/screens/forez_directory_screen.dart b/lib/forez/ui/screens/forez_directory_screen.dart index 0f709bd..3926961 100644 --- a/lib/forez/ui/screens/forez_directory_screen.dart +++ b/lib/forez/ui/screens/forez_directory_screen.dart @@ -7,6 +7,8 @@ import 'package:comunic/models/group_membership.dart'; import 'package:comunic/models/user.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; +import 'package:comunic/utils/account_utils.dart'; +import 'package:comunic/utils/conversations_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -14,6 +16,8 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert +enum _PopupMenuActions { PRIVATE_CONVERSATION } + class ForezDirectoryScreen extends StatefulWidget { @override _ForezDirectoryScreenState createState() => _ForezDirectoryScreenState(); @@ -39,14 +43,52 @@ class _ForezDirectoryScreenState extends State { ); Widget onBuild() => ListView.builder( - itemBuilder: (c, i) => - _buildMember(_members[i], _users.getUser(_members[i].userID)), + itemBuilder: (c, i) => _ForezMemberTile( + member: _members[i], + user: _users.getUser(_members[i].userID), + selectedAction: _doPopupMenuAction, + ), itemCount: _members.length, ); - Widget _buildMember(GroupMembership membership, User user) => ListTile( + void _doPopupMenuAction(_PopupMenuActions action, User user) async { + switch (action) { + case _PopupMenuActions.PRIVATE_CONVERSATION: + openPrivateConversation(context, user.id); + break; + } + } +} + +class _ForezMemberTile extends StatelessWidget { + final User user; + final GroupMembership member; + final Function(_PopupMenuActions, User) selectedAction; + + const _ForezMemberTile({ + Key key, + @required this.user, + @required this.member, + @required this.selectedAction, + }) : super(key: key); + + @override + Widget build(BuildContext context) => ListTile( leading: AccountImageWidget(user: user), title: Text(user.fullName), - subtitle: Text(membership.membershipText), + subtitle: Text(member.membershipText), + trailing: user.id == userID() + ? null + : PopupMenuButton( + itemBuilder: (c) => popupMenuItems, + onSelected: (a) => selectedAction(a, user), + ), ); + + List> get popupMenuItems => [ + PopupMenuItem( + child: Text(tr("Private conversation")), + value: _PopupMenuActions.PRIVATE_CONVERSATION, + ), + ]; }