From 63ffdfdd1cb57fbf8c98f6ba0c0ba2a87a3a787d Mon Sep 17 00:00:00 2001 From: Sun Date: Tue, 1 Jun 2021 17:23:02 +0800 Subject: [PATCH] unify select friends contact UI --- lib/apps/assistant/page.dart | 76 +++++++------------------------- lib/apps/assistant/provider.dart | 1 - lib/apps/chat/detail.dart | 73 +++++++----------------------- lib/apps/group_chat/detail.dart | 73 +++++++----------------------- lib/widgets/show_contact.dart | 24 ++++++---- 5 files changed, 65 insertions(+), 182 deletions(-) diff --git a/lib/apps/assistant/page.dart b/lib/apps/assistant/page.dart index 358c5b8..d15da5b 100644 --- a/lib/apps/assistant/page.dart +++ b/lib/apps/assistant/page.dart @@ -9,11 +9,10 @@ import 'package:esse/l10n/localizations.dart'; import 'package:esse/widgets/emoji.dart'; import 'package:esse/widgets/shadow_dialog.dart'; import 'package:esse/widgets/audio_recorder.dart'; -import 'package:esse/widgets/user_info.dart'; +import 'package:esse/widgets/show_contact.dart'; import 'package:esse/global.dart'; import 'package:esse/options.dart'; -import 'package:esse/apps/chat/provider.dart'; import 'package:esse/apps/assistant/models.dart'; import 'package:esse/apps/assistant/provider.dart'; import 'package:esse/apps/assistant/message.dart'; @@ -131,64 +130,24 @@ class _AssistantDetailState extends State { }); } - void _sendContact(ColorScheme color, AppLocalizations lang, friends) { + _callback(int id) { + context.read().create(MessageType.Contact, "${id}"); + setState(() { + textFocus.requestFocus(); + emojiShow = false; + sendShow = false; + menuShow = false; + recordShow = false; + }); + } + + void _sendContact(ColorScheme color, AppLocalizations lang) { showShadowDialog( context, Icons.person_rounded, - 'Contact', - Column(children: [ - Container( - height: 40.0, - decoration: BoxDecoration( - color: color.surface, - borderRadius: BorderRadius.circular(15.0)), - child: TextField( - autofocus: false, - textInputAction: TextInputAction.search, - textAlignVertical: TextAlignVertical.center, - style: TextStyle(fontSize: 14.0), - onSubmitted: (value) { - toast(context, 'WIP...'); - }, - decoration: InputDecoration( - hintText: lang.search, - hintStyle: TextStyle(color: color.onPrimary.withOpacity(0.5)), - border: InputBorder.none, - contentPadding: - EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0), - ), - ), - ), - SizedBox(height: 15.0), - Column( - children: friends.map((contact) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - context.read().create(MessageType.Contact, "${contact.id}"); - Navigator.of(context).pop(); - setState(() { - textFocus.requestFocus(); - emojiShow = false; - sendShow = false; - menuShow = false; - recordShow = false; - }); - }, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20.0, vertical: 14.0), - child: Row( - children: [ - contact.showAvatar(), - SizedBox(width: 15.0), - Text(contact.name, style: TextStyle(fontSize: 16.0)), - ], - ), - ), - ); - }).toList()) - ])); + lang.contact, + ContactList(callback: _callback, multiple: false) + ); } @override @@ -424,8 +383,7 @@ class _AssistantDetailState extends State { ExtensionButton( icon: Icons.person_rounded, text: lang.contact, - action: () => _sendContact(color, lang, - context.read().friends.values), + action: () => _sendContact(color, lang), bgColor: color.surface, iconColor: color.primary), ], diff --git a/lib/apps/assistant/provider.dart b/lib/apps/assistant/provider.dart index fa46373..96008ec 100644 --- a/lib/apps/assistant/provider.dart +++ b/lib/apps/assistant/provider.dart @@ -28,7 +28,6 @@ class AssistantProvider extends ChangeNotifier { create(MessageType q_type, String q_content) { rpc.send('assistant-create', [q_type.toInt(), q_content]); - notifyListeners(); } /// delete a message. diff --git a/lib/apps/chat/detail.dart b/lib/apps/chat/detail.dart index f1287f4..be8b047 100644 --- a/lib/apps/chat/detail.dart +++ b/lib/apps/chat/detail.dart @@ -11,6 +11,7 @@ import 'package:esse/widgets/shadow_dialog.dart'; import 'package:esse/widgets/audio_recorder.dart'; import 'package:esse/widgets/user_info.dart'; import 'package:esse/widgets/chat_message.dart'; +import 'package:esse/widgets/show_contact.dart'; import 'package:esse/global.dart'; import 'package:esse/provider.dart'; import 'package:esse/session.dart'; @@ -121,64 +122,24 @@ class _ChatDetailState extends State { }); } - void _sendContact(ColorScheme color, AppLocalizations lang, friends) { + _callback(int id) { + context.read().messageCreate(Message(_actived, MessageType.Contact, "${id}")); + setState(() { + textFocus.requestFocus(); + emojiShow = false; + sendShow = false; + menuShow = false; + recordShow = false; + }); + } + + void _sendContact(ColorScheme color, AppLocalizations lang) { showShadowDialog( context, Icons.person_rounded, - 'Contact', - Column(children: [ - Container( - height: 40.0, - decoration: BoxDecoration( - color: color.surface, - borderRadius: BorderRadius.circular(15.0)), - child: TextField( - autofocus: false, - textInputAction: TextInputAction.search, - textAlignVertical: TextAlignVertical.center, - style: TextStyle(fontSize: 14.0), - onSubmitted: (value) { - toast(context, 'WIP...'); - }, - decoration: InputDecoration( - hintText: lang.search, - hintStyle: TextStyle(color: color.onPrimary.withOpacity(0.5)), - border: InputBorder.none, - contentPadding: - EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0), - ), - ), - ), - SizedBox(height: 15.0), - Column( - children: friends.map((contact) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - context.read().messageCreate(Message(_actived, MessageType.Contact, "${contact.id}")); - Navigator.of(context).pop(); - setState(() { - textFocus.requestFocus(); - emojiShow = false; - sendShow = false; - menuShow = false; - recordShow = false; - }); - }, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20.0, vertical: 14.0), - child: Row( - children: [ - contact.showAvatar(), - SizedBox(width: 15.0), - Text(contact.name, style: TextStyle(fontSize: 16.0)), - ], - ), - ), - ); - }).toList()) - ])); + lang.contact, + ContactList(callback: _callback, multiple: false) + ); } @override @@ -536,7 +497,7 @@ class _ChatDetailState extends State { ExtensionButton( icon: Icons.person_rounded, text: lang.contact, - action: () => _sendContact(color, lang, context.read().friends.values), + action: () => _sendContact(color, lang), bgColor: color.surface, iconColor: color.primary), ], diff --git a/lib/apps/group_chat/detail.dart b/lib/apps/group_chat/detail.dart index b7b8db5..6bcfbe0 100644 --- a/lib/apps/group_chat/detail.dart +++ b/lib/apps/group_chat/detail.dart @@ -20,7 +20,6 @@ import 'package:esse/global.dart'; import 'package:esse/provider.dart'; import 'package:esse/apps/primitives.dart'; -import 'package:esse/apps/chat/provider.dart'; import 'package:esse/apps/group_chat/models.dart'; import 'package:esse/apps/group_chat/provider.dart'; @@ -127,64 +126,24 @@ class _GroupChatDetailState extends State { }); } - void _sendContact(ColorScheme color, AppLocalizations lang, friends) { + _callback(int id) { + context.read().messageCreate(MessageType.Contact, "${id}"); + setState(() { + textFocus.requestFocus(); + emojiShow = false; + sendShow = false; + menuShow = false; + recordShow = false; + }); + } + + void _sendContact(ColorScheme color, AppLocalizations lang) { showShadowDialog( context, Icons.person_rounded, - 'Contact', - Column(children: [ - Container( - height: 40.0, - decoration: BoxDecoration( - color: color.surface, - borderRadius: BorderRadius.circular(15.0)), - child: TextField( - autofocus: false, - textInputAction: TextInputAction.search, - textAlignVertical: TextAlignVertical.center, - style: TextStyle(fontSize: 14.0), - onSubmitted: (value) { - toast(context, 'WIP...'); - }, - decoration: InputDecoration( - hintText: lang.search, - hintStyle: TextStyle(color: color.onPrimary.withOpacity(0.5)), - border: InputBorder.none, - contentPadding: - EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0), - ), - ), - ), - SizedBox(height: 15.0), - Column( - children: friends.map((contact) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - //context.read().messageCreate(Message(friend.id, MessageType.Contact, "${contact.id}")); - Navigator.of(context).pop(); - setState(() { - textFocus.requestFocus(); - emojiShow = false; - sendShow = false; - menuShow = false; - recordShow = false; - }); - }, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20.0, vertical: 14.0), - child: Row( - children: [ - contact.showAvatar(), - SizedBox(width: 15.0), - Text(contact.name, style: TextStyle(fontSize: 16.0)), - ], - ), - ), - ); - }).toList()) - ])); + lang.contact, + ContactList(callback: _callback, multiple: false) + ); } @override @@ -527,7 +486,7 @@ class _GroupChatDetailState extends State { ExtensionButton( icon: Icons.person_rounded, text: lang.contact, - action: () => _sendContact(color, lang, context.read().friends.values), + action: () => _sendContact(color, lang), bgColor: color.surface, iconColor: color.primary), ], diff --git a/lib/widgets/show_contact.dart b/lib/widgets/show_contact.dart index 2ce41d2..7b7aa3d 100644 --- a/lib/widgets/show_contact.dart +++ b/lib/widgets/show_contact.dart @@ -8,7 +8,7 @@ import 'package:esse/apps/chat/provider.dart'; class ContactList extends StatefulWidget { final Function callback; final bool multiple; - const ContactList({Key key, this.callback, this.multiple}): super(key: key); + const ContactList({Key key, this.callback, this.multiple = true}): super(key: key); @override _ContactListState createState() => _ContactListState(); @@ -34,17 +34,22 @@ class _ContactListState extends State { Widget _friend(int i, Friend friend) { return Container( height: 55.0, - child: ListTile( + child: widget.multiple + ? ListTile( leading: friend.showAvatar(), title: Text(friend.name), trailing: Checkbox( value: _checks[i], - onChanged: (bool value) { - setState(() { - _checks[i] = value; - }); - }, - ), + onChanged: (bool value) => setState(() => _checks[i] = value), + ) + ) + : ListTile( + onTap: () { + Navigator.pop(context); + widget.callback(friend.id); + }, + leading: friend.showAvatar(), + title: Text(friend.name), ) ); } @@ -54,7 +59,7 @@ class _ContactListState extends State { final color = Theme.of(context).colorScheme; final lang = AppLocalizations.of(context); - double maxHeight = (MediaQuery.of(context).size.height - 300); + double maxHeight = (MediaQuery.of(context).size.height - 400); if (maxHeight < 100.0) { maxHeight = 100.0; } @@ -93,6 +98,7 @@ class _ContactListState extends State { ), const Divider(height: 1.0, color: Color(0x40ADB0BB)), const SizedBox(height: 10.0), + if (widget.multiple) Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [