1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Start to build Directory pane

This commit is contained in:
Pierre HUBERT 2021-04-25 17:06:28 +02:00
parent ecd11fbf29
commit c04f85c40b
4 changed files with 75 additions and 19 deletions

View File

@ -1,4 +1,5 @@
import 'package:comunic/forez/helpers/forez_group_helper.dart'; 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/helpers/events_helper.dart';
import 'package:comunic/models/conversation.dart'; import 'package:comunic/models/conversation.dart';
import 'package:comunic/ui/dialogs/alert_dialog.dart'; import 'package:comunic/ui/dialogs/alert_dialog.dart';
@ -150,7 +151,7 @@ class _ForezRouteBodyState extends SafeState<ForezRouteBody> {
_Tab( _Tab(
icon: Icons.import_contacts, icon: Icons.import_contacts,
title: tr("Directory"), title: tr("Directory"),
widget: () => Text("Directory"), widget: () => ForezDirectoryScreen(),
), ),
]; ];

View File

@ -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<ForezDirectoryScreen> {
final _key = GlobalKey<AsyncScreenWidgetState>();
UsersList _users;
GroupMembersList _members;
Future<void> _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),
);
}

View File

@ -14,6 +14,24 @@ enum GroupMembershipLevel {
VISITOR 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 GroupVisibilityLevel { OPEN, PRIVATE, SECRETE }
enum GroupRegistrationLevel { OPEN, MODERATED, CLOSED } enum GroupRegistrationLevel { OPEN, MODERATED, CLOSED }
@ -72,24 +90,7 @@ class Group implements Comparable<Group> {
(membershipLevel == GroupMembershipLevel.MEMBER && (membershipLevel == GroupMembershipLevel.MEMBER &&
postCreationLevel == GroupPostCreationLevel.MEMBERS); postCreationLevel == GroupPostCreationLevel.MEMBERS);
String get membershipText { String get membershipText => membershipToText(membershipLevel);
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!");
}
@override @override
int compareTo(Group other) => id.compareTo(other.id); int compareTo(Group other) => id.compareTo(other.id);

View File

@ -20,4 +20,6 @@ class GroupMembership {
assert(groupID != null), assert(groupID != null),
assert(timeCreate != null), assert(timeCreate != null),
assert(level != null); assert(level != null);
String get membershipText => membershipToText(level);
} }