diff --git a/lib/forez/ui/routes/forez_route.dart b/lib/forez/ui/routes/forez_route.dart index b955b91..a01fdba 100644 --- a/lib/forez/ui/routes/forez_route.dart +++ b/lib/forez/ui/routes/forez_route.dart @@ -1,4 +1,5 @@ import 'package:comunic/forez/helpers/forez_group_helper.dart'; +import 'package:comunic/forez/ui/screens/forez_directory_screen.dart'; import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/dialogs/alert_dialog.dart'; @@ -150,7 +151,7 @@ class _ForezRouteBodyState extends SafeState { _Tab( icon: Icons.import_contacts, title: tr("Directory"), - widget: () => Text("Directory"), + widget: () => ForezDirectoryScreen(), ), ]; diff --git a/lib/forez/ui/screens/forez_directory_screen.dart b/lib/forez/ui/screens/forez_directory_screen.dart new file mode 100644 index 0000000..0f709bd --- /dev/null +++ b/lib/forez/ui/screens/forez_directory_screen.dart @@ -0,0 +1,52 @@ +import 'package:comunic/forez/helpers/forez_group_helper.dart'; +import 'package:comunic/helpers/groups_helper.dart'; +import 'package:comunic/helpers/users_helper.dart'; +import 'package:comunic/lists/group_members_list.dart'; +import 'package:comunic/lists/users_list.dart'; +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/intl_utils.dart'; +import 'package:flutter/material.dart'; + +/// Forez directory screen +/// +/// @author Pierre Hubert + +class ForezDirectoryScreen extends StatefulWidget { + @override + _ForezDirectoryScreenState createState() => _ForezDirectoryScreenState(); +} + +class _ForezDirectoryScreenState extends State { + final _key = GlobalKey(); + + UsersList _users; + GroupMembersList _members; + + Future _load() async { + _members = await GroupsHelper.getMembersList(forezGroup.id); + _users = await UsersHelper().getListWithThrow(_members.usersID); + } + + @override + Widget build(BuildContext context) => AsyncScreenWidget( + onReload: _load, + onBuild: onBuild, + errorMessage: tr("Failed to load members list!"), + key: _key, + ); + + Widget onBuild() => ListView.builder( + itemBuilder: (c, i) => + _buildMember(_members[i], _users.getUser(_members[i].userID)), + itemCount: _members.length, + ); + + Widget _buildMember(GroupMembership membership, User user) => ListTile( + leading: AccountImageWidget(user: user), + title: Text(user.fullName), + subtitle: Text(membership.membershipText), + ); +} diff --git a/lib/models/group.dart b/lib/models/group.dart index 15967cf..07c6973 100644 --- a/lib/models/group.dart +++ b/lib/models/group.dart @@ -14,6 +14,24 @@ enum GroupMembershipLevel { VISITOR } +String membershipToText(GroupMembershipLevel level) { + switch (level) { + case GroupMembershipLevel.ADMINISTRATOR: + return tr("Administrator"); + case GroupMembershipLevel.MODERATOR: + return tr("Moderator"); + case GroupMembershipLevel.MEMBER: + return tr("Member"); + case GroupMembershipLevel.INVITED: + return tr("Invited"); + case GroupMembershipLevel.PENDING: + return tr("Requested"); + case GroupMembershipLevel.VISITOR: + return tr("Visitor"); + } + throw new Exception("Unreachable statement!"); +} + enum GroupVisibilityLevel { OPEN, PRIVATE, SECRETE } enum GroupRegistrationLevel { OPEN, MODERATED, CLOSED } @@ -72,24 +90,7 @@ class Group implements Comparable { (membershipLevel == GroupMembershipLevel.MEMBER && postCreationLevel == GroupPostCreationLevel.MEMBERS); - String get membershipText { - switch (membershipLevel) { - case GroupMembershipLevel.ADMINISTRATOR: - return tr("Administrator"); - case GroupMembershipLevel.MODERATOR: - return tr("Moderator"); - case GroupMembershipLevel.MEMBER: - return tr("Member"); - case GroupMembershipLevel.INVITED: - return tr("Invited"); - case GroupMembershipLevel.PENDING: - return tr("Requested"); - case GroupMembershipLevel.VISITOR: - return tr("Visitor"); - } - - throw new Exception("Unreachable statement!"); - } + String get membershipText => membershipToText(membershipLevel); @override int compareTo(Group other) => id.compareTo(other.id); diff --git a/lib/models/group_membership.dart b/lib/models/group_membership.dart index 58abe46..e5adbc3 100644 --- a/lib/models/group_membership.dart +++ b/lib/models/group_membership.dart @@ -20,4 +20,6 @@ class GroupMembership { assert(groupID != null), assert(timeCreate != null), assert(level != null); + + String get membershipText => membershipToText(level); }