1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-30 14:58:52 +00:00
comunicmobile/lib/ui/screens/authorized_group_page_screen.dart

151 lines
4.5 KiB
Dart
Raw Normal View History

2020-04-16 06:52:26 +00:00
import 'package:comunic/enums/post_target.dart';
2020-04-16 06:24:34 +00:00
import 'package:comunic/helpers/posts_helper.dart';
2020-04-15 16:23:38 +00:00
import 'package:comunic/models/advanced_group_info.dart';
2020-05-05 11:21:37 +00:00
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/screens/group_members_screen.dart';
2020-05-01 13:12:55 +00:00
import 'package:comunic/ui/screens/group_settings_screen.dart';
2020-04-15 16:39:07 +00:00
import 'package:comunic/ui/widgets/group_following_widget.dart';
2020-04-15 16:23:38 +00:00
import 'package:comunic/ui/widgets/group_icon_widget.dart';
import 'package:comunic/ui/widgets/group_membership_widget.dart';
2020-04-15 17:23:08 +00:00
import 'package:comunic/ui/widgets/like_widget.dart';
2020-04-16 06:52:26 +00:00
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
2020-04-16 06:24:34 +00:00
import 'package:comunic/ui/widgets/posts_list_widget.dart';
2020-05-01 13:12:55 +00:00
import 'package:comunic/utils/intl_utils.dart';
2020-04-15 16:23:38 +00:00
import 'package:flutter/material.dart';
/// Authorized group page screen
///
/// This screen is shown when the user is allowed to access to a group's page
///
/// @author Pierre Hubert
enum _MenuItems { OPEN_MEMBERS, OPEN_SETTINGS }
2020-05-01 13:12:55 +00:00
2020-04-15 16:23:38 +00:00
class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo;
final Function() needRefresh;
const AuthorizedGroupPageScreen({
Key key,
@required this.advancedGroupInfo,
@required this.needRefresh,
}) : assert(advancedGroupInfo != null),
assert(needRefresh != null),
super(key: key);
@override
_AuthorizedGroupPageScreenState createState() =>
_AuthorizedGroupPageScreenState();
}
class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
AdvancedGroupInfo get _group => widget.advancedGroupInfo;
2020-04-16 07:07:23 +00:00
final _postsKey = GlobalKey<PostsListWidgetState>();
2020-04-15 16:23:38 +00:00
@override
Widget build(BuildContext context) {
2020-04-16 06:43:41 +00:00
return RefreshIndicator(
onRefresh: () => widget.needRefresh(),
2020-05-08 07:44:41 +00:00
child: _buildGroupPagePostsList(),
2020-04-15 16:23:38 +00:00
);
}
/// Build group page header
2020-04-16 06:24:34 +00:00
Widget _buildGroupPageHeader() {
2020-04-16 06:52:26 +00:00
return Container(
2020-04-16 06:58:56 +00:00
color: Colors.black26,
2020-04-16 06:52:26 +00:00
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
GroupIcon(
group: _group,
),
Text(
" ${_group.displayName}",
style: TextStyle(fontSize: 20),
),
Spacer(),
Column(
children: <Widget>[
GroupMembershipWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 4,
),
GroupFollowingWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 2,
),
LikeWidget(
likeElement: _group,
2020-05-01 13:12:55 +00:00
),
],
),
PopupMenuButton<_MenuItems>(
itemBuilder: (c) => [
PopupMenuItem(
child: Text(tr("Group members")),
value: _MenuItems.OPEN_MEMBERS,
enabled: _group.isAtLeastModerator,
),
2020-05-01 13:12:55 +00:00
PopupMenuItem(
child: Text(tr("Group settings")),
value: _MenuItems.OPEN_SETTINGS,
enabled: _group.isAdmin,
),
2020-04-16 06:52:26 +00:00
],
2020-05-01 13:12:55 +00:00
onSelected: _handleMenuSelection,
),
2020-04-16 06:52:26 +00:00
],
),
2020-04-15 16:23:38 +00:00
),
);
}
2020-04-16 06:24:34 +00:00
2020-04-16 06:52:26 +00:00
/// Add create post target
Widget _buildPostCreationArea() {
if (!_group.canCreatePost) return Container();
return PostCreateFormWidget(
postTarget: PostTarget.GROUP_PAGE,
targetID: _group.id,
2020-04-17 08:37:02 +00:00
onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false));
2020-04-16 06:52:26 +00:00
}
2020-04-16 06:24:34 +00:00
/// Build the list of posts of the group
Widget _buildGroupPagePostsList() {
return PostsListWidget(
2020-04-16 07:07:23 +00:00
key: _postsKey,
2020-05-08 07:44:41 +00:00
topWidgets: <Widget>[
_buildGroupPageHeader(),
_buildPostCreationArea(),
],
2020-04-16 06:24:34 +00:00
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
showPostsTarget: false,
userNamesClickable: true,
getOlder: (from) => PostsHelper().getGroupPosts(_group.id, from: from),
);
}
2020-05-01 13:12:55 +00:00
/// Handles menu selection
void _handleMenuSelection(_MenuItems item) {
switch (item) {
case _MenuItems.OPEN_MEMBERS:
MainController.of(context).push(GroupMembersScreen(groupID: _group.id));
break;
2020-05-01 13:12:55 +00:00
case _MenuItems.OPEN_SETTINGS:
MainController.of(context)
.push(GroupSettingsScreen(groupID: _group.id));
break;
}
}
2020-04-15 16:23:38 +00:00
}