1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Add call notice on conversations list

This commit is contained in:
Pierre HUBERT 2021-03-13 12:02:24 +01:00
parent d10b1d0d22
commit 4614f3ae2e

View File

@ -1,6 +1,7 @@
import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart'; import 'package:comunic/models/conversation.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/conversation_image_widget.dart'; import 'package:comunic/ui/widgets/conversation_image_widget.dart';
import 'package:comunic/ui/widgets/custom_list_tile.dart'; import 'package:comunic/ui/widgets/custom_list_tile.dart';
import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/date_utils.dart';
@ -52,65 +53,83 @@ class ConversationTile extends StatelessWidget {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => Column(
return CustomListTile( children: [_buildMainTile(context), _buildCallTile(context)],
onTap: () => onOpen(conversation), );
// Conversation name
title: Text(
ConversationsHelper.getConversationName(
conversation,
usersList,
),
style: TextStyle(
fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
),
),
// Tile color Widget _buildMainTile(BuildContext context) => CustomListTile(
tileColor: conversation.sawLastMessage onTap: () => onOpen(conversation),
? null // Conversation name
: (conversation.color ?? Colors.blue).withOpacity(0.2), title: Text(
ConversationsHelper.getConversationName(
// Leading icon conversation,
leading: usersList,
ConversationImageWidget(conversation: conversation, users: usersList),
// Conversation information
isThreeLine: true,
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_buildSubInformation(Icons.access_time,
diffTimeFromNowToStr(conversation.lastActivity)),
_buildSubInformation(
Icons.group,
conversation.members.length == 1
? tr("1 member")
: tr(
"%num% members",
args: {
"num": conversation.members.length.toString(),
},
),
), ),
], style: TextStyle(
), fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
),
),
onLongPressOpenMenu: (position) { // Tile color
showMenu<_PopupMenuChoices>( tileColor: conversation.sawLastMessage
context: context, ? null
position: position, : (conversation.color ?? Colors.blue).withOpacity(0.2),
items: [
PopupMenuItem( // Leading icon
child: Text(tr("Update")), leading: ConversationImageWidget(
value: _PopupMenuChoices.UPDATE, conversation: conversation, users: usersList),
),
PopupMenuItem( // Conversation information
child: Text(tr("Delete")), isThreeLine: true,
value: _PopupMenuChoices.DELETE, subtitle: Column(
) crossAxisAlignment: CrossAxisAlignment.stretch,
]).then(_conversationMenuCallback); children: <Widget>[
}, _buildSubInformation(Icons.access_time,
diffTimeFromNowToStr(conversation.lastActivity)),
_buildSubInformation(
Icons.group,
conversation.members.length == 1
? tr("1 member")
: tr(
"%num% members",
args: {
"num": conversation.members.length.toString(),
},
),
),
],
),
onLongPressOpenMenu: (position) {
showMenu<_PopupMenuChoices>(
context: context,
position: position,
items: [
PopupMenuItem(
child: Text(tr("Update")),
value: _PopupMenuChoices.UPDATE,
),
PopupMenuItem(
child: Text(tr("Delete")),
value: _PopupMenuChoices.DELETE,
)
]).then(_conversationMenuCallback);
},
);
/// Build call tile, in case of ongoing call
Widget _buildCallTile(BuildContext context) {
if (!conversation.isHavingCall) return Container();
return Padding(
padding: EdgeInsets.only(bottom: 20),
child: ListTile(
onTap: () => MainController.of(context).startCall(conversation.id),
dense: true,
title: Text(tr("Ongoing call")),
leading: Icon(Icons.call),
tileColor: Colors.yellow.withOpacity(0.2),
),
); );
} }