1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00
comunicmobile/lib/ui/tiles/accepted_friend_tile.dart

124 lines
3.6 KiB
Dart
Raw Normal View History

2022-03-18 16:54:19 +00:00
import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/models/friend.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
2019-06-10 12:24:34 +00:00
import 'package:comunic/utils/navigation_utils.dart';
import 'package:flutter/material.dart';
/// Accepted friend tile
///
/// @author Pierre HUBERT
2022-03-18 16:54:19 +00:00
enum _FriendMenuChoices {
REMOVE,
TOGGLE_FOLLOWING,
PRIVATE_CONVERSATION,
REPORT
}
typedef OnRequestDeleteFriend = void Function(Friend);
2019-05-01 17:46:13 +00:00
typedef OnSetFollowing = void Function(Friend, bool);
typedef OnOpenPrivateConversation = void Function(Friend);
2022-03-18 16:54:19 +00:00
typedef OnReportFriend = void Function(Friend);
class AcceptedFriendTile extends StatelessWidget {
final Friend friend;
final User user;
final OnRequestDeleteFriend onRequestDelete;
2019-05-01 17:46:13 +00:00
final OnSetFollowing onSetFollowing;
final OnOpenPrivateConversation onOpenPrivateConversation;
2022-03-18 16:54:19 +00:00
final OnReportFriend onReportFriend;
2019-05-01 17:46:13 +00:00
const AcceptedFriendTile({
Key? key,
required this.friend,
required this.user,
required this.onRequestDelete,
required this.onSetFollowing,
required this.onOpenPrivateConversation,
2022-03-18 16:54:19 +00:00
required this.onReportFriend,
2022-03-11 15:40:56 +00:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
2022-03-11 15:21:35 +00:00
onTap: () => openUserPage(context: context, userID: user.id),
leading: AccountImageWidget(user: user),
title: Text(user.displayName),
subtitle: friend.isConnected
? Text(
tr(
"Online",
)!,
style: TextStyle(color: Colors.green),
)
: Text(
diffTimeFromNowToStr(friend.lastActive!)!,
),
trailing: PopupMenuButton<_FriendMenuChoices>(
itemBuilder: (c) => [
2022-03-11 15:40:56 +00:00
//Open a private conversation
PopupMenuItem(
child: Text(tr("Private conversation")!),
value: _FriendMenuChoices.PRIVATE_CONVERSATION,
),
2022-03-11 15:40:56 +00:00
// Update following status
PopupMenuItem(
child: Row(
children: <Widget>[
Icon(friend.following
? Icons.check_box
: Icons.check_box_outline_blank),
Container(width: 10.0),
Text(friend.following ? tr("Following")! : tr("Follow")!),
],
),
value: _FriendMenuChoices.TOGGLE_FOLLOWING,
),
2022-03-11 15:40:56 +00:00
// Remove the friend from the list
PopupMenuItem(
child: Text(tr("Remove")!),
value: _FriendMenuChoices.REMOVE,
),
2022-03-18 16:54:19 +00:00
]..addAll(srvConfig!.isReportingEnabled
? [
// Report user
PopupMenuItem(
child: Text(tr("Report abuse")!),
value: _FriendMenuChoices.REPORT,
),
]
: []),
onSelected: _selectedMenuOption,
),
);
}
void _selectedMenuOption(_FriendMenuChoices value) {
switch (value) {
// Open private conversation
case _FriendMenuChoices.PRIVATE_CONVERSATION:
onOpenPrivateConversation(friend);
break;
2019-05-01 17:46:13 +00:00
//Toggle following status
case _FriendMenuChoices.TOGGLE_FOLLOWING:
onSetFollowing(friend, !friend.following);
break;
//Delete friend
case _FriendMenuChoices.REMOVE:
onRequestDelete(friend);
break;
2022-03-18 16:54:19 +00:00
case _FriendMenuChoices.REPORT:
onReportFriend(friend);
break;
}
}
}