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

Improve directory screen

This commit is contained in:
Pierre HUBERT 2021-04-26 08:45:25 +02:00
parent 5cb7fced5b
commit db04366f56
2 changed files with 77 additions and 38 deletions

View File

@ -4,7 +4,6 @@ import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/group_members_list.dart'; import 'package:comunic/lists/group_members_list.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/group.dart';
import 'package:comunic/models/group_membership.dart'; import 'package:comunic/models/group_membership.dart';
import 'package:comunic/models/user.dart'; import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart';
@ -82,6 +81,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
break; break;
case _PopupMenuActions.CANCEL_INVITATION: case _PopupMenuActions.CANCEL_INVITATION:
if (!await showConfirmDialog(
context: context,
message: tr(
"Do you really want to cancel the invitation sent to %u%?",
args: {"u": user.fullName}))) return;
await GroupsHelper.cancelInvitation(forezGroup.id, user.id); await GroupsHelper.cancelInvitation(forezGroup.id, user.id);
_key.currentState.refresh(); _key.currentState.refresh();
break; break;
@ -92,6 +97,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
break; break;
case _PopupMenuActions.REJECT_REQUEST: case _PopupMenuActions.REJECT_REQUEST:
if (!await showConfirmDialog(
context: context,
message: tr(
"Do you really want to reject of %u% to join the Forez group?",
args: {"u": user.fullName}))) return;
await GroupsHelper.respondRequest(forezGroup.id, user.id, false); await GroupsHelper.respondRequest(forezGroup.id, user.id, false);
_key.currentState.refresh(); _key.currentState.refresh();
break; break;
@ -136,55 +147,79 @@ class _ForezMemberTile extends StatelessWidget {
leading: AccountImageWidget(user: user), leading: AccountImageWidget(user: user),
title: Text(user.fullName), title: Text(user.fullName),
subtitle: Text(member.membershipText), subtitle: Text(member.membershipText),
trailing: member.level == GroupMembershipLevel.PENDING trailing: !member.isAtLeastMember && forezGroup.isAtLeastModerator
? _buildRequestedButton() ? (member.isInvited
: _buildPopupMenuButton(), ? _buildInvitedButton()
: _buildRequestedButton())
: _buildConversationButton(),
onTap: member.isAtLeastMember ? () => onTap(user) : null, onTap: member.isAtLeastMember ? () => onTap(user) : null,
); );
Widget _buildPopupMenuButton() => user.id == userID() Widget _buildConversationButton() => user.id == userID()
? null ? null
: PopupMenuButton( : IconButton(
itemBuilder: (c) => popupMenuItems, icon: Icon(Icons.message),
onSelected: (a) => selectedAction(a, user), onPressed: () =>
); selectedAction(_PopupMenuActions.PRIVATE_CONVERSATION, user));
Widget _buildInvitedButton() => _MembershipButton(
user: user,
action: _PopupMenuActions.CANCEL_INVITATION,
onTap: selectedAction,
color: Colors.redAccent,
icon: Icons.close,
);
Widget _buildRequestedButton() => IntrinsicWidth( Widget _buildRequestedButton() => IntrinsicWidth(
child: Row( child: Row(
children: [ children: [
ElevatedButton( _MembershipButton(
onPressed: () => user: user,
selectedAction(_PopupMenuActions.ACCEPT_REQUEST, user), action: _PopupMenuActions.ACCEPT_REQUEST,
child: Icon(Icons.check), onTap: selectedAction,
style: ButtonStyle( color: Colors.green,
visualDensity: VisualDensity.compact, icon: Icons.check,
backgroundColor: MaterialStateProperty.all(Colors.green)),
), ),
SizedBox(width: 5), SizedBox(width: 5),
OutlinedButton( _MembershipButton(
onPressed: () => user: user,
selectedAction(_PopupMenuActions.REJECT_REQUEST, user), action: _PopupMenuActions.REJECT_REQUEST,
child: Icon(Icons.close), onTap: selectedAction,
style: ButtonStyle( color: Colors.redAccent,
visualDensity: VisualDensity.compact, icon: Icons.close,
foregroundColor: MaterialStateProperty.all(Colors.redAccent)),
), ),
], ],
), ),
); );
}
List<PopupMenuItem<_PopupMenuActions>> get popupMenuItems => [
PopupMenuItem( class _MembershipButton extends StatelessWidget {
child: Text(tr("Private conversation")), final User user;
value: _PopupMenuActions.PRIVATE_CONVERSATION, final _PopupMenuActions action;
) final Function(_PopupMenuActions, User) onTap;
]..addAll(member.level == GroupMembershipLevel.INVITED && final Color color;
forezGroup.isAtLeastModerator final IconData icon;
? [
PopupMenuItem( const _MembershipButton({
child: Text(tr("Cancel invitation")), Key key,
value: _PopupMenuActions.CANCEL_INVITATION, @required this.user,
), @required this.action,
] @required this.onTap,
: []); @required this.color,
@required this.icon,
}) : assert(user != null),
assert(action != null),
assert(onTap != null),
assert(color != null),
assert(icon != null),
super(key: key);
@override
Widget build(BuildContext context) => ElevatedButton(
onPressed: () => onTap(action, user),
child: Icon(icon),
style: ButtonStyle(
visualDensity: VisualDensity.compact,
backgroundColor: MaterialStateProperty.all(color)),
);
} }

View File

@ -27,4 +27,8 @@ class GroupMembership {
level == GroupMembershipLevel.ADMINISTRATOR || level == GroupMembershipLevel.ADMINISTRATOR ||
level == GroupMembershipLevel.MODERATOR || level == GroupMembershipLevel.MODERATOR ||
level == GroupMembershipLevel.MEMBER; level == GroupMembershipLevel.MEMBER;
bool get isPending => level == GroupMembershipLevel.PENDING;
bool get isInvited => level == GroupMembershipLevel.INVITED;
} }