mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Display the list of unread conversations
This commit is contained in:
76
lib/ui/screens/unread_conversations_screen.dart
Normal file
76
lib/ui/screens/unread_conversations_screen.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/unread_conversations_list.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||
import 'package:comunic/utils/date_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Unread conversations screen
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class UnreadConversationsScreen extends StatefulWidget {
|
||||
@override
|
||||
_UnreadConversationsScreenState createState() =>
|
||||
_UnreadConversationsScreenState();
|
||||
}
|
||||
|
||||
class _UnreadConversationsScreenState extends State<UnreadConversationsScreen> {
|
||||
UnreadConversationsList _list;
|
||||
UsersList _users;
|
||||
|
||||
Future<void> _refresh() async {
|
||||
_list = await ConversationsHelper.getListUnread();
|
||||
_users = await UsersHelper().getListWithThrow(_list.usersID);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AsyncScreenWidget(
|
||||
onReload: _refresh,
|
||||
onBuild: _buildList,
|
||||
errorMessage: tr("Could not load the list of unread conversations!"),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList() {
|
||||
// Check for no unread conversation
|
||||
if (_list.isEmpty)
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
tr("You do not have any unread conversation yet..."),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return ListView.builder(
|
||||
itemBuilder: _tileBuilder,
|
||||
itemCount: _list.length,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tileBuilder(BuildContext context, int index) {
|
||||
final conv = _list[index];
|
||||
final user = _users.getUser(conv.userID);
|
||||
return ListTile(
|
||||
leading: AccountImageWidget(user: user),
|
||||
title: Text(user.displayName),
|
||||
subtitle: RichText(
|
||||
text: TextSpan(style: Theme.of(context).textTheme.body1, children: [
|
||||
TextSpan(text: conv.convName.isNotEmpty ? conv.convName + "\n" : ""),
|
||||
TextSpan(
|
||||
text: conv.message,
|
||||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
]),
|
||||
),
|
||||
trailing: Text(diffTimeFromNowToStr(conv.lastActive)),
|
||||
);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/notifications_helper.dart';
|
||||
import 'package:comunic/models/count_unread_notifications.dart';
|
||||
import 'package:comunic/ui/screens/notifications_screen.dart';
|
||||
import 'package:comunic/ui/screens/unread_conversations_screen.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/ui/widgets/tablet_mode/appbar_custom_dropdown_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -71,13 +72,7 @@ class _ComunicTabletAppBarWidgetState
|
||||
key: conversationsDropdownKey,
|
||||
icon: Icon(Icons.message),
|
||||
notificationsBadge: _unreadNotifications.conversations,
|
||||
onBuildOverlay: (c) => Center(
|
||||
child: RaisedButton(
|
||||
child: Text("Close"),
|
||||
onPressed: () =>
|
||||
conversationsDropdownKey.currentState.toggleOverlay(),
|
||||
),
|
||||
),
|
||||
onBuildOverlay: (c) => UnreadConversationsScreen(),
|
||||
),
|
||||
PopupMenuButton(itemBuilder: (c) => []),
|
||||
],
|
||||
|
Reference in New Issue
Block a user