1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Start to build group settings screen

This commit is contained in:
Pierre HUBERT 2020-05-01 15:12:55 +02:00
parent 0bb9be9a72
commit 257523b526
4 changed files with 111 additions and 1 deletions

View File

@ -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<AdvancedGroupInfo> 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<String, dynamic> map) {
return Group(

View File

@ -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 ||

View File

@ -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<AuthorizedGroupPageScreen> {
),
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<AuthorizedGroupPageScreen> {
buildListView: false,
);
}
/// Handles menu selection
void _handleMenuSelection(_MenuItems item) {
switch (item) {
case _MenuItems.OPEN_SETTINGS:
MainController.of(context)
.push(GroupSettingsScreen(groupID: _group.id));
break;
}
}
}

View File

@ -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<GroupSettingsScreen> {
AdvancedGroupInfo _groupSettings;
Future<void> _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(),
),
],
);
}
}