1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Get and show the name of conversation members

This commit is contained in:
2019-04-23 17:29:58 +02:00
parent c94a294252
commit 7fc03ba15c
9 changed files with 199 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import 'package:comunic/enums/load_error_level.dart';
import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/conversations_list.dart';
import 'package:comunic/ui/tiles/conversation_tile.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
@ -17,7 +18,8 @@ class ConversationsScreen extends StatefulWidget {
class _ConversationScreenState extends State<ConversationsScreen> {
final ConversationsHelper _conversationsHelper = ConversationsHelper();
List<Conversation> _list;
final UsersHelper _usersHelper = UsersHelper();
ConversationsList _list;
LoadErrorLevel _error = LoadErrorLevel.NONE;
bool _loading = true;
@ -31,7 +33,7 @@ class _ConversationScreenState extends State<ConversationsScreen> {
void setLoading(bool loading) => setState(() => _loading = loading);
void gotLoadingError() {
void _gotLoadingError() {
setLoading(false);
setError(_list == null ? LoadErrorLevel.MAJOR : LoadErrorLevel.MINOR);
}
@ -41,12 +43,18 @@ class _ConversationScreenState extends State<ConversationsScreen> {
setError(LoadErrorLevel.NONE);
setLoading(true);
//Process the list of conversations
final list = await _conversationsHelper.downloadList();
if (list == null) return _gotLoadingError();
if (list == null) return gotLoadingError();
//Get information about the members of the conversations
list.users = await _usersHelper.downloadInfo(list.allUsersID);
if(list.users == null) return _gotLoadingError();
//Save list
_list = list;
setState(() {
_list = list;
});
setLoading(false);
}
@ -79,6 +87,7 @@ class _ConversationScreenState extends State<ConversationsScreen> {
itemBuilder: (context, index) {
return ConversationTile(
conversation: _list.elementAt(index),
usersList: _list.users,
);
},
itemCount: _list.length,

View File

@ -1,3 +1,5 @@
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';
@ -9,8 +11,13 @@ import 'package:flutter/material.dart';
class ConversationTile extends StatelessWidget {
final Conversation conversation;
final UsersList usersList;
const ConversationTile({Key key, this.conversation}) : super(key: key);
const ConversationTile(
{Key key, @required this.conversation, @required this.usersList})
: assert(conversation != null),
assert(usersList != null),
super(key: key);
_buildSubInformation(IconData icon, String content) {
return Row(
@ -28,7 +35,10 @@ class ConversationTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(conversation.name == null ? "Unknown" : conversation.name),
title: Text(ConversationsHelper.getConversationName(
conversation,
usersList,
)),
leading: Icon(
conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
color: conversation.sawLastMessage ? null : Colors.blue,