From c4790635df61e0e2f33ab97a58e1bcd4ac374137 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 24 Apr 2021 10:14:56 +0200 Subject: [PATCH] Load group information --- lib/forez/helpers/forez_group_helper.dart | 14 ++++++++++++++ lib/forez/main_forez_dev.dart | 2 ++ lib/forez/ui/routes/forez_route.dart | 5 +++-- lib/models/config.dart | 4 ++++ lib/ui/screens/conversations_list_screen.dart | 7 +++++-- lib/ui/widgets/init_widget.dart | 3 +++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/forez/helpers/forez_group_helper.dart b/lib/forez/helpers/forez_group_helper.dart index dade2bc..bcb6a90 100644 --- a/lib/forez/helpers/forez_group_helper.dart +++ b/lib/forez/helpers/forez_group_helper.dart @@ -1,4 +1,6 @@ +import 'package:comunic/helpers/groups_helper.dart'; import 'package:comunic/helpers/preferences_helper.dart'; +import 'package:comunic/models/advanced_group_info.dart'; /// Forez group helper /// @@ -6,6 +8,8 @@ import 'package:comunic/helpers/preferences_helper.dart'; /// /// @author Pierre Hubert +AdvancedGroupInfo _forezGroup; + class ForezGroupHelper { static Future setId(int groupID) async { (await PreferencesHelper.getInstance()) @@ -16,4 +20,14 @@ class ForezGroupHelper { return (await PreferencesHelper.getInstance()) .getInt(PreferencesKeyList.FOREZ_GROUP); } + + static Future refreshInfo() async { + final res = await GroupsHelper().getAdvancedInfo(await getId()); + assert(res.status == GetAdvancedInfoStatus.SUCCESS); + _forezGroup = res.info; + } + + static AdvancedGroupInfo getGroup() => _forezGroup; } + +AdvancedGroupInfo get forezGroup => ForezGroupHelper.getGroup(); diff --git a/lib/forez/main_forez_dev.dart b/lib/forez/main_forez_dev.dart index 3c1535a..605d00e 100644 --- a/lib/forez/main_forez_dev.dart +++ b/lib/forez/main_forez_dev.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:comunic/forez/helpers/forez_group_helper.dart'; import 'package:comunic/forez/tour/forez_tour_builder.dart'; import 'package:comunic/forez/ui/routes/forez_route.dart'; import 'package:comunic/main.dart'; @@ -34,6 +35,7 @@ void main() { appName: "#Forez", appQuickDescription: tr("Events organisation in Forez plain"), toursEntriesBuilder: buildTour, + additionalLoading: () => ForezGroupHelper.refreshInfo(), mainRouteBuilder: (c, k) => ForezRoute(key: k), )); diff --git a/lib/forez/ui/routes/forez_route.dart b/lib/forez/ui/routes/forez_route.dart index c22cbba..88ce800 100644 --- a/lib/forez/ui/routes/forez_route.dart +++ b/lib/forez/ui/routes/forez_route.dart @@ -1,3 +1,4 @@ +import 'package:comunic/forez/helpers/forez_group_helper.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/dialogs/alert_dialog.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; @@ -74,7 +75,7 @@ class _ForezRouteBodyState extends SafeState { length: _tabs.length, child: Scaffold( appBar: AppBar( - title: Text("#Forez"), + title: Text(forezGroup.name), actions: [_buildPopupMenuButton()], bottom: TabBar(tabs: _tabs), ), @@ -103,7 +104,7 @@ class _ForezRouteBodyState extends SafeState { MainController.of(context).openSettings(); break; case _PopupMenuItems.ACTION_SIGN_OUT: - // TODO : handle logout + MainController.of(context).requestLogout(); break; } } diff --git a/lib/models/config.dart b/lib/models/config.dart index e9cde97..208881e 100644 --- a/lib/models/config.dart +++ b/lib/models/config.dart @@ -27,6 +27,9 @@ class Config { // Entries for the welcome tour final TourEntriesBuilder toursEntriesBuilder; + // Custom initialization + final Future Function() additionalLoading; + // Custom main application route final Widget Function(BuildContext, GlobalKey) mainRouteBuilder; @@ -41,6 +44,7 @@ class Config { this.appName = "Comunic", this.appQuickDescription, this.toursEntriesBuilder, + this.additionalLoading, this.mainRouteBuilder, }) : assert(apiServerName != null), assert(apiServerUri != null), diff --git a/lib/ui/screens/conversations_list_screen.dart b/lib/ui/screens/conversations_list_screen.dart index 52a2e8c..fa7cd73 100644 --- a/lib/ui/screens/conversations_list_screen.dart +++ b/lib/ui/screens/conversations_list_screen.dart @@ -114,8 +114,11 @@ class _ConversationScreenState extends SafeState { /// Create a new conversation void _createConversation() { - MainController.of(context) - .push(CreateConversationScreen(), canShowAsDialog: true); + MainController.of(context).push( + CreateConversationScreen(), + canShowAsDialog: true, + hideNavBar: true, + ); if (widget.onOpen != null) widget.onOpen(); } diff --git a/lib/ui/widgets/init_widget.dart b/lib/ui/widgets/init_widget.dart index d66c868..206a93c 100644 --- a/lib/ui/widgets/init_widget.dart +++ b/lib/ui/widgets/init_widget.dart @@ -90,6 +90,9 @@ class _InitializeWidgetState extends SafeState { print("Attempting WebSocket connection..."); + if (config().additionalLoading != null) + await config().additionalLoading(); + setState(() {}); } catch (e, stack) { print("Could not connect to server! $e");