1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-30 14:58:52 +00:00
comunicmobile/lib/ui/tiles/accepted_friend_tile.dart

110 lines
3.3 KiB
Dart
Raw Normal View History

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
enum _FriendMenuChoices { REMOVE, TOGGLE_FOLLOWING, PRIVATE_CONVERSATION }
typedef OnRequestDeleteFriend = void Function(Friend);
2019-05-01 17:46:13 +00:00
typedef OnSetFollowing = void Function(Friend, bool);
typedef OnOpenPrivateConversation = 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;
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,
2019-05-01 17:46:13 +00:00
}) : assert(friend != null),
assert(user != null),
assert(onRequestDelete != null),
2019-05-01 17:46:13 +00:00
assert(onSetFollowing != null),
assert(onOpenPrivateConversation != null),
super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
2019-06-10 12:24:34 +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) => [
//Open a private conversation
PopupMenuItem(
child: Text(tr("Private conversation")),
value: _FriendMenuChoices.PRIVATE_CONVERSATION,
),
// Update following status
2019-05-01 17:46:13 +00:00
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,
),
// Remove the friend from the list
PopupMenuItem(
child: Text(tr("Remove")),
value: _FriendMenuChoices.REMOVE,
2019-05-01 17:46:13 +00:00
),
],
onSelected: _selectedMenuOption,
),
);
}
void _selectedMenuOption(_FriendMenuChoices value) {
if (value == null) return;
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;
}
}
}