mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-27 21:38:51 +00:00
124 lines
3.5 KiB
Dart
124 lines
3.5 KiB
Dart
import 'package:comunic/helpers/conversations_helper.dart';
|
|
import 'package:comunic/lists/users_list.dart';
|
|
import 'package:comunic/models/conversation.dart';
|
|
import 'package:comunic/utils/date_utils.dart';
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Single conversation tile
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
typedef OpenConversationCallback = void Function(Conversation);
|
|
typedef RequestDeleteConversationCallback = void Function(Conversation);
|
|
typedef RequestUpdateConversationCallback = void Function(Conversation);
|
|
|
|
enum _PopupMenuChoices { UPDATE, DELETE }
|
|
|
|
class ConversationTile extends StatelessWidget {
|
|
final Conversation conversation;
|
|
final UsersList usersList;
|
|
final OpenConversationCallback onOpen;
|
|
final RequestUpdateConversationCallback onRequestUpdate;
|
|
final RequestDeleteConversationCallback onRequestDelete;
|
|
|
|
const ConversationTile({
|
|
Key key,
|
|
@required this.conversation,
|
|
@required this.usersList,
|
|
@required this.onOpen,
|
|
@required this.onRequestUpdate,
|
|
@required this.onRequestDelete,
|
|
}) : assert(conversation != null),
|
|
assert(usersList != null),
|
|
assert(onOpen != null),
|
|
assert(onRequestUpdate != null),
|
|
assert(onRequestDelete != null),
|
|
super(key: key);
|
|
|
|
_buildSubInformation(IconData icon, String content) {
|
|
return Row(
|
|
children: <Widget>[
|
|
Icon(
|
|
icon,
|
|
size: 15.0,
|
|
color: Colors.grey,
|
|
),
|
|
Text(" " + content),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListTile(
|
|
onTap: () => onOpen(conversation),
|
|
// Conversation name
|
|
title: Text(
|
|
ConversationsHelper.getConversationName(
|
|
conversation,
|
|
usersList,
|
|
),
|
|
style: TextStyle(
|
|
fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
|
|
),
|
|
),
|
|
|
|
// Leading icon
|
|
leading: Icon(
|
|
conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
|
|
color: conversation.sawLastMessage ? null : Colors.blue,
|
|
),
|
|
|
|
// Conversation information
|
|
isThreeLine: true,
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
_buildSubInformation(
|
|
Icons.access_time, diffTimeFromNowToStr(conversation.lastActive)),
|
|
_buildSubInformation(
|
|
Icons.group,
|
|
conversation.members.length == 1
|
|
? tr("1 member")
|
|
: tr(
|
|
"%num% members",
|
|
args: {
|
|
"num": conversation.members.length.toString(),
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
// Trailing information
|
|
trailing: PopupMenuButton<_PopupMenuChoices>(
|
|
itemBuilder: (b) => <PopupMenuEntry<_PopupMenuChoices>>[
|
|
PopupMenuItem(
|
|
child: Text(tr("Update")),
|
|
value: _PopupMenuChoices.UPDATE,
|
|
),
|
|
PopupMenuItem(
|
|
child: Text(tr("Delete")),
|
|
value: _PopupMenuChoices.DELETE,
|
|
)
|
|
],
|
|
onSelected: _conversationMenuCallback,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Method called each time an option of the menu is selected
|
|
void _conversationMenuCallback(_PopupMenuChoices c) {
|
|
switch (c) {
|
|
case _PopupMenuChoices.UPDATE:
|
|
onRequestUpdate(conversation);
|
|
break;
|
|
|
|
case _PopupMenuChoices.DELETE:
|
|
onRequestDelete(conversation);
|
|
break;
|
|
}
|
|
}
|
|
}
|