mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
166 lines
5.0 KiB
Dart
166 lines
5.0 KiB
Dart
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/main_route.dart';
|
|
import 'package:comunic/ui/screens/group_members_screen.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';
|
|
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
|
|
///
|
|
/// 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 }
|
|
|
|
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;
|
|
|
|
// Allows load older posts when we reach the bottom of the page
|
|
final _postsKey = GlobalKey<PostsListWidgetState>();
|
|
ScrollWatcher _postsController;
|
|
|
|
@override
|
|
void initState() {
|
|
_postsController = ScrollWatcher(
|
|
onReachBottom: () => _postsKey.currentState.reachedPostsBottom());
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RefreshIndicator(
|
|
onRefresh: () => widget.needRefresh(),
|
|
child: ListView(
|
|
physics: AlwaysScrollableScrollPhysics(),
|
|
controller: _postsController,
|
|
children: <Widget>[
|
|
_buildGroupPageHeader(),
|
|
_buildPostCreationArea(),
|
|
_buildGroupPagePostsList()
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Build group page header
|
|
Widget _buildGroupPageHeader() {
|
|
return Container(
|
|
color: Colors.black26,
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
PopupMenuButton<_MenuItems>(
|
|
itemBuilder: (c) => [
|
|
PopupMenuItem(
|
|
child: Text(tr("Group members")),
|
|
value: _MenuItems.OPEN_MEMBERS,
|
|
enabled: _group.isAtLeastModerator,
|
|
),
|
|
PopupMenuItem(
|
|
child: Text(tr("Group settings")),
|
|
value: _MenuItems.OPEN_SETTINGS,
|
|
enabled: _group.isAdmin,
|
|
),
|
|
],
|
|
onSelected: _handleMenuSelection,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Add create post target
|
|
Widget _buildPostCreationArea() {
|
|
if (!_group.canCreatePost) return Container();
|
|
|
|
return PostCreateFormWidget(
|
|
postTarget: PostTarget.GROUP_PAGE,
|
|
targetID: _group.id,
|
|
onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false));
|
|
}
|
|
|
|
/// Build the list of posts of the group
|
|
Widget _buildGroupPagePostsList() {
|
|
return PostsListWidget(
|
|
key: _postsKey,
|
|
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
|
|
showPostsTarget: false,
|
|
userNamesClickable: true,
|
|
getOlder: (from) => PostsHelper().getGroupPosts(_group.id, from: from),
|
|
buildListView: false,
|
|
);
|
|
}
|
|
|
|
/// Handles menu selection
|
|
void _handleMenuSelection(_MenuItems item) {
|
|
switch (item) {
|
|
case _MenuItems.OPEN_MEMBERS:
|
|
MainController.of(context).push(GroupMembersScreen(groupID: _group.id));
|
|
break;
|
|
|
|
case _MenuItems.OPEN_SETTINGS:
|
|
MainController.of(context)
|
|
.push(GroupSettingsScreen(groupID: _group.id));
|
|
break;
|
|
}
|
|
}
|
|
}
|