1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/ui/screens/authorized_group_page_screen.dart

130 lines
3.7 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-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-04-16 07:07:23 +00:00
import 'package:comunic/ui/widgets/scroll_watcher.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
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
// 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();
}
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(),
child: ListView(
2020-04-16 07:07:23 +00:00
controller: _postsController,
2020-04-16 06:52:26 +00:00
children: <Widget>[
_buildGroupPageHeader(),
_buildPostCreationArea(),
_buildGroupPagePostsList()
],
2020-04-16 06:43:41 +00:00
),
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-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,
onCreated: () => widget.needRefresh());
}
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-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-04-16 06:43:41 +00:00
buildListView: false,
2020-04-16 06:24:34 +00:00
);
}
2020-04-15 16:23:38 +00:00
}