1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-26 12:58:51 +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/lists/group_members_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/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
@ -82,6 +81,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
break;
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);
_key.currentState.refresh();
break;
@ -92,6 +97,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
break;
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);
_key.currentState.refresh();
break;
@ -136,55 +147,79 @@ class _ForezMemberTile extends StatelessWidget {
leading: AccountImageWidget(user: user),
title: Text(user.fullName),
subtitle: Text(member.membershipText),
trailing: member.level == GroupMembershipLevel.PENDING
? _buildRequestedButton()
: _buildPopupMenuButton(),
trailing: !member.isAtLeastMember && forezGroup.isAtLeastModerator
? (member.isInvited
? _buildInvitedButton()
: _buildRequestedButton())
: _buildConversationButton(),
onTap: member.isAtLeastMember ? () => onTap(user) : null,
);
Widget _buildPopupMenuButton() => user.id == userID()
Widget _buildConversationButton() => user.id == userID()
? null
: PopupMenuButton(
itemBuilder: (c) => popupMenuItems,
onSelected: (a) => selectedAction(a, user),
);
: IconButton(
icon: Icon(Icons.message),
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(
child: Row(
children: [
ElevatedButton(
onPressed: () =>
selectedAction(_PopupMenuActions.ACCEPT_REQUEST, user),
child: Icon(Icons.check),
style: ButtonStyle(
visualDensity: VisualDensity.compact,
backgroundColor: MaterialStateProperty.all(Colors.green)),
_MembershipButton(
user: user,
action: _PopupMenuActions.ACCEPT_REQUEST,
onTap: selectedAction,
color: Colors.green,
icon: Icons.check,
),
SizedBox(width: 5),
OutlinedButton(
onPressed: () =>
selectedAction(_PopupMenuActions.REJECT_REQUEST, user),
child: Icon(Icons.close),
style: ButtonStyle(
visualDensity: VisualDensity.compact,
foregroundColor: MaterialStateProperty.all(Colors.redAccent)),
_MembershipButton(
user: user,
action: _PopupMenuActions.REJECT_REQUEST,
onTap: selectedAction,
color: Colors.redAccent,
icon: Icons.close,
),
],
),
);
List<PopupMenuItem<_PopupMenuActions>> get popupMenuItems => [
PopupMenuItem(
child: Text(tr("Private conversation")),
value: _PopupMenuActions.PRIVATE_CONVERSATION,
)
]..addAll(member.level == GroupMembershipLevel.INVITED &&
forezGroup.isAtLeastModerator
? [
PopupMenuItem(
child: Text(tr("Cancel invitation")),
value: _PopupMenuActions.CANCEL_INVITATION,
),
]
: []);
}
class _MembershipButton extends StatelessWidget {
final User user;
final _PopupMenuActions action;
final Function(_PopupMenuActions, User) onTap;
final Color color;
final IconData icon;
const _MembershipButton({
Key key,
@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.MODERATOR ||
level == GroupMembershipLevel.MEMBER;
bool get isPending => level == GroupMembershipLevel.PENDING;
bool get isInvited => level == GroupMembershipLevel.INVITED;
}