mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Display icons for all conversations
This commit is contained in:
parent
c8ca80f6e7
commit
b9babd43a8
@ -56,6 +56,9 @@ class Conversation extends SerializableElement<Conversation> {
|
|||||||
/// Get the list of members in the conversation
|
/// Get the list of members in the conversation
|
||||||
Set<int> get membersID => members.map((e) => e.userID).toSet();
|
Set<int> get membersID => members.map((e) => e.userID).toSet();
|
||||||
|
|
||||||
|
/// Get the list of the OTHER members of the conversation (all except current user)
|
||||||
|
Set<int> get otherMembersID => membersID..remove(userID());
|
||||||
|
|
||||||
/// Check if the last message has been seen or not
|
/// Check if the last message has been seen or not
|
||||||
bool get sawLastMessage => lastActivity <= membership.lastAccessTime;
|
bool get sawLastMessage => lastActivity <= membership.lastAccessTime;
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
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/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';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Single conversation tile
|
/// Single conversation tile
|
||||||
@ -73,15 +72,8 @@ class ConversationTile extends StatelessWidget {
|
|||||||
: (conversation.color ?? Colors.blue).withOpacity(0.2),
|
: (conversation.color ?? Colors.blue).withOpacity(0.2),
|
||||||
|
|
||||||
// Leading icon
|
// Leading icon
|
||||||
leading: conversation.logoURL == null
|
leading:
|
||||||
? Icon(
|
ConversationImageWidget(conversation: conversation, users: usersList),
|
||||||
conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
|
|
||||||
color: (darkTheme() ? darkAccentColor : null),
|
|
||||||
)
|
|
||||||
: CachedNetworkImage(
|
|
||||||
imageUrl: conversation.logoURL,
|
|
||||||
width: 30,
|
|
||||||
),
|
|
||||||
|
|
||||||
// Conversation information
|
// Conversation information
|
||||||
isThreeLine: true,
|
isThreeLine: true,
|
||||||
|
118
lib/ui/widgets/conversation_image_widget.dart
Normal file
118
lib/ui/widgets/conversation_image_widget.dart
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:comunic/lists/users_list.dart';
|
||||||
|
import 'package:comunic/models/conversation.dart';
|
||||||
|
import 'package:comunic/models/user.dart';
|
||||||
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Conversation image widget
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
class ConversationImageWidget extends StatelessWidget {
|
||||||
|
final Conversation conversation;
|
||||||
|
final UsersList users;
|
||||||
|
final double size;
|
||||||
|
|
||||||
|
const ConversationImageWidget(
|
||||||
|
{Key key,
|
||||||
|
@required this.conversation,
|
||||||
|
@required this.users,
|
||||||
|
this.size = 30})
|
||||||
|
: assert(conversation != null),
|
||||||
|
assert(users != null),
|
||||||
|
assert(size > 0),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Material(
|
||||||
|
child: _buildIcon(),
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(18.0),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildIcon() {
|
||||||
|
if (conversation.logoURL != null)
|
||||||
|
return CachedNetworkImage(
|
||||||
|
imageUrl: conversation.logoURL,
|
||||||
|
width: size,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (conversation.members.length < 2)
|
||||||
|
return Icon(
|
||||||
|
Icons.lock,
|
||||||
|
size: size,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (conversation.members.length == 2)
|
||||||
|
return AccountImageWidget(
|
||||||
|
width: size,
|
||||||
|
user: users.getUser(conversation.otherMembersID.first),
|
||||||
|
);
|
||||||
|
|
||||||
|
return MultipleAccountImagesWidget(
|
||||||
|
users:
|
||||||
|
conversation.otherMembersID.map((id) => users.getUser(id)).toList(),
|
||||||
|
size: size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MultipleAccountImagesWidget extends StatelessWidget {
|
||||||
|
final List<User> users;
|
||||||
|
final double size;
|
||||||
|
|
||||||
|
const MultipleAccountImagesWidget({
|
||||||
|
Key key,
|
||||||
|
@required this.users,
|
||||||
|
@required this.size,
|
||||||
|
}) : assert(users != null),
|
||||||
|
assert(size != null),
|
||||||
|
assert(size > 0),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Container(
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
child: _buildContent(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildContent() {
|
||||||
|
if (users.length == 2) return _buildFirstRow();
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [_buildFirstRow(), _buildSecondRow()],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildFirstRow() => Row(
|
||||||
|
children: [
|
||||||
|
AccountImageWidget(
|
||||||
|
user: users[0],
|
||||||
|
width: size / 2,
|
||||||
|
),
|
||||||
|
AccountImageWidget(
|
||||||
|
user: users[1],
|
||||||
|
width: size / 2,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildSecondRow() => Row(
|
||||||
|
children: [
|
||||||
|
AccountImageWidget(
|
||||||
|
user: users[2],
|
||||||
|
width: size / 2,
|
||||||
|
),
|
||||||
|
users.length > 3
|
||||||
|
? AccountImageWidget(
|
||||||
|
user: users[3],
|
||||||
|
width: size / 2,
|
||||||
|
)
|
||||||
|
: Container()
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
@ -276,7 +276,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.1"
|
version: "0.1.1"
|
||||||
image:
|
image:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: image
|
name: image
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
@ -100,6 +100,9 @@ dependencies:
|
|||||||
# Copy content to clipboard
|
# Copy content to clipboard
|
||||||
clipboard: ^0.1.2+8
|
clipboard: ^0.1.2+8
|
||||||
|
|
||||||
|
# Image manager
|
||||||
|
image: ^2.1.19
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user