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

215 lines
6.3 KiB
Dart
Raw Normal View History

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';
2021-03-16 18:01:50 +00:00
import 'package:comunic/ui/screens/group_sections/about_group_section.dart';
2021-04-22 13:15:40 +00:00
import 'package:comunic/ui/screens/group_sections/forez_presence_section.dart';
2021-04-06 16:41:51 +00:00
import 'package:comunic/ui/screens/group_sections/group_conversation_section.dart';
2021-03-16 17:41:16 +00:00
import 'package:comunic/ui/screens/group_sections/group_members_screen.dart';
2021-03-16 17:36:17 +00:00
import 'package:comunic/ui/screens/group_sections/group_posts_section.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';
2021-03-16 18:14:49 +00:00
import 'package:comunic/ui/widgets/post_container_widget.dart';
2021-03-16 17:27:02 +00:00
import 'package:comunic/ui/widgets/safe_state.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
2021-03-16 17:27:02 +00:00
Color get _headerTextColor => Colors.white;
Color get _headerColor => Colors.blueAccent.shade700;
2020-04-15 16:23:38 +00:00
class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo;
final int? conversationID;
2020-04-15 16:23:38 +00:00
final Function() needRefresh;
const AuthorizedGroupPageScreen({
Key? key,
required this.advancedGroupInfo,
required this.conversationID,
required this.needRefresh,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2020-04-15 16:23:38 +00:00
@override
_AuthorizedGroupPageScreenState createState() =>
_AuthorizedGroupPageScreenState();
}
2021-03-16 17:27:02 +00:00
class _AuthorizedGroupPageScreenState
extends SafeState<AuthorizedGroupPageScreen>
with SingleTickerProviderStateMixin {
2020-04-15 16:23:38 +00:00
AdvancedGroupInfo get _group => widget.advancedGroupInfo;
TabController? _tabController;
2021-03-16 17:27:02 +00:00
List<_GroupPageTab> get _tabs => [
2021-03-16 17:36:17 +00:00
// Posts list
_GroupPageTab(
2021-03-17 15:58:10 +00:00
widget: (c) => GroupPostsSection(group: _group),
label: tr("Posts")!,
2021-03-16 17:36:17 +00:00
),
2021-03-16 18:01:50 +00:00
2021-04-22 13:15:40 +00:00
// Forez presence tab
_GroupPageTab(
2021-04-22 13:41:35 +00:00
widget: (c) => ForezPresenceSection(groupID: _group.id),
label: tr("Presence")!,
2021-04-22 13:15:40 +00:00
visible: _group.isForezGroup,
),
2021-03-16 18:01:50 +00:00
// About the group
_GroupPageTab(
2021-03-17 15:58:10 +00:00
widget: (c) => AboutGroupSection(group: _group),
label: tr("About")!,
),
_GroupPageTab(
widget: (c) => GroupMembersSection(groupID: _group.id),
label: tr("Members")!,
visible: _group.isAtLeastModerator || _group.isMembersListPublic!,
2021-03-16 18:01:50 +00:00
)
2021-04-06 16:11:44 +00:00
].where((element) => element.visible).toList()
// Add group conversations
..insertAll(
2021-04-30 16:35:11 +00:00
(_group.isForezGroup ? 2 : 1),
_group.conversations!
2021-04-06 16:11:44 +00:00
.map((e) => _GroupPageTab(
2021-04-06 16:41:51 +00:00
widget: (c) => GroupConversationSection(conv: e),
label: e.name!))
2021-04-06 16:11:44 +00:00
.toList());
2021-03-16 17:27:02 +00:00
@override
void initState() {
_tabController = TabController(
length: _tabs.length,
2021-04-06 16:22:45 +00:00
initialIndex: widget.conversationID == null
? 0
2021-04-27 07:47:24 +00:00
: (_group.isForezGroup ? 2 : 1) +
_group.conversations!
2021-04-06 16:22:45 +00:00
.indexWhere((element) => element.id == widget.conversationID),
2021-03-16 17:27:02 +00:00
vsync: this,
);
super.initState();
}
@override
void dispose() {
_tabController!.dispose();
2021-03-16 17:27:02 +00:00
super.dispose();
}
2020-04-15 16:23:38 +00:00
@override
Widget build(BuildContext context) {
2021-03-16 18:14:49 +00:00
return PostContainer(
child: Column(
children: [
_buildGroupPageHeader(),
2021-04-07 14:16:33 +00:00
Row(
children: [
Expanded(
child: Material(
color: _headerColor,
child: TabBar(
isScrollable: true,
tabs: _tabs.map((e) => e.tab).toList(),
controller: _tabController,
),
),
),
],
2021-03-16 17:27:02 +00:00
),
2021-03-16 18:14:49 +00:00
Expanded(
child: TabBarView(
controller: _tabController,
2021-03-17 15:58:10 +00:00
children: _tabs.map((e) => e.widget(context)).toList(),
2021-03-16 18:14:49 +00:00
),
2021-03-16 17:27:02 +00:00
),
2021-03-16 18:14:49 +00:00
],
),
2020-04-15 16:23:38 +00:00
);
}
/// Build group page header
2020-04-16 06:24:34 +00:00
Widget _buildGroupPageHeader() {
2021-03-16 17:36:17 +00:00
return Material(
color: _headerColor,
child: DefaultTextStyle(
style: TextStyle(color: _headerTextColor),
2021-03-16 17:27:02 +00:00
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
GroupIcon(
group: _group,
2021-03-16 16:43:24 +00:00
),
2021-03-16 17:27:02 +00:00
Expanded(
child: Text(
" ${_group.displayName}",
style: TextStyle(fontSize: 20),
2020-04-16 06:52:26 +00:00
),
2021-03-16 17:27:02 +00:00
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GroupMembershipWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 4,
),
GroupFollowingWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
inactiveColor: Colors.blueAccent,
activeColor: Colors.white,
),
Container(
height: 2,
),
LikeWidget(
inativeColor: Colors.blueAccent,
activeColor: Colors.white,
likeElement: _group,
),
],
),
2021-03-16 17:36:17 +00:00
// Settings button
_group.isAdmin
? IconButton(
icon: Icon(Icons.settings, color: _headerTextColor),
onPressed: () => MainController.of(context)!.push(
2021-03-16 18:14:49 +00:00
GroupSettingsScreen(groupID: _group.id),
canShowAsDialog: true))
2021-03-16 17:36:17 +00:00
: Container(),
2021-03-16 17:27:02 +00:00
],
),
2020-04-16 06:52:26 +00:00
),
2020-04-15 16:23:38 +00:00
),
);
}
}
2021-03-16 17:27:02 +00:00
class _GroupPageTab {
2021-03-17 15:58:10 +00:00
final WidgetBuilder widget;
final bool visible;
2021-03-16 17:27:02 +00:00
final String label;
const _GroupPageTab({
required this.widget,
this.visible = true,
required this.label,
2022-03-11 16:02:06 +00:00
});
2021-03-16 17:27:02 +00:00
Tab get tab => Tab(text: label);
}