From 1fa4ed59d401bb0d68f1deb39c522baa85b8c8c3 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 23 Apr 2021 18:11:17 +0200 Subject: [PATCH] Start to build specific Forez tour --- lib/forez/forez_tour_builder.dart | 21 ++++ lib/{ => forez}/main_forez_dev.dart | 2 + lib/models/config.dart | 5 + .../settings/account_settings_route.dart | 2 +- .../{TourRoute.dart => tour_route.dart} | 95 ++++++++++--------- lib/ui/widgets/init_widget.dart | 2 +- lib/ui/widgets/tour/first_pane.dart | 16 +++- 7 files changed, 91 insertions(+), 52 deletions(-) create mode 100644 lib/forez/forez_tour_builder.dart rename lib/{ => forez}/main_forez_dev.dart (91%) rename lib/ui/routes/{TourRoute.dart => tour_route.dart} (67%) diff --git a/lib/forez/forez_tour_builder.dart b/lib/forez/forez_tour_builder.dart new file mode 100644 index 0000000..87b0390 --- /dev/null +++ b/lib/forez/forez_tour_builder.dart @@ -0,0 +1,21 @@ +import 'package:comunic/ui/routes/tour_route.dart'; +import 'package:comunic/ui/widgets/tour/first_pane.dart'; +import 'package:comunic/ui/widgets/tour/last_pane.dart'; +import 'package:comunic/utils/intl_utils.dart'; +import 'package:flutter/material.dart'; + +/// Forez tour builder +/// +/// Handles the presentation tour for the Forez flavor application +/// +/// @author Pierre Hubert + +List buildTour(TourRouteState state) => [ + FirstTourPane( + msgOne: tr( + "Welcome to #Forez, the central application dedicated to events planning in the Forez plain!"), + msgTwo: tr( + "Let's configure the application and present you some features!"), + ), + LastTourPane(), + ]; diff --git a/lib/main_forez_dev.dart b/lib/forez/main_forez_dev.dart similarity index 91% rename from lib/main_forez_dev.dart rename to lib/forez/main_forez_dev.dart index 5ba45d8..32e14e0 100644 --- a/lib/main_forez_dev.dart +++ b/lib/forez/main_forez_dev.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:comunic/forez/forez_tour_builder.dart'; import 'package:comunic/main.dart'; import 'package:comunic/models/config.dart'; import 'package:comunic/utils/intl_utils.dart'; @@ -29,6 +30,7 @@ void main() { splashBackgroundColor: Colors.green.shade900, appName: "#Forez", appQuickDescription: tr("Events organisation in Forez plain"), + toursEntriesBuilder: buildTour, )); HttpOverrides.global = new MyHttpOverride(); diff --git a/lib/models/config.dart b/lib/models/config.dart index 09bf18e..fc56099 100644 --- a/lib/models/config.dart +++ b/lib/models/config.dart @@ -1,5 +1,6 @@ import 'dart:ui'; +import 'package:comunic/ui/routes/tour_route.dart'; import 'package:meta/meta.dart'; /// Application configuration model @@ -18,6 +19,9 @@ class Config { final String appName; final String appQuickDescription; + // Entries for the welcome tour + final TourEntriesBuilder toursEntriesBuilder; + const Config({ @required this.apiServerName, @required this.apiServerUri, @@ -26,6 +30,7 @@ class Config { this.splashBackgroundColor = defaultColor, this.appName = "Comunic", this.appQuickDescription, + this.toursEntriesBuilder, }) : assert(apiServerName != null), assert(apiServerUri != null), assert(apiServerSecure != null), diff --git a/lib/ui/routes/settings/account_settings_route.dart b/lib/ui/routes/settings/account_settings_route.dart index 29750b9..1f1bc82 100644 --- a/lib/ui/routes/settings/account_settings_route.dart +++ b/lib/ui/routes/settings/account_settings_route.dart @@ -1,4 +1,3 @@ -import 'package:comunic/ui/routes/TourRoute.dart'; import 'package:comunic/ui/routes/settings/account_image_settings.dart'; import 'package:comunic/ui/routes/settings/account_privacy_settings.dart'; import 'package:comunic/ui/routes/settings/account_security_settings.dart'; @@ -6,6 +5,7 @@ import 'package:comunic/ui/routes/settings/application_settings.dart'; import 'package:comunic/ui/routes/settings/custom_emojies_account_settings.dart'; import 'package:comunic/ui/routes/settings/general_account_settings.dart'; import 'package:comunic/ui/routes/settings/notifications_settings.dart'; +import 'package:comunic/ui/routes/tour_route.dart'; import 'package:comunic/ui/widgets/settings/header_spacer_section.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; diff --git a/lib/ui/routes/TourRoute.dart b/lib/ui/routes/tour_route.dart similarity index 67% rename from lib/ui/routes/TourRoute.dart rename to lib/ui/routes/tour_route.dart index f31ddfa..73f6da4 100644 --- a/lib/ui/routes/TourRoute.dart +++ b/lib/ui/routes/tour_route.dart @@ -1,5 +1,6 @@ import 'package:comunic/helpers/preferences_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; +import 'package:comunic/models/config.dart'; import 'package:comunic/models/user.dart'; import 'package:comunic/ui/routes/push_notifications_route.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; @@ -22,14 +23,16 @@ import 'package:flutter/material.dart'; Future showTour(BuildContext context) async => await Navigator.of(context) .push(MaterialPageRoute(builder: (c) => TourRoute())); +typedef TourEntriesBuilder = List Function(TourRouteState); + class TourRoute extends StatefulWidget { @override - _TourRouteState createState() => _TourRouteState(); + TourRouteState createState() => TourRouteState(); } -class _TourRouteState extends State { - final key = GlobalKey(); - final _pushNotificationsKey = +class TourRouteState extends State { + final _key = GlobalKey(); + final pushNotificationsKey = GlobalKey(); User currUser; @@ -43,58 +46,60 @@ class _TourRouteState extends State { void setStateKeepCurrentIndex(BuildContext cxt) async { _defaultIndex = DefaultTabController.of(cxt).index; - await key.currentState.refresh(); + await _key.currentState.refresh(); } - List get _list => [ - FirstTourPane(), + List get _list => config().toursEntriesBuilder != null + ? config().toursEntriesBuilder(this) + : [ + FirstTourPane(), - // Account image - AccountImageTourPane( - user: currUser, - onUpdated: setStateKeepCurrentIndex, - ), + // Account image + AccountImageTourPane( + user: currUser, + onUpdated: setStateKeepCurrentIndex, + ), - // Notifications - TourNotificationsPane( - pushNotificationsKey: _pushNotificationsKey, - onConfigured: () => setState(() {}), - onChanged: () => setState(() {}), - ), + // Notifications + TourNotificationsPane( + pushNotificationsKey: pushNotificationsKey, + onConfigured: () => setState(() {}), + onChanged: () => setState(() {}), + ), - PresentationPane( - icon: Icons.group_add, - title: tr("Friends"), - text: tr( - "You can search the people you know and ask them to become your friends!\n\nThis will help you to reach them to exchange information!"), - ), - PresentationPane( - icon: Icons.question_answer, - title: tr("Conversations"), - text: tr( - "With Comunic, you can have conversations with all your friends.\n\nIt is also possible to make video calls!"), - ), - PresentationPane( - icon: Icons.group, - title: tr("Groups"), - text: tr( - "You can join groups where people share the same interests as you!\n\nIt is also easy to create your own groups!"), - ), - PresentationPane( - icon: Icons.lock, - title: tr("Privacy"), - text: tr( - "Your data is YOUR DATA. We will never use it or sell it.\n\nIf you do not trust us, you can always check out our source code to verify it!"), - ), - LastTourPane(), - ]; + PresentationPane( + icon: Icons.group_add, + title: tr("Friends"), + text: tr( + "You can search the people you know and ask them to become your friends!\n\nThis will help you to reach them to exchange information!"), + ), + PresentationPane( + icon: Icons.question_answer, + title: tr("Conversations"), + text: tr( + "With Comunic, you can have conversations with all your friends.\n\nIt is also possible to make video calls!"), + ), + PresentationPane( + icon: Icons.group, + title: tr("Groups"), + text: tr( + "You can join groups where people share the same interests as you!\n\nIt is also easy to create your own groups!"), + ), + PresentationPane( + icon: Icons.lock, + title: tr("Privacy"), + text: tr( + "Your data is YOUR DATA. We will never use it or sell it.\n\nIf you do not trust us, you can always check out our source code to verify it!"), + ), + LastTourPane(), + ]; @override Widget build(BuildContext context) => LoginRoutesTheme( child: Scaffold( body: SafeArea( child: AsyncScreenWidget( - key: key, + key: _key, onReload: _init, errorMessage: tr("Failed to load tour!"), onBuild: () => DefaultTabController( diff --git a/lib/ui/widgets/init_widget.dart b/lib/ui/widgets/init_widget.dart index aa51a87..1f320b2 100644 --- a/lib/ui/widgets/init_widget.dart +++ b/lib/ui/widgets/init_widget.dart @@ -6,10 +6,10 @@ import 'package:comunic/helpers/version_helper.dart'; import 'package:comunic/helpers/websocket_helper.dart'; import 'package:comunic/models/config.dart'; import 'package:comunic/ui/dialogs/deprecation_dialog.dart'; -import 'package:comunic/ui/routes/TourRoute.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/routes/main_route/smartphone_route.dart'; import 'package:comunic/ui/routes/main_route/tablet_route.dart'; +import 'package:comunic/ui/routes/tour_route.dart'; import 'package:comunic/ui/routes/welcome_route.dart'; import 'package:comunic/ui/widgets/login_routes_theme.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; diff --git a/lib/ui/widgets/tour/first_pane.dart b/lib/ui/widgets/tour/first_pane.dart index 989ca9b..6b23fb7 100644 --- a/lib/ui/widgets/tour/first_pane.dart +++ b/lib/ui/widgets/tour/first_pane.dart @@ -1,3 +1,4 @@ +import 'package:comunic/models/config.dart'; import 'package:comunic/ui/widgets/tour/fixed_tour_size_text_area.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -7,6 +8,11 @@ import 'package:flutter/material.dart'; /// @author Pierre Hubert class FirstTourPane extends StatelessWidget { + final String msgOne; + final String msgTwo; + + const FirstTourPane({Key key, this.msgOne, this.msgTwo}) : super(key: key); + @override Widget build(BuildContext context) { return Column( @@ -14,15 +20,15 @@ class FirstTourPane extends StatelessWidget { children: [ Spacer(flex: 3), Text( - "Comunic", + config().appName, style: TextStyle(fontSize: 25), ), Spacer(flex: 2), - FixedTourSizeTextArea(tr( - "Welcome to Comunic, the social network that respect your privacy!")), + FixedTourSizeTextArea(msgOne ?? + tr("Welcome to Comunic, the social network that respect your privacy!")), Spacer(flex: 1), - FixedTourSizeTextArea(tr( - "Let's configure a few things and present you some features of the network...")), + FixedTourSizeTextArea(msgTwo ?? + tr("Let's configure a few things and present you some features of the network...")), Spacer(flex: 3), ], );