mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Add call notice on conversations list
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
import 'package:comunic/helpers/conversations_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/users_list.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/custom_list_tile.dart';
 | 
			
		||||
import 'package:comunic/utils/date_utils.dart';
 | 
			
		||||
@@ -52,65 +53,83 @@ class ConversationTile extends StatelessWidget {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return CustomListTile(
 | 
			
		||||
      onTap: () => onOpen(conversation),
 | 
			
		||||
      // Conversation name
 | 
			
		||||
      title: Text(
 | 
			
		||||
        ConversationsHelper.getConversationName(
 | 
			
		||||
          conversation,
 | 
			
		||||
          usersList,
 | 
			
		||||
        ),
 | 
			
		||||
        style: TextStyle(
 | 
			
		||||
          fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
  Widget build(BuildContext context) => Column(
 | 
			
		||||
        children: [_buildMainTile(context), _buildCallTile(context)],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      // Tile color
 | 
			
		||||
      tileColor: conversation.sawLastMessage
 | 
			
		||||
          ? null
 | 
			
		||||
          : (conversation.color ?? Colors.blue).withOpacity(0.2),
 | 
			
		||||
 | 
			
		||||
      // Leading icon
 | 
			
		||||
      leading:
 | 
			
		||||
          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(),
 | 
			
		||||
                    },
 | 
			
		||||
                  ),
 | 
			
		||||
  Widget _buildMainTile(BuildContext context) => CustomListTile(
 | 
			
		||||
        onTap: () => onOpen(conversation),
 | 
			
		||||
        // Conversation name
 | 
			
		||||
        title: Text(
 | 
			
		||||
          ConversationsHelper.getConversationName(
 | 
			
		||||
            conversation,
 | 
			
		||||
            usersList,
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
          style: TextStyle(
 | 
			
		||||
            fontWeight: conversation.sawLastMessage ? null : FontWeight.bold,
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
 | 
			
		||||
      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);
 | 
			
		||||
      },
 | 
			
		||||
        // Tile color
 | 
			
		||||
        tileColor: conversation.sawLastMessage
 | 
			
		||||
            ? null
 | 
			
		||||
            : (conversation.color ?? Colors.blue).withOpacity(0.2),
 | 
			
		||||
 | 
			
		||||
        // Leading icon
 | 
			
		||||
        leading: 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(),
 | 
			
		||||
                      },
 | 
			
		||||
                    ),
 | 
			
		||||
            ),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
 | 
			
		||||
        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),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user