diff --git a/lib/helpers/groups_helper.dart b/lib/helpers/groups_helper.dart index fdcbd0e..8d17395 100644 --- a/lib/helpers/groups_helper.dart +++ b/lib/helpers/groups_helper.dart @@ -177,6 +177,21 @@ class GroupsHelper { } } + /// Get group settings + /// + /// This function is currently a kind of alias, but it might + /// change in the future + /// + /// Throws in case of error + Future getSettings(int groupID) async { + final groupInfo = await getAdvancedInfo(groupID); + + if (groupInfo.status != GetAdvancedInfoStatus.SUCCESS) + throw Exception("Could not get group information!"); + + return groupInfo.info; + } + /// Turn an API entry into a group object Group _getGroupFromAPI(Map map) { return Group( diff --git a/lib/models/group.dart b/lib/models/group.dart index 07b05dd..381543b 100644 --- a/lib/models/group.dart +++ b/lib/models/group.dart @@ -59,6 +59,8 @@ class Group { membershipLevel == GroupMembershipLevel.MODERATOR || membershipLevel == GroupMembershipLevel.MEMBER; + bool get isAdmin => membershipLevel == GroupMembershipLevel.ADMINISTRATOR; + bool get canCreatePost => membershipLevel == GroupMembershipLevel.ADMINISTRATOR || membershipLevel == GroupMembershipLevel.MODERATOR || diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index d5580ab..1497529 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -1,6 +1,8 @@ import 'package:comunic/enums/post_target.dart'; import 'package:comunic/helpers/posts_helper.dart'; import 'package:comunic/models/advanced_group_info.dart'; +import 'package:comunic/ui/routes/main_route.dart'; +import 'package:comunic/ui/screens/group_settings_screen.dart'; import 'package:comunic/ui/widgets/group_following_widget.dart'; import 'package:comunic/ui/widgets/group_icon_widget.dart'; import 'package:comunic/ui/widgets/group_membership_widget.dart'; @@ -8,6 +10,7 @@ import 'package:comunic/ui/widgets/like_widget.dart'; import 'package:comunic/ui/widgets/post_create_form_widget.dart'; import 'package:comunic/ui/widgets/posts_list_widget.dart'; import 'package:comunic/ui/widgets/scroll_watcher.dart'; +import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; /// Authorized group page screen @@ -16,6 +19,8 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert +enum _MenuItems { OPEN_SETTINGS } + class AuthorizedGroupPageScreen extends StatefulWidget { final AdvancedGroupInfo advancedGroupInfo; final Function() needRefresh; @@ -97,9 +102,19 @@ class _AuthorizedGroupPageScreenState extends State { ), LikeWidget( likeElement: _group, + ), + ], + ), + PopupMenuButton<_MenuItems>( + itemBuilder: (c) => [ + PopupMenuItem( + child: Text(tr("Group settings")), + value: _MenuItems.OPEN_SETTINGS, + enabled: _group.isAdmin, ) ], - ) + onSelected: _handleMenuSelection, + ), ], ), ), @@ -127,4 +142,14 @@ class _AuthorizedGroupPageScreenState extends State { buildListView: false, ); } + + /// Handles menu selection + void _handleMenuSelection(_MenuItems item) { + switch (item) { + case _MenuItems.OPEN_SETTINGS: + MainController.of(context) + .push(GroupSettingsScreen(groupID: _group.id)); + break; + } + } } diff --git a/lib/ui/screens/group_settings_screen.dart b/lib/ui/screens/group_settings_screen.dart new file mode 100644 index 0000000..4abcae4 --- /dev/null +++ b/lib/ui/screens/group_settings_screen.dart @@ -0,0 +1,68 @@ +import 'package:comunic/helpers/groups_helper.dart'; +import 'package:comunic/models/advanced_group_info.dart'; +import 'package:comunic/ui/widgets/async_screen_widget.dart'; +import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; +import 'package:comunic/ui/widgets/safe_state.dart'; +import 'package:comunic/utils/intl_utils.dart'; +import 'package:flutter/material.dart'; +import 'package:settings_ui/settings_ui.dart'; + +/// Groups settings screen +/// +/// @author Pierre Hubert + +class GroupSettingsScreen extends StatefulWidget { + final int groupID; + + const GroupSettingsScreen({Key key, @required this.groupID}) + : assert(groupID != null), + super(key: key); + + @override + _GroupSettingsScreenState createState() => _GroupSettingsScreenState(); +} + +class _GroupSettingsScreenState extends SafeState { + AdvancedGroupInfo _groupSettings; + + Future _refresh() async { + _groupSettings = await GroupsHelper().getSettings(widget.groupID); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + leading: ComunicBackButton(), + title: Text(tr("Group settings")), + ), + body: _buildBody(), + ); + } + + Widget _buildBody() { + return AsyncScreenWidget( + onReload: _refresh, + onBuild: _buildContent, + errorMessage: tr("Could not get group settings!"), + ); + } + + Widget _buildContent() { + return SettingsList( + sections: [_buildGeneralSection()], + ); + } + + Widget _buildGeneralSection() { + return SettingsSection( + title: tr("General information"), + tiles: [ + SettingsTile( + title: tr("Group ID"), + subtitle: _groupSettings.id.toString(), + ), + ], + ); + } +}