2021-04-24 08:14:56 +00:00
|
|
|
import 'package:comunic/forez/helpers/forez_group_helper.dart';
|
2021-04-26 07:33:54 +00:00
|
|
|
import 'package:comunic/forez/ui/routes/forez_member_profile_route.dart';
|
2021-04-25 15:06:28 +00:00
|
|
|
import 'package:comunic/forez/ui/screens/forez_directory_screen.dart';
|
2021-04-24 08:35:12 +00:00
|
|
|
import 'package:comunic/helpers/events_helper.dart';
|
2021-04-24 07:16:29 +00:00
|
|
|
import 'package:comunic/models/conversation.dart';
|
|
|
|
import 'package:comunic/ui/dialogs/alert_dialog.dart';
|
|
|
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
|
|
|
import 'package:comunic/ui/routes/main_route/page_info.dart';
|
2021-04-24 07:46:53 +00:00
|
|
|
import 'package:comunic/ui/screens/conversations_list_screen.dart';
|
2021-04-24 08:17:18 +00:00
|
|
|
import 'package:comunic/ui/screens/group_sections/forez_presence_section.dart';
|
2021-04-24 08:21:24 +00:00
|
|
|
import 'package:comunic/ui/screens/group_sections/group_posts_section.dart';
|
2021-12-30 11:32:50 +00:00
|
|
|
import 'package:comunic/ui/widgets/banner_widget.dart';
|
2021-04-24 07:46:53 +00:00
|
|
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
|
|
|
import 'package:comunic/ui/widgets/status_widget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/tab_transition_widget.dart';
|
2021-04-24 07:16:29 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Forez route
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class ForezRoute extends StatefulWidget implements MainRoute {
|
2022-03-10 18:39:57 +00:00
|
|
|
const ForezRoute({Key? key}) : super(key: key);
|
2021-04-24 07:16:29 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _MainRouteState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Private implementation of HomeController
|
|
|
|
class _MainRouteState extends MainController {
|
2021-04-24 08:47:13 +00:00
|
|
|
final GlobalKey<_ForezRouteBodyState> _mainKey = GlobalKey();
|
|
|
|
|
2021-04-24 07:16:29 +00:00
|
|
|
@override
|
|
|
|
PageInfo get defaultPage => PageInfo(
|
2021-04-24 08:47:13 +00:00
|
|
|
type: PageType.OTHER_PAGE,
|
|
|
|
child: ForezRouteBody(key: _mainKey),
|
|
|
|
hideNavBar: true,
|
|
|
|
);
|
2021-04-24 07:16:29 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-10 18:39:57 +00:00
|
|
|
if (forezGroup == null) return Text(tr("Missing Forez group!")!);
|
2021-04-24 08:57:10 +00:00
|
|
|
|
2021-04-24 07:46:53 +00:00
|
|
|
return StatusWidget(
|
|
|
|
child: (c) => SafeArea(
|
2021-04-24 07:16:29 +00:00
|
|
|
// Avoid OS areas
|
|
|
|
child: WillPopScope(
|
|
|
|
onWillPop: willPop,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: currentPage.hideNavBar ? null : AppBar(),
|
|
|
|
body: SafeArea(key: currentPage.key, child: currentPage.child),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-25 15:55:39 +00:00
|
|
|
@override
|
|
|
|
void pushPage(PageInfo page) {
|
|
|
|
if (page.hideNavBar)
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (c) => page.child));
|
|
|
|
else
|
|
|
|
super.pushPage(page);
|
|
|
|
}
|
|
|
|
|
2021-04-24 07:16:29 +00:00
|
|
|
@override
|
|
|
|
void openConversation(Conversation conv, {fullScreen: false}) {
|
|
|
|
// Forcefully open conversations in a "normal" way (do not display groups)
|
2022-03-10 18:39:57 +00:00
|
|
|
openConversationById(conv.id!, fullScreen: fullScreen);
|
2021-04-24 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-03-10 18:39:57 +00:00
|
|
|
void openGroup(int groupID, {int? conversationID}) => _unsupportedFeature();
|
2021-04-25 15:55:39 +00:00
|
|
|
|
|
|
|
@override
|
2021-04-26 07:33:54 +00:00
|
|
|
void openUserPage(int userID) => pushPage(PageInfo(
|
|
|
|
child: ForezMemberProfileRoute(userID: userID),
|
|
|
|
hideNavBar: true,
|
|
|
|
canShowAsDialog: true,
|
|
|
|
type: PageType.USER_PAGE,
|
|
|
|
id: userID,
|
|
|
|
));
|
2021-04-25 15:55:39 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void openFriendsList() => _unsupportedFeature();
|
|
|
|
|
|
|
|
void _unsupportedFeature() => alert(context,
|
|
|
|
tr("This feature is available only in the Comunic application!"));
|
2021-04-24 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 07:46:53 +00:00
|
|
|
enum _PopupMenuItems { ACTION_SETTINGS, ACTION_SIGN_OUT }
|
|
|
|
|
2021-04-24 07:16:29 +00:00
|
|
|
class ForezRouteBody extends StatefulWidget {
|
2022-03-10 18:39:57 +00:00
|
|
|
ForezRouteBody({Key? key}) : super(key: key);
|
2021-04-24 08:47:13 +00:00
|
|
|
|
2021-04-24 07:16:29 +00:00
|
|
|
@override
|
|
|
|
_ForezRouteBodyState createState() => _ForezRouteBodyState();
|
|
|
|
}
|
|
|
|
|
2021-04-24 07:46:53 +00:00
|
|
|
class _ForezRouteBodyState extends SafeState<ForezRouteBody> {
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-04-24 08:35:12 +00:00
|
|
|
|
|
|
|
listenChangeState<NewNumberUnreadConversations>((event) {});
|
2021-04-24 07:46:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 07:16:29 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-04-24 07:46:53 +00:00
|
|
|
return DefaultTabController(
|
|
|
|
length: _tabs.length,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(forezGroup!.name),
|
2021-04-24 07:46:53 +00:00
|
|
|
actions: <Widget>[_buildPopupMenuButton()],
|
|
|
|
bottom: TabBar(tabs: _tabs),
|
|
|
|
),
|
2021-12-30 11:32:50 +00:00
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
BannerWidget(),
|
|
|
|
Expanded(child: TabBarView(children: _tabsPages)),
|
|
|
|
],
|
|
|
|
),
|
2021-04-24 07:46:53 +00:00
|
|
|
),
|
|
|
|
);
|
2021-04-24 07:16:29 +00:00
|
|
|
}
|
2021-04-24 07:46:53 +00:00
|
|
|
|
|
|
|
Widget _buildPopupMenuButton() => PopupMenuButton<_PopupMenuItems>(
|
|
|
|
itemBuilder: (c) => [
|
|
|
|
PopupMenuItem(
|
2022-03-10 18:39:57 +00:00
|
|
|
child: Text(tr("Settings")!),
|
2021-04-24 07:46:53 +00:00
|
|
|
value: _PopupMenuItems.ACTION_SETTINGS,
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
2022-03-10 18:39:57 +00:00
|
|
|
child: Text(tr("Sign out")!),
|
2021-04-24 07:46:53 +00:00
|
|
|
value: _PopupMenuItems.ACTION_SIGN_OUT,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
onSelected: _onMenuSelection,
|
|
|
|
);
|
|
|
|
|
|
|
|
void _onMenuSelection(_PopupMenuItems value) {
|
|
|
|
switch (value) {
|
|
|
|
case _PopupMenuItems.ACTION_SETTINGS:
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.openSettings();
|
2021-04-24 07:46:53 +00:00
|
|
|
break;
|
|
|
|
case _PopupMenuItems.ACTION_SIGN_OUT:
|
2022-03-10 18:39:57 +00:00
|
|
|
MainController.of(context)!.requestLogout();
|
2021-04-24 07:46:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final _list = <_Tab>[
|
2021-04-24 08:21:24 +00:00
|
|
|
// Posts tab
|
|
|
|
_Tab(
|
|
|
|
icon: Icons.auto_stories,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Posts")!,
|
|
|
|
widget: () => GroupPostsSection(group: forezGroup!),
|
2021-04-24 08:21:24 +00:00
|
|
|
),
|
|
|
|
|
2021-04-24 07:46:53 +00:00
|
|
|
// Presence tab
|
|
|
|
_Tab(
|
|
|
|
icon: Icons.calendar_today,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Presence")!,
|
|
|
|
widget: () => ForezPresenceSection(groupID: forezGroup!.id),
|
2021-04-24 07:46:53 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// Conversations tab
|
|
|
|
_Tab(
|
|
|
|
icon: Icons.question_answer,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Conversations")!,
|
2021-04-24 08:17:18 +00:00
|
|
|
widget: () => ConversationsListScreen(),
|
2022-03-10 18:39:57 +00:00
|
|
|
isUnread: (c) => StatusWidgetState.of(c)!.unreadConversations! > 0,
|
2021-04-24 07:46:53 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// Directory tab
|
|
|
|
_Tab(
|
|
|
|
icon: Icons.import_contacts,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Directory")!,
|
2021-04-25 15:06:28 +00:00
|
|
|
widget: () => ForezDirectoryScreen(),
|
2021-04-24 07:46:53 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
List<Tab> get _tabs => _list
|
|
|
|
.map((e) => Tab(
|
|
|
|
icon: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(e.icon),
|
|
|
|
e.isUnread?.call(context) ?? false
|
|
|
|
? Container(color: Colors.red, width: 10, height: 10)
|
|
|
|
: Container(width: 0)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
text: e.title))
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
List<Widget> get _tabsPages =>
|
2021-04-24 08:17:18 +00:00
|
|
|
_list.map((e) => TabTransitionWidget(e.widget())).toList();
|
2021-04-24 07:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _Tab {
|
|
|
|
final IconData icon;
|
|
|
|
final String title;
|
2021-04-24 08:17:18 +00:00
|
|
|
final Widget Function() widget;
|
2022-03-10 18:39:57 +00:00
|
|
|
final bool Function(BuildContext)? isUnread;
|
2021-04-24 07:46:53 +00:00
|
|
|
|
|
|
|
const _Tab({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.icon,
|
|
|
|
required this.title,
|
|
|
|
required this.widget,
|
2021-04-24 07:46:53 +00:00
|
|
|
this.isUnread,
|
2022-03-11 15:27:01 +00:00
|
|
|
});
|
2021-04-24 07:16:29 +00:00
|
|
|
}
|