From 661475dec775985cf63eb6f777eb3fb63b62cc39 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 6 Apr 2021 18:41:51 +0200 Subject: [PATCH] Update conversation settings --- lib/ui/routes/conversation_route.dart | 10 +---- lib/ui/routes/main_route/main_route.dart | 10 +++++ .../screens/authorized_group_page_screen.dart | 6 +-- lib/ui/screens/conversations_list_screen.dart | 7 +--- .../group_conversation_section.dart | 36 +++++++++++++++++ .../screens/update_conversation_screen.dart | 39 ++++++++++++------- 6 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 lib/ui/screens/group_sections/group_conversation_section.dart diff --git a/lib/ui/routes/conversation_route.dart b/lib/ui/routes/conversation_route.dart index a37f5e3..2e31d00 100644 --- a/lib/ui/routes/conversation_route.dart +++ b/lib/ui/routes/conversation_route.dart @@ -3,7 +3,6 @@ import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/lists/users_list.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; -import 'package:comunic/ui/routes/update_conversation_route.dart'; import 'package:comunic/ui/screens/conversation_screen.dart'; import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; import 'package:comunic/ui/widgets/conversation_image_widget.dart'; @@ -65,13 +64,8 @@ class _ConversationRouteState extends SafeState { } } - void _openSettings() { - MainController.of(context).push( - UpdateConversationRoute( - conversationID: widget.conversationID, - ), - hideNavBar: true); - } + void _openSettings() => + MainController.of(context).openConversationSettingsRoute(_conversation); Widget _buildRouteBody() { //Handle errors diff --git a/lib/ui/routes/main_route/main_route.dart b/lib/ui/routes/main_route/main_route.dart index cc08e87..e57ebb8 100644 --- a/lib/ui/routes/main_route/main_route.dart +++ b/lib/ui/routes/main_route/main_route.dart @@ -5,6 +5,7 @@ import 'package:comunic/ui/routes/conversation_message_stats_route.dart'; import 'package:comunic/ui/routes/conversation_route.dart'; import 'package:comunic/ui/routes/main_route/page_info.dart'; import 'package:comunic/ui/routes/settings/account_settings_route.dart'; +import 'package:comunic/ui/routes/update_conversation_route.dart'; import 'package:comunic/ui/screens/call_screen.dart'; import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/screens/friends_list_screen.dart'; @@ -169,6 +170,15 @@ abstract class MainController extends State { hideNavBar: true, )); + /// Open conversation settings route + void openConversationSettingsRoute(Conversation conv) => pushPage(PageInfo( + child: UpdateConversationRoute( + conversationID: conv.id, + ), + canShowAsDialog: true, + hideNavBar: true, + )); + /// Open a conversation message statistics page void openConversationMessageStats( Conversation conv, ConversationMessage message) => diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index 249b3d5..51b9d4d 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -1,7 +1,7 @@ import 'package:comunic/models/advanced_group_info.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; -import 'package:comunic/ui/screens/conversation_screen.dart'; import 'package:comunic/ui/screens/group_sections/about_group_section.dart'; +import 'package:comunic/ui/screens/group_sections/group_conversation_section.dart'; import 'package:comunic/ui/screens/group_sections/group_members_screen.dart'; import 'package:comunic/ui/screens/group_sections/group_posts_section.dart'; import 'package:comunic/ui/screens/group_settings_screen.dart'; @@ -75,9 +75,7 @@ class _AuthorizedGroupPageScreenState 1, _group.conversations .map((e) => _GroupPageTab( - widget: (c) => ConversationScreen( - conversationID: e.id, - ), + widget: (c) => GroupConversationSection(conv: e), label: e.name)) .toList()); diff --git a/lib/ui/screens/conversations_list_screen.dart b/lib/ui/screens/conversations_list_screen.dart index c318c43..52a2e8c 100644 --- a/lib/ui/screens/conversations_list_screen.dart +++ b/lib/ui/screens/conversations_list_screen.dart @@ -8,7 +8,6 @@ import 'package:comunic/lists/groups_list.dart'; import 'package:comunic/lists/users_list.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; -import 'package:comunic/ui/routes/update_conversation_route.dart'; import 'package:comunic/ui/screens/create_conversation_screen.dart'; import 'package:comunic/ui/tiles/conversation_tile.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; @@ -122,11 +121,7 @@ class _ConversationScreenState extends SafeState { /// Handle conversations updated requests void _updateConversation(Conversation conversation) { - MainController.of(context).push( - UpdateConversationRoute( - conversationID: conversation.id, - ), - ); + MainController.of(context).openConversationSettingsRoute(conversation); } /// Handle conversation deletion request diff --git a/lib/ui/screens/group_sections/group_conversation_section.dart b/lib/ui/screens/group_sections/group_conversation_section.dart new file mode 100644 index 0000000..d615f8b --- /dev/null +++ b/lib/ui/screens/group_sections/group_conversation_section.dart @@ -0,0 +1,36 @@ +import 'package:comunic/models/conversation.dart'; +import 'package:comunic/ui/routes/main_route/main_route.dart'; +import 'package:flutter/material.dart'; + +import '../conversation_screen.dart'; + +/// Group conversation section +/// +/// @author Pierre Hubert + +class GroupConversationSection extends StatelessWidget { + final Conversation conv; + + const GroupConversationSection({ + Key key, + @required this.conv, + }) : assert(conv != null), + super(key: key); + + @override + Widget build(BuildContext context) => Stack( + children: [ + ConversationScreen( + conversationID: conv.id, + ), + Positioned( + right: 1.0, + child: IconButton( + icon: Icon(Icons.settings), + onPressed: () => MainController.of(context) + .openConversationSettingsRoute(conv), + ), + ) + ], + ); +} diff --git a/lib/ui/screens/update_conversation_screen.dart b/lib/ui/screens/update_conversation_screen.dart index c45e681..56482c4 100644 --- a/lib/ui/screens/update_conversation_screen.dart +++ b/lib/ui/screens/update_conversation_screen.dart @@ -68,6 +68,9 @@ class _UpdateConversationScreen extends State { get isAdmin => !isUpdating || _conversation.isAdmin; + bool get _isGroupConversation => + isUpdating && _conversation.isGroupConversation; + bool get _canAddMembers => (isAdmin || _conversation.canEveryoneAddMembers) && (!isUpdating || !_conversation.isManaged); @@ -122,6 +125,10 @@ class _UpdateConversationScreen extends State { padding: EdgeInsets.all(8.0), child: Column( children: [ + _isGroupConversation + ? Text(tr("This conversation is managed by a group")) + : Container(), + // Conversation name TextField( controller: _nameController, @@ -161,21 +168,23 @@ class _UpdateConversationScreen extends State { ), // Allow every members of the conversation to add users ? - Row( - children: [ - Switch.adaptive( - value: _canEveryoneAddMembers, - onChanged: isAdmin - ? (b) => setState(() { - _canEveryoneAddMembers = b; - }) - : null, - ), - Flexible( - child: Text(tr( - "Allow all members of the conversation to add users"))) - ], - ), + _isGroupConversation + ? Container() + : Row( + children: [ + Switch.adaptive( + value: _canEveryoneAddMembers, + onChanged: isAdmin + ? (b) => setState(() { + _canEveryoneAddMembers = b; + }) + : null, + ), + Flexible( + child: Text(tr( + "Allow all members of the conversation to add users"))) + ], + ), // Add a member to the conversation PickUserWidget(