mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Improve directory screen
This commit is contained in:
		@@ -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)),
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user