1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Visually notify user of new messages when conversation is collapsed

This commit is contained in:
Pierre HUBERT 2020-05-09 10:39:37 +02:00
parent 123eaad296
commit 032815b29f
2 changed files with 18 additions and 2 deletions

View File

@ -1,8 +1,10 @@
import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/ui/screens/conversation_screen.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/ui/widgets/tablet_mode/conversations/conversation_window_container.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
@ -32,6 +34,7 @@ class _ConversationWindowState extends SafeState<ConversationWindow> {
String _convTitle;
bool _error = false;
bool _collapsed = false;
bool _hasNewMessages = false;
int get _convID => widget.convID;
@ -39,7 +42,10 @@ class _ConversationWindowState extends SafeState<ConversationWindow> {
void _setError(bool e) => setState(() => _error = e);
void _toggleVisibility() => setState(() => _collapsed = !_collapsed);
void _toggleVisibility() => setState(() {
_collapsed = !_collapsed;
if (!_collapsed) _hasNewMessages = false;
});
Future<void> _refresh() async {
try {
@ -67,6 +73,12 @@ class _ConversationWindowState extends SafeState<ConversationWindow> {
void initState() {
super.initState();
_refresh();
listen<NewConversationMessageEvent>((e) {
if (e.msg.conversationID == _convID &&
_collapsed &&
e.msg.userID != userID()) setState(() => _hasNewMessages = true);
});
}
@override
@ -101,7 +113,8 @@ class _ConversationWindowState extends SafeState<ConversationWindow> {
);
return ConversationWindowContainer(
icon: Icon(Icons.comment),
icon: Icon(_hasNewMessages ? Icons.trip_origin : Icons.comment),
appBarBgColor: _hasNewMessages ? Colors.green : null,
title: Text(_convTitle),
onClose: widget.onClose,
onToggleCollapse: _toggleVisibility,

View File

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
/// @author Pierre Hubert
class ConversationWindowContainer extends StatelessWidget {
final Color appBarBgColor;
final Widget icon;
final Widget title;
final void Function() onClose;
@ -16,6 +17,7 @@ class ConversationWindowContainer extends StatelessWidget {
const ConversationWindowContainer({
Key key,
this.appBarBgColor,
this.icon,
@required this.title,
@required this.onClose,
@ -37,6 +39,7 @@ class ConversationWindowContainer extends StatelessWidget {
height: !isCollapsed ? 400 : 40,
child: Scaffold(
appBar: AppBar(
backgroundColor: appBarBgColor,
leading: icon,
title: GestureDetector(child: title, onTap: onToggleCollapse),
actions: <Widget>[