From 0472965acbfae02bc0b7fc28374294c2c56389c0 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 27 Jun 2024 11:02:16 +0200 Subject: [PATCH 01/18] feat: first screen join beta --- lib/pages/beta/beta.dart | 126 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 lib/pages/beta/beta.dart diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart new file mode 100644 index 0000000000..d1acdc40d6 --- /dev/null +++ b/lib/pages/beta/beta.dart @@ -0,0 +1,126 @@ +import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; +import 'dart:io' show Platform; + +class BetaJoinPage extends StatelessWidget { + // URLs + final String testflightAppUrl = 'https://apps.apple.com/us/app/testflight/id899247664'; + final String appleBetaUrl = 'https://testflight.apple.com/join/daXe0NfW'; + final String playStoreUrl = 'https://play.google.com/store/apps/details?id=fr.tawkie.app'; + final String androidBetaUrl = 'https://play.google.com/apps/testing/fr.tawkie.app'; + + const BetaJoinPage({super.key}); + + void joinBeta() async { + if (Platform.isIOS) { + if (await canLaunch(appleBetaUrl)) { + await launch(appleBetaUrl); + } else { + throw 'Could not launch $appleBetaUrl'; + } + } else if (Platform.isAndroid) { + if (await canLaunch(playStoreUrl)) { + await launch(playStoreUrl); + } else { + throw 'Could not launch $playStoreUrl'; + } + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Rejoindre la Bêta'), + ), + body: Padding( + padding: EdgeInsets.all(16.0), + child: ListView( + children: [ + Text( + '## Comment tester la version Beta et accéder aux nouvelles fonctionnalités en avance ?\n', + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + Text( + 'Participer à la Beta permet d\'avoir accès aux mises à jour de l\'application en avance et tester en premier.ère les nouvelles fonctionnalités !\n', + style: TextStyle(fontSize: 16), + ), + Text( + 'Sous iOS :', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + '- Installer Apple Testflight', + style: TextStyle(fontSize: 16), + ), + InkWell( + child: Text( + 'Apple Testflight', + style: TextStyle(fontSize: 16, color: Colors.blue), + ), + onTap: () async { + if (await canLaunch(testflightAppUrl)) { + await launch(testflightAppUrl); + } else { + throw 'Could not launch $testflightAppUrl'; + } + }, + ), + Text( + '- Rejoindre la Beta', + style: TextStyle(fontSize: 16), + ), + InkWell( + child: Text( + 'Beta iOS', + style: TextStyle(fontSize: 16, color: Colors.blue), + ), + onTap: () async { + if (await canLaunch(appleBetaUrl)) { + await launch(appleBetaUrl); + } else { + throw 'Could not launch $appleBetaUrl'; + } + }, + ), + Text( + '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', + style: TextStyle(fontSize: 16), + ), + Text( + 'Sous Android :', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + '- Rejoindre la Beta depuis le Play Store ou en ligne', + style: TextStyle(fontSize: 16), + ), + InkWell( + child: Text( + 'Beta Android', + style: TextStyle(fontSize: 16, color: Colors.blue), + ), + onTap: () async { + if (await canLaunch(androidBetaUrl)) { + await launch(androidBetaUrl); + } else { + throw 'Could not launch $androidBetaUrl'; + } + }, + ), + Text( + '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', + style: TextStyle(fontSize: 16), + ), + SizedBox(height: 20), + ElevatedButton.icon( + onPressed: joinBeta, + icon: Icon(Icons.new_releases), + label: Text('Rejoindre la Bêta'), + ), + ], + ), + ), + ); + } +} From 4ce89f63895853d28f30abfe820e4496d240dcdd Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 27 Jun 2024 11:02:26 +0200 Subject: [PATCH 02/18] feat: joinbeta in route --- lib/config/routes.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index abb3dcd54a..c7b1e61edf 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -2,14 +2,12 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - import 'package:go_router/go_router.dart'; - import 'package:tawkie/config/themes.dart'; import 'package:tawkie/pages/add_bridge/add_bridge.dart'; -import 'package:tawkie/pages/add_bridge/add_bridge_body.dart'; import 'package:tawkie/pages/archive/archive.dart'; import 'package:tawkie/pages/auth/auth.dart'; +import 'package:tawkie/pages/beta/beta.dart'; import 'package:tawkie/pages/chat/chat.dart'; import 'package:tawkie/pages/chat_access_settings/chat_access_settings_controller.dart'; import 'package:tawkie/pages/chat_details/chat_details.dart'; @@ -49,7 +47,8 @@ abstract class AppRoutes { final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); final sessionToken = await _secureStorage.read(key: 'sessionToken'); - final bool isLoggedKratos = sessionToken is String && sessionToken.isNotEmpty; + final bool isLoggedKratos = + sessionToken is String && sessionToken.isNotEmpty; final bool isLoggedMatrix = Matrix.of(context).client.isLogged(); final bool preAuth = state.fullPath!.startsWith('/home'); @@ -306,6 +305,15 @@ abstract class AppRoutes { ), ], ), + GoRoute( + path: 'joinBeta', + pageBuilder: (context, state) => defaultPageBuilder( + context, + state, + const BetaJoinPage(), + ), + redirect: loggedOutRedirect, + ), // Route to social networking page via chat bot // The entire path is: /rooms/settings/addbridgebot GoRoute( From 7535d4fe3a84951c1589aa1740a08c5c149d9db1 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 27 Jun 2024 12:48:15 +0200 Subject: [PATCH 03/18] feat: join beta item menu --- .../chat_list/client_chooser_button.dart | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 0c2f16f59a..3cc639bbe1 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -1,15 +1,14 @@ +import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; - -import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:go_router/go_router.dart'; import 'package:keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:matrix/matrix.dart'; import 'package:tawkie/utils/fluffy_share.dart'; - import 'package:tawkie/widgets/avatar.dart'; import 'package:tawkie/widgets/matrix.dart'; + import 'chat_list.dart'; class ClientChooserButton extends StatelessWidget { @@ -80,6 +79,16 @@ class ClientChooserButton extends StatelessWidget { ], ), ), + PopupMenuItem( + value: SettingsAction.joinBeta, + child: Row( + children: [ + const Icon(Icons.new_releases), + const SizedBox(width: 18), + Text("Rejoindre la bêta"), + ], + ), + ), PopupMenuItem( value: SettingsAction.settings, child: Row( @@ -288,6 +297,9 @@ class ClientChooserButton extends StatelessWidget { case SettingsAction.archive: context.go('/rooms/archive'); break; + case SettingsAction.joinBeta: + context.go('/rooms/settings/joinBeta'); + break; // Redirect to bot social network connection page case SettingsAction.addBridgeBot: context.go('/rooms/settings/addbridgebot'); @@ -377,4 +389,5 @@ enum SettingsAction { invite, settings, archive, + joinBeta, } From b65a8a730d19b492862326d15745f9fc31ef66e9 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 27 Jun 2024 12:48:35 +0200 Subject: [PATCH 04/18] feat: opent play store for android --- lib/pages/beta/beta.dart | 163 +++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 76 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index d1acdc40d6..b34c34c5ad 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -1,32 +1,48 @@ +import 'dart:io' show Platform; + import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; -import 'dart:io' show Platform; class BetaJoinPage extends StatelessWidget { // URLs - final String testflightAppUrl = 'https://apps.apple.com/us/app/testflight/id899247664'; + final String testflightAppUrl = + 'https://apps.apple.com/us/app/testflight/id899247664'; final String appleBetaUrl = 'https://testflight.apple.com/join/daXe0NfW'; - final String playStoreUrl = 'https://play.google.com/store/apps/details?id=fr.tawkie.app'; - final String androidBetaUrl = 'https://play.google.com/apps/testing/fr.tawkie.app'; + final String playStoreUrl = + 'https://play.google.com/store/apps/details?id=fr.tawkie.app'; + final String androidBetaUrl = + 'https://play.google.com/apps/testing/fr.tawkie.app'; const BetaJoinPage({super.key}); void joinBeta() async { if (Platform.isIOS) { - if (await canLaunch(appleBetaUrl)) { - await launch(appleBetaUrl); + final String appStoreUrl = + 'itms-apps://itunes.apple.com/app/id899247664'; // Direct link to the TestFlight app + if (await canLaunchUrl(Uri.parse(appStoreUrl))) { + await launchUrl(Uri.parse(appStoreUrl)); + } else if (await canLaunchUrl(Uri.parse(appleBetaUrl))) { + await launchUrl(Uri.parse(appleBetaUrl)); } else { throw 'Could not launch $appleBetaUrl'; } } else if (Platform.isAndroid) { - if (await canLaunch(playStoreUrl)) { - await launch(playStoreUrl); + final String playStoreUrl = + 'market://details?id=fr.tawkie.app'; // Direct link to the Play Store app + if (await canLaunchUrl(Uri.parse(playStoreUrl))) { + await launchUrl(Uri.parse(playStoreUrl)); + } else if (await canLaunchUrl(Uri.parse(androidBetaUrl))) { + await launchUrl(Uri.parse(androidBetaUrl)); } else { - throw 'Could not launch $playStoreUrl'; + throw 'Could not launch $androidBetaUrl'; } } } + void joinGroup() { + print("Rejoindre le groupe Beta"); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -45,78 +61,73 @@ class BetaJoinPage extends StatelessWidget { 'Participer à la Beta permet d\'avoir accès aux mises à jour de l\'application en avance et tester en premier.ère les nouvelles fonctionnalités !\n', style: TextStyle(fontSize: 16), ), - Text( - 'Sous iOS :', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - '- Installer Apple Testflight', - style: TextStyle(fontSize: 16), - ), - InkWell( - child: Text( - 'Apple Testflight', - style: TextStyle(fontSize: 16, color: Colors.blue), + if (Platform.isIOS) ...[ + Text( + 'Sous iOS :', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), - onTap: () async { - if (await canLaunch(testflightAppUrl)) { - await launch(testflightAppUrl); - } else { - throw 'Could not launch $testflightAppUrl'; - } - }, - ), - Text( - '- Rejoindre la Beta', - style: TextStyle(fontSize: 16), - ), - InkWell( - child: Text( - 'Beta iOS', - style: TextStyle(fontSize: 16, color: Colors.blue), + Text( + '- Installer Apple Testflight', + style: TextStyle(fontSize: 16), ), - onTap: () async { - if (await canLaunch(appleBetaUrl)) { - await launch(appleBetaUrl); - } else { - throw 'Could not launch $appleBetaUrl'; - } - }, - ), - Text( - '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', - style: TextStyle(fontSize: 16), - ), - Text( - 'Sous Android :', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - '- Rejoindre la Beta depuis le Play Store ou en ligne', - style: TextStyle(fontSize: 16), - ), - InkWell( - child: Text( - 'Beta Android', - style: TextStyle(fontSize: 16, color: Colors.blue), + ElevatedButton( + onPressed: () => joinBeta(), + child: Text('Télécharger Apple Testflight'), ), - onTap: () async { - if (await canLaunch(androidBetaUrl)) { - await launch(androidBetaUrl); - } else { - throw 'Could not launch $androidBetaUrl'; - } - }, - ), - Text( - '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', - style: TextStyle(fontSize: 16), - ), - SizedBox(height: 20), + Divider(thickness: 1), + Text( + '- Rejoindre la Beta', + style: TextStyle(fontSize: 16), + ), + ElevatedButton( + onPressed: () async { + if (await canLaunchUrl(Uri.parse(appleBetaUrl))) { + await launchUrl(Uri.parse(appleBetaUrl)); + } else { + throw 'Could not launch $appleBetaUrl'; + } + }, + child: Text('Télécharger la Beta iOS'), + ), + Divider(thickness: 1), + Text( + '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', + style: TextStyle(fontSize: 16), + ), + ], + if (Platform.isAndroid) ...[ + Text( + 'Sous Android :', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + '- Rejoindre la Beta depuis le Play Store ou en ligne', + style: TextStyle(fontSize: 16), + ), + ElevatedButton( + onPressed: () async { + final String playStoreUrl = + 'market://details?id=fr.tawkie.app'; + if (await canLaunchUrl(Uri.parse(playStoreUrl))) { + await launchUrl(Uri.parse(playStoreUrl)); + } else if (await canLaunchUrl(Uri.parse(androidBetaUrl))) { + await launchUrl(Uri.parse(androidBetaUrl)); + } else { + throw 'Could not launch $androidBetaUrl'; + } + }, + child: Text('Télécharger la Beta Android'), + ), + Divider(thickness: 1), + Text( + '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', + style: TextStyle(fontSize: 16), + ), + ], ElevatedButton.icon( - onPressed: joinBeta, + onPressed: joinGroup, icon: Icon(Icons.new_releases), - label: Text('Rejoindre la Bêta'), + label: Text('Rejoindre le groupe Beta'), ), ], ), From c64336c8135d31f47cd0e174da66177af2b8a834 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 27 Jun 2024 14:04:29 +0200 Subject: [PATCH 05/18] feat: ios open Testflight on ios --- lib/pages/beta/beta.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index b34c34c5ad..c31ea2ae7f 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -1,5 +1,4 @@ import 'dart:io' show Platform; - import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -71,7 +70,13 @@ class BetaJoinPage extends StatelessWidget { style: TextStyle(fontSize: 16), ), ElevatedButton( - onPressed: () => joinBeta(), + onPressed: () async { + if (await canLaunchUrl(Uri.parse(testflightAppUrl))) { + await launchUrl(Uri.parse(testflightAppUrl)); + } else { + throw 'Could not launch $testflightAppUrl'; + } + }, child: Text('Télécharger Apple Testflight'), ), Divider(thickness: 1), From 9b35b1e93931defee23ef444ee79554e7dad30e4 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Fri, 28 Jun 2024 14:26:34 +0200 Subject: [PATCH 06/18] feat: tentative to join group function --- lib/pages/beta/beta.dart | 70 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index c31ea2ae7f..aea7891cbf 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -1,5 +1,10 @@ -import 'dart:io' show Platform; +import 'dart:io' show HttpException, Platform; + import 'package:flutter/material.dart'; +import 'package:future_loading_dialog/future_loading_dialog.dart'; +import 'package:matrix/matrix.dart'; +import 'package:tawkie/pages/chat_list/utils/on_chat_tap.dart'; +import 'package:tawkie/widgets/matrix.dart'; import 'package:url_launcher/url_launcher.dart'; class BetaJoinPage extends StatelessWidget { @@ -38,8 +43,65 @@ class BetaJoinPage extends StatelessWidget { } } - void joinGroup() { - print("Rejoindre le groupe Beta"); + // Function to join the beta room + Future joinGroup(BuildContext context) async { + try { + const roomAlias = '#beta:alpha.tawkie.fr'; + final client = Matrix.of(context).client; + + // Get room ID by alias + final roomIdResponse = await client.getRoomIdByAlias(roomAlias); + final roomId = roomIdResponse.roomId; + + print('Room ID Response: $roomIdResponse'); + print('Room ID: $roomId'); + + if (roomId == null) { + throw Exception('Room ID not found for alias: $roomAlias'); + } + + // Check if the room is already joined + final room = client.getRoomById(roomId); + if (room != null && room.membership == Membership.join) { + // Room already joined, navigate to chat + onChatTap(room, context); + return; + } + + // Join the room + final result = await showFutureLoadingDialog( + context: context, + future: () async { + // Join the room and wait for it to appear in the sync + final roomId = await client.joinRoom(roomAlias); + await client.waitForRoomInSync(roomId); + return roomId; + }, + ); + + // Navigate to chat or perform other actions + final joinedRoom = client.getRoomById(result.result.toString()); + if (joinedRoom != null) { + onChatTap(joinedRoom, context); + } else { + throw Exception('Room not found after joining: $result'); + } + } on MatrixException catch (e) { + print('Matrix Exception: ${e.error}'); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Matrix Error: ${e.error}')), + ); + } on HttpException catch (e) { + print('HTTP Error: ${e.message}'); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('HTTP Error: ${e.message}')), + ); + } catch (e) { + print('General Error: $e'); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Error: $e')), + ); + } } @override @@ -130,7 +192,7 @@ class BetaJoinPage extends StatelessWidget { ), ], ElevatedButton.icon( - onPressed: joinGroup, + onPressed: () => joinGroup(context), icon: Icon(Icons.new_releases), label: Text('Rejoindre le groupe Beta'), ), From de0fcf5e1e866f959bf3cf36fa5f232ca4bc025b Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Mon, 1 Jul 2024 15:03:50 +0200 Subject: [PATCH 07/18] feat: test function create and join --- lib/pages/beta/beta.dart | 272 ++++++++++++++++++++++++++++++++------- 1 file changed, 227 insertions(+), 45 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index aea7891cbf..c558fd01ee 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -1,9 +1,10 @@ -import 'dart:io' show HttpException, Platform; +import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; +import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:tawkie/pages/chat_list/utils/on_chat_tap.dart'; +import 'package:matrix/matrix_api_lite.dart' as MatrixLite; import 'package:tawkie/widgets/matrix.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -43,64 +44,242 @@ class BetaJoinPage extends StatelessWidget { } } - // Function to join the beta room - Future joinGroup(BuildContext context) async { + Future createAndJoinRoom({ + required BuildContext context, + }) async { + final client = Matrix.of(context).client; + final String roomAliasName = 'testTree'; // L'alias local de la room + final String roomAlias = '#$roomAliasName:staging.tawkie.fr'; + try { - const roomAlias = '#beta:alpha.tawkie.fr'; - final client = Matrix.of(context).client; + final createRoomResult = await showFutureLoadingDialog( + context: context, + future: () async { + try { + print('Creating room'); // Log pour diagnostiquer - // Get room ID by alias - final roomIdResponse = await client.getRoomIdByAlias(roomAlias); - final roomId = roomIdResponse.roomId; + // Créer la room + final roomId = await client.createRoom( + name: 'testTree Room', + topic: 'Room for testTree', + visibility: MatrixLite.Visibility.public, + roomAliasName: roomAliasName, + preset: CreateRoomPreset.publicChat, + // Utiliser le preset pour les rooms publiques + initialState: [ + StateEvent( + type: 'm.room.join_rules', + stateKey: '', + content: { + 'join_rule': 'public', + }, + ), + StateEvent( + type: 'm.room.history_visibility', + stateKey: '', + content: { + 'history_visibility': 'shared', + }, + ), + ], + ); - print('Room ID Response: $roomIdResponse'); - print('Room ID: $roomId'); + if (roomId == null) { + print('Failed to create room'); + throw Exception('Failed to create room'); + } - if (roomId == null) { - throw Exception('Room ID not found for alias: $roomAlias'); - } + print('Room created with ID: $roomId'); + return roomId; + } catch (e) { + // Gérer les exceptions pendant la création de la room + print('Error creating room: $e'); // Log pour diagnostiquer + throw Exception('Failed to create room: $e'); + } + }, + ); + + if (createRoomResult.error == null) { + final roomId = createRoomResult.result!; + print('Room created successfully: $roomId'); + + final joinResult = await showFutureLoadingDialog( + context: context, + future: () async { + try { + print( + 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer + + // Obtenir l'ID de la room à partir de l'alias + final id = await client.getRoomIdByAlias(roomAlias); + if (id == null) { + print('Room ID is null'); + throw Exception('Failed to get room ID for alias: $roomAlias'); + } + print('Room ID: ${id.roomId}'); + + final waitForRoom = client.waitForRoomInSync( + id.roomId!, + join: true, + ); - // Check if the room is already joined - final room = client.getRoomById(roomId); - if (room != null && room.membership == Membership.join) { - // Room already joined, navigate to chat - onChatTap(room, context); - return; + await client + .joinRoom(id.roomId!, serverName: ['staging.tawkie.fr']); + await waitForRoom; + + return id.roomId!; // Retourner l'ID de la room + } catch (e) { + // Gérer les exceptions pendant la tentative de rejoindre la room + print('Error joining room: $e'); // Log pour diagnostiquer + throw Exception('Failed to join room: $e'); + } + }, + ); + + if (joinResult.error == null) { + // Fermer la boîte de dialogue + Navigator.of(context).pop(); + + final joinedRoom = client.getRoomById(joinResult.result!); + if (joinedRoom == null) { + print('Room not found after joining'); + throw Exception('Room not found after joining'); + } + + // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas + if (!joinedRoom.isSpace) { + context.go('/rooms/${joinResult.result!}'); + } + } else { + // Gérer l'erreur si l'adhésion à la room échoue + print( + 'Failed to join room: ${joinResult.error}'); // Log pour diagnostiquer + final snackBar = SnackBar( + content: Text('Failed to join room: ${joinResult.error}')); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + } else { + print( + 'Failed to create room: ${createRoomResult.error}'); // Log pour diagnostiquer + final snackBar = SnackBar( + content: Text('Failed to create room: ${createRoomResult.error}')); + ScaffoldMessenger.of(context).showSnackBar(snackBar); } + } catch (e) { + // Afficher un message d'erreur général si une exception est levée + print('Something went wrong: $e'); // Log pour diagnostiquer + final snackBar = SnackBar(content: Text('Something went wrong: $e')); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + } + + Future joinGroup({ + required BuildContext context, + }) async { + final client = Matrix.of(context).client; + final String roomAlias = '#testTree:staging.tawkie.fr'; + final List serverName = [ + 'staging.tawkie.fr' + ]; // Liste des serveurs à contacter - // Join the room + try { final result = await showFutureLoadingDialog( context: context, future: () async { - // Join the room and wait for it to appear in the sync - final roomId = await client.joinRoom(roomAlias); - await client.waitForRoomInSync(roomId); - return roomId; + try { + print( + 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer + + // Obtenir l'ID de la room à partir de l'alias + final roomAliasResult = await client.getRoomIdByAlias(roomAlias); + + final roomId = roomAliasResult.roomId; + if (roomId == null) { + print('Room ID is null'); + throw Exception('Room ID is null for alias: $roomAlias'); + } + + final joinResult = await showFutureLoadingDialog( + context: context, + future: () async { + try { + print( + 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer + + client.clearArchivesFromCache(); + + // Obtenir l'ID de la room à partir de l'alias + final id = await client.getRoomIdByAlias(roomAlias); + if (id == null) { + print('Room ID is null'); + throw Exception( + 'Failed to get room ID for alias: $roomAlias'); + } + print('Room ID: ${id.roomId}'); + + await client + .joinRoom(id.roomId!, serverName: ['staging.tawkie.fr']); + + return id.roomId!; // Retourner l'ID de la room + } catch (e) { + // Gérer les exceptions pendant la tentative de rejoindre la room + print('Error joining room: $e'); // Log pour diagnostiquer + throw Exception('Failed to join room: $e'); + } + }, + ); + + if (joinResult.error == null) { + // Fermer la boîte de dialogue + Navigator.of(context).pop(); + + final joinedRoom = client.getRoomById(joinResult.result!); + if (joinedRoom == null) { + print('Room not found after joining'); + throw Exception('Room not found after joining'); + } + + // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas + if (!joinedRoom.isSpace) { + context.go('/rooms/${joinResult.result!}'); + } + } + + return roomId; // Retourner l'ID de la room + } catch (e) { + // Gérer les exceptions pendant la tentative de rejoindre la room + print('Error joining room: $e'); // Log pour diagnostiquer + throw Exception('Failed to join room: $e'); + } }, ); - // Navigate to chat or perform other actions - final joinedRoom = client.getRoomById(result.result.toString()); - if (joinedRoom != null) { - onChatTap(joinedRoom, context); + if (result.error == null) { + // Fermer la boîte de dialogue + Navigator.of(context).pop(); + + final room = client.getRoomById(result.result!); + if (room == null) { + print('Room not found after joining'); + throw Exception('Room not found after joining'); + } + + // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas + if (!room.isSpace) { + context.go('/rooms/${result.result!}'); + } } else { - throw Exception('Room not found after joining: $result'); + // Gérer l'erreur si l'adhésion à la room échoue + print('Failed to join room: ${result.error}'); // Log pour diagnostiquer + final snackBar = + SnackBar(content: Text('Failed to join room: ${result.error}')); + ScaffoldMessenger.of(context).showSnackBar(snackBar); } - } on MatrixException catch (e) { - print('Matrix Exception: ${e.error}'); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Matrix Error: ${e.error}')), - ); - } on HttpException catch (e) { - print('HTTP Error: ${e.message}'); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('HTTP Error: ${e.message}')), - ); } catch (e) { - print('General Error: $e'); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Error: $e')), - ); + // Afficher un message d'erreur général si une exception est levée + print('Something went wrong: $e'); // Log pour diagnostiquer + final snackBar = SnackBar(content: Text('Something went wrong: $e')); + ScaffoldMessenger.of(context).showSnackBar(snackBar); } } @@ -192,7 +371,10 @@ class BetaJoinPage extends StatelessWidget { ), ], ElevatedButton.icon( - onPressed: () => joinGroup(context), + onPressed: () async { + //await createAndJoinRoom(context: context); + await joinGroup(context: context); + }, icon: Icon(Icons.new_releases), label: Text('Rejoindre le groupe Beta'), ), From 2788e3a4c59e65f6c19dd7379b9344c204074ece Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Wed, 3 Jul 2024 14:25:40 +0200 Subject: [PATCH 08/18] feat: better function join group beta --- lib/pages/beta/beta.dart | 258 ++++++++------------------------------- 1 file changed, 52 insertions(+), 206 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index c558fd01ee..4fad704885 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -1,10 +1,10 @@ import 'dart:io' show Platform; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; -import 'package:matrix/matrix_api_lite.dart' as MatrixLite; import 'package:tawkie/widgets/matrix.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -44,241 +44,88 @@ class BetaJoinPage extends StatelessWidget { } } - Future createAndJoinRoom({ + Future joinGroup({ required BuildContext context, }) async { final client = Matrix.of(context).client; - final String roomAliasName = 'testTree'; // L'alias local de la room - final String roomAlias = '#$roomAliasName:staging.tawkie.fr'; + const String roomAliasName = 'testbeta'; + const String roomAlias = '#$roomAliasName:staging.tawkie.fr'; try { - final createRoomResult = await showFutureLoadingDialog( - context: context, - future: () async { - try { - print('Creating room'); // Log pour diagnostiquer - - // Créer la room - final roomId = await client.createRoom( - name: 'testTree Room', - topic: 'Room for testTree', - visibility: MatrixLite.Visibility.public, - roomAliasName: roomAliasName, - preset: CreateRoomPreset.publicChat, - // Utiliser le preset pour les rooms publiques - initialState: [ - StateEvent( - type: 'm.room.join_rules', - stateKey: '', - content: { - 'join_rule': 'public', - }, - ), - StateEvent( - type: 'm.room.history_visibility', - stateKey: '', - content: { - 'history_visibility': 'shared', - }, - ), - ], - ); - - if (roomId == null) { - print('Failed to create room'); - throw Exception('Failed to create room'); - } - - print('Room created with ID: $roomId'); - return roomId; - } catch (e) { - // Gérer les exceptions pendant la création de la room - print('Error creating room: $e'); // Log pour diagnostiquer - throw Exception('Failed to create room: $e'); - } - }, - ); - - if (createRoomResult.error == null) { - final roomId = createRoomResult.result!; - print('Room created successfully: $roomId'); - - final joinResult = await showFutureLoadingDialog( - context: context, - future: () async { - try { - print( - 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer - - // Obtenir l'ID de la room à partir de l'alias - final id = await client.getRoomIdByAlias(roomAlias); - if (id == null) { - print('Room ID is null'); - throw Exception('Failed to get room ID for alias: $roomAlias'); - } - print('Room ID: ${id.roomId}'); - - final waitForRoom = client.waitForRoomInSync( - id.roomId!, - join: true, - ); - - await client - .joinRoom(id.roomId!, serverName: ['staging.tawkie.fr']); - await waitForRoom; - - return id.roomId!; // Retourner l'ID de la room - } catch (e) { - // Gérer les exceptions pendant la tentative de rejoindre la room - print('Error joining room: $e'); // Log pour diagnostiquer - throw Exception('Failed to join room: $e'); - } - }, - ); - - if (joinResult.error == null) { - // Fermer la boîte de dialogue - Navigator.of(context).pop(); + if (kDebugMode) { + print('Attempting to join room: $roomAlias'); + } - final joinedRoom = client.getRoomById(joinResult.result!); - if (joinedRoom == null) { - print('Room not found after joining'); - throw Exception('Room not found after joining'); - } + // Get room ID from alias + final roomAliasResult = await client.getRoomIdByAlias(roomAlias); + final roomId = roomAliasResult.roomId; - // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas - if (!joinedRoom.isSpace) { - context.go('/rooms/${joinResult.result!}'); - } - } else { - // Gérer l'erreur si l'adhésion à la room échoue - print( - 'Failed to join room: ${joinResult.error}'); // Log pour diagnostiquer - final snackBar = SnackBar( - content: Text('Failed to join room: ${joinResult.error}')); - ScaffoldMessenger.of(context).showSnackBar(snackBar); + if (roomId == null) { + final errorMsg = 'Room ID is null for alias: $roomAlias'; + if (kDebugMode) { + print(errorMsg); } - } else { - print( - 'Failed to create room: ${createRoomResult.error}'); // Log pour diagnostiquer - final snackBar = SnackBar( - content: Text('Failed to create room: ${createRoomResult.error}')); - ScaffoldMessenger.of(context).showSnackBar(snackBar); + throw Exception(errorMsg); } - } catch (e) { - // Afficher un message d'erreur général si une exception est levée - print('Something went wrong: $e'); // Log pour diagnostiquer - final snackBar = SnackBar(content: Text('Something went wrong: $e')); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - } - } - Future joinGroup({ - required BuildContext context, - }) async { - final client = Matrix.of(context).client; - final String roomAlias = '#testTree:staging.tawkie.fr'; - final List serverName = [ - 'staging.tawkie.fr' - ]; // Liste des serveurs à contacter + // Check if the user is already a member of the room + final room = client.getRoomById(roomId); + if (room != null && room.membership == Membership.join) { + // Navigate directly to the room + context.go('/rooms/$roomId'); + return; + } - try { final result = await showFutureLoadingDialog( context: context, future: () async { try { - print( - 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer - - // Obtenir l'ID de la room à partir de l'alias - final roomAliasResult = await client.getRoomIdByAlias(roomAlias); - - final roomId = roomAliasResult.roomId; - if (roomId == null) { - print('Room ID is null'); - throw Exception('Room ID is null for alias: $roomAlias'); - } + // Retrieve participating servers + final servers = roomAliasResult.servers ?? ['staging.tawkie.fr']; + final waitForRoom = client.waitForRoomInSync(roomId, join: true); - final joinResult = await showFutureLoadingDialog( - context: context, - future: () async { - try { - print( - 'Attempting to join room: $roomAlias'); // Log pour diagnostiquer - - client.clearArchivesFromCache(); - - // Obtenir l'ID de la room à partir de l'alias - final id = await client.getRoomIdByAlias(roomAlias); - if (id == null) { - print('Room ID is null'); - throw Exception( - 'Failed to get room ID for alias: $roomAlias'); - } - print('Room ID: ${id.roomId}'); + await client.joinRoom(roomId, serverName: servers); + await waitForRoom; - await client - .joinRoom(id.roomId!, serverName: ['staging.tawkie.fr']); - - return id.roomId!; // Retourner l'ID de la room - } catch (e) { - // Gérer les exceptions pendant la tentative de rejoindre la room - print('Error joining room: $e'); // Log pour diagnostiquer - throw Exception('Failed to join room: $e'); - } - }, - ); - - if (joinResult.error == null) { - // Fermer la boîte de dialogue - Navigator.of(context).pop(); - - final joinedRoom = client.getRoomById(joinResult.result!); - if (joinedRoom == null) { - print('Room not found after joining'); - throw Exception('Room not found after joining'); - } - - // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas - if (!joinedRoom.isSpace) { - context.go('/rooms/${joinResult.result!}'); - } - } - - return roomId; // Retourner l'ID de la room + return roomId; } catch (e) { - // Gérer les exceptions pendant la tentative de rejoindre la room - print('Error joining room: $e'); // Log pour diagnostiquer - throw Exception('Failed to join room: $e'); + final errorMsg = 'Failed to join room: $e'; + if (kDebugMode) { + print(errorMsg); + } + throw Exception(errorMsg); } }, ); if (result.error == null) { - // Fermer la boîte de dialogue Navigator.of(context).pop(); - final room = client.getRoomById(result.result!); - if (room == null) { - print('Room not found after joining'); - throw Exception('Room not found after joining'); + final joinedRoom = client.getRoomById(result.result!); + if (joinedRoom == null) { + final errorMsg = 'Room not found after joining'; + if (kDebugMode) { + print(errorMsg); + } + throw Exception(errorMsg); } - // Vérifier si la room est un espace et naviguer vers la room si ce n'est pas le cas - if (!room.isSpace) { - context.go('/rooms/${result.result!}'); - } + // Navigate to the room + context.go('/rooms/${result.result!}'); } else { - // Gérer l'erreur si l'adhésion à la room échoue - print('Failed to join room: ${result.error}'); // Log pour diagnostiquer - final snackBar = - SnackBar(content: Text('Failed to join room: ${result.error}')); + final errorMsg = 'Failed to join room: ${result.error}'; + if (kDebugMode) { + print(errorMsg); + } + final snackBar = SnackBar(content: Text(errorMsg)); ScaffoldMessenger.of(context).showSnackBar(snackBar); } } catch (e) { - // Afficher un message d'erreur général si une exception est levée - print('Something went wrong: $e'); // Log pour diagnostiquer - final snackBar = SnackBar(content: Text('Something went wrong: $e')); + final errorMsg = 'Something went wrong: $e'; + if (kDebugMode) { + print(errorMsg); + } + final snackBar = SnackBar(content: Text(errorMsg)); ScaffoldMessenger.of(context).showSnackBar(snackBar); } } @@ -372,7 +219,6 @@ class BetaJoinPage extends StatelessWidget { ], ElevatedButton.icon( onPressed: () async { - //await createAndJoinRoom(context: context); await joinGroup(context: context); }, icon: Icon(Icons.new_releases), From f7ec3dead22b26d5c7fbb052bbb80eb5649a7bc9 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Wed, 3 Jul 2024 15:09:00 +0200 Subject: [PATCH 09/18] feat: translate en/fr l10n beta page --- assets/l10n/intl_en.arb | 19 +++++++- assets/l10n/intl_fr.arb | 19 +++++++- lib/pages/beta/beta.dart | 97 ++++++++++++++++++++++++++-------------- 3 files changed, 100 insertions(+), 35 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index d12c0c3214..e070f9c36d 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2682,5 +2682,22 @@ "privacyTextPrivacy": "privacy policy", "privacyTextAnd": " and ", "privacyTextTerms": "terms of service", - "createGroupLimitationWarning": "Only Tawkie / Matrix users can be added to a group chat." + "createGroupLimitationWarning": "Only Tawkie / Matrix users can be added to a group chat.", + "joinBetaTitle": "Join the Beta", + "betaJoinExplanation": "## How to test the Beta version and access new features in advance?", + "betaJoinBenefit": "Participating in the Beta allows you to access application updates in advance and be the first to test new features!", + "iosInstructionsTitle": "On iOS:", + "installTestflight": "- Install Apple Testflight", + "downloadTestflightButton": "Download Apple Testflight", + "joinBetaTitleIOS": "- Join the Beta", + "downloadBetaIOSButton": "Download the iOS Beta", + "joinBetaGroup": "- Join the Tawkie Beta group: #beta", + "androidInstructionsTitle": "On Android:", + "joinBetaPlayStore": "- Join the Beta from the Play Store or online", + "downloadBetaAndroidButton": "Download the Android Beta", + "joinBetaButtonLabel": "Join the Beta group", + "joinBetaError": "Something went wrong: ", + "failedToJoinRoom": "Failed to join room: ", + "roomIdNullError": "Room ID is null for alias: ", + "roomNotFoundError": "Room not found after joining" } diff --git a/assets/l10n/intl_fr.arb b/assets/l10n/intl_fr.arb index 0e8f218a51..0bbb75a0fc 100644 --- a/assets/l10n/intl_fr.arb +++ b/assets/l10n/intl_fr.arb @@ -2498,5 +2498,22 @@ "privacyTextPrivacy": "politiques de confidentialité", "privacyTextAnd": " et ", "privacyTextTerms": "conditions générales d’utilisation et de services", - "createGroupLimitationWarning": "Seul.es les utilisateur.ices Tawkie peuvent être rajouté.es aux groupes." + "createGroupLimitationWarning": "Seul.es les utilisateur.ices Tawkie peuvent être rajouté.es aux groupes.", + "joinBetaTitle": "Rejoindre la Bêta", + "betaJoinExplanation": "## Comment tester la version Beta et accéder aux nouvelles fonctionnalités en avance ?", + "betaJoinBenefit": "Participer à la Beta permet d'avoir accès aux mises à jour de l'application en avance et tester en premier.ère les nouvelles fonctionnalités !", + "iosInstructionsTitle": "Sous iOS :", + "installTestflight": "- Installer Apple Testflight", + "downloadTestflightButton": "Télécharger Apple Testflight", + "joinBetaTitleIOS": "- Rejoindre la Beta", + "downloadBetaIOSButton": "Télécharger la Beta iOS", + "joinBetaGroup": "- Rejoindre le groupe Tawkie de la Beta : #beta", + "androidInstructionsTitle": "Sous Android :", + "joinBetaPlayStore": "- Rejoindre la Beta depuis le Play Store ou en ligne", + "downloadBetaAndroidButton": "Télécharger la Beta Android", + "joinBetaButtonLabel": "Rejoindre le groupe Beta", + "joinBetaError": "Une erreur s'est produite : ", + "failedToJoinRoom": "Échec de la connexion à la salle : ", + "roomIdNullError": "L'ID de la salle est nul pour l'alias : ", + "roomNotFoundError": "Salle introuvable après la connexion" } diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 4fad704885..587f9709d7 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -2,6 +2,7 @@ import 'dart:io' show Platform; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; @@ -61,7 +62,9 @@ class BetaJoinPage extends StatelessWidget { final roomId = roomAliasResult.roomId; if (roomId == null) { - final errorMsg = 'Room ID is null for alias: $roomAlias'; + final errorMsg = L10n.of(context)!.failedToJoinRoom + + L10n.of(context)!.roomIdNullError + + roomAlias; if (kDebugMode) { print(errorMsg); } @@ -89,7 +92,7 @@ class BetaJoinPage extends StatelessWidget { return roomId; } catch (e) { - final errorMsg = 'Failed to join room: $e'; + final errorMsg = L10n.of(context)!.failedToJoinRoom + e.toString(); if (kDebugMode) { print(errorMsg); } @@ -103,7 +106,8 @@ class BetaJoinPage extends StatelessWidget { final joinedRoom = client.getRoomById(result.result!); if (joinedRoom == null) { - final errorMsg = 'Room not found after joining'; + final errorMsg = L10n.of(context)!.failedToJoinRoom + + L10n.of(context)!.roomNotFoundError; if (kDebugMode) { print(errorMsg); } @@ -113,7 +117,8 @@ class BetaJoinPage extends StatelessWidget { // Navigate to the room context.go('/rooms/${result.result!}'); } else { - final errorMsg = 'Failed to join room: ${result.error}'; + final errorMsg = + L10n.of(context)!.failedToJoinRoom + result.error.toString(); if (kDebugMode) { print(errorMsg); } @@ -121,7 +126,7 @@ class BetaJoinPage extends StatelessWidget { ScaffoldMessenger.of(context).showSnackBar(snackBar); } } catch (e) { - final errorMsg = 'Something went wrong: $e'; + final errorMsg = L10n.of(context)!.joinBetaError + e.toString(); if (kDebugMode) { print(errorMsg); } @@ -134,28 +139,38 @@ class BetaJoinPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Rejoindre la Bêta'), + title: Text(L10n.of(context)!.joinBetaTitle), ), body: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: ListView( children: [ Text( - '## Comment tester la version Beta et accéder aux nouvelles fonctionnalités en avance ?\n', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + L10n.of(context)!.betaJoinExplanation, + style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + const SizedBox( + height: 20.0, ), Text( - 'Participer à la Beta permet d\'avoir accès aux mises à jour de l\'application en avance et tester en premier.ère les nouvelles fonctionnalités !\n', - style: TextStyle(fontSize: 16), + L10n.of(context)!.betaJoinBenefit, + style: const TextStyle(fontSize: 16), + ), + const SizedBox( + height: 20.0, ), if (Platform.isIOS) ...[ Text( - 'Sous iOS :', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + L10n.of(context)!.iosInstructionsTitle, + style: + const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), Text( - '- Installer Apple Testflight', - style: TextStyle(fontSize: 16), + L10n.of(context)!.installTestflight, + style: const TextStyle(fontSize: 16), + ), + const SizedBox( + height: 10.0, ), ElevatedButton( onPressed: () async { @@ -165,12 +180,15 @@ class BetaJoinPage extends StatelessWidget { throw 'Could not launch $testflightAppUrl'; } }, - child: Text('Télécharger Apple Testflight'), + child: Text(L10n.of(context)!.downloadTestflightButton), ), - Divider(thickness: 1), + const Divider(thickness: 1), Text( - '- Rejoindre la Beta', - style: TextStyle(fontSize: 16), + L10n.of(context)!.joinBetaTitleIOS, + style: const TextStyle(fontSize: 16), + ), + const SizedBox( + height: 10.0, ), ElevatedButton( onPressed: () async { @@ -180,22 +198,29 @@ class BetaJoinPage extends StatelessWidget { throw 'Could not launch $appleBetaUrl'; } }, - child: Text('Télécharger la Beta iOS'), + child: Text(L10n.of(context)!.downloadBetaIOSButton), ), - Divider(thickness: 1), + const SizedBox( + height: 10.0, + ), + const Divider(thickness: 1), Text( - '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', - style: TextStyle(fontSize: 16), + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), ), ], if (Platform.isAndroid) ...[ Text( - 'Sous Android :', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + L10n.of(context)!.androidInstructionsTitle, + style: + const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), Text( - '- Rejoindre la Beta depuis le Play Store ou en ligne', - style: TextStyle(fontSize: 16), + L10n.of(context)!.joinBetaPlayStore, + style: const TextStyle(fontSize: 16), + ), + const SizedBox( + height: 10.0, ), ElevatedButton( onPressed: () async { @@ -209,20 +234,26 @@ class BetaJoinPage extends StatelessWidget { throw 'Could not launch $androidBetaUrl'; } }, - child: Text('Télécharger la Beta Android'), + child: Text(L10n.of(context)!.downloadBetaAndroidButton), ), - Divider(thickness: 1), + const SizedBox( + height: 10.0, + ), + const Divider(thickness: 1), Text( - '- Rejoindre le groupe Tawkie de la Beta : #beta:alpha.tawkie.fr\n', - style: TextStyle(fontSize: 16), + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), ), ], + const SizedBox( + height: 10.0, + ), ElevatedButton.icon( onPressed: () async { await joinGroup(context: context); }, - icon: Icon(Icons.new_releases), - label: Text('Rejoindre le groupe Beta'), + icon: const Icon(Icons.new_releases), + label: Text(L10n.of(context)!.joinBetaButtonLabel), ), ], ), From 602706dff083dac89bef2ee7322cf8d6f3ce4079 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Wed, 3 Jul 2024 16:48:32 +0200 Subject: [PATCH 10/18] feat: variable from app_config --- lib/config/app_config.dart | 17 +++ lib/pages/beta/beta.dart | 227 +++++++++++++++++-------------------- 2 files changed, 120 insertions(+), 124 deletions(-) diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 8b7ed48ff9..42111cefba 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -75,6 +75,23 @@ abstract class AppConfig { static const String baseUrl = kDebugMode ? stagingUrl : productionUrl; static String tawkieSubscriptionIdentifier = 'Tawkie subscription'; + // URLs for Beta Join + static const String testflightAppUrl = 'https://apps.apple.com/us/app/testflight/id899247664'; + static const String appleBetaUrl = 'https://testflight.apple.com/join/daXe0NfW'; + static const String playStoreUrl = 'https://play.google.com/store/apps/details?id=fr.tawkie.app'; + static const String androidBetaUrl = 'https://play.google.com/apps/testing/fr.tawkie.app'; + + static const String iosUrl = 'itms-apps://itunes.apple.com/app/id899247664'; + static const String androidUrl = 'market://details?id=fr.tawkie.app'; + + static const String prodBetaAlias = 'beta'; + static const String testBetaAlias = 'testbeta'; + static const String betaAlias = kDebugMode ? testBetaAlias : prodBetaAlias; + static const String serverStagingUrl = ':staging.tawkie.fr'; + static const String serverProductionUrl = ':alpha.tawkie.fr'; + static const String server = kDebugMode ? serverStagingUrl : serverProductionUrl; + static const String roomAlias = '#$betaAlias$server'; + static void loadFromJson(Map json) { if (json['chat_color'] != null) { try { diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 587f9709d7..39f28e03b5 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -6,51 +6,48 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; +import 'package:tawkie/config/app_config.dart'; import 'package:tawkie/widgets/matrix.dart'; import 'package:url_launcher/url_launcher.dart'; class BetaJoinPage extends StatelessWidget { - // URLs - final String testflightAppUrl = - 'https://apps.apple.com/us/app/testflight/id899247664'; - final String appleBetaUrl = 'https://testflight.apple.com/join/daXe0NfW'; - final String playStoreUrl = - 'https://play.google.com/store/apps/details?id=fr.tawkie.app'; - final String androidBetaUrl = - 'https://play.google.com/apps/testing/fr.tawkie.app'; - const BetaJoinPage({super.key}); void joinBeta() async { - if (Platform.isIOS) { - final String appStoreUrl = - 'itms-apps://itunes.apple.com/app/id899247664'; // Direct link to the TestFlight app - if (await canLaunchUrl(Uri.parse(appStoreUrl))) { - await launchUrl(Uri.parse(appStoreUrl)); - } else if (await canLaunchUrl(Uri.parse(appleBetaUrl))) { - await launchUrl(Uri.parse(appleBetaUrl)); - } else { - throw 'Could not launch $appleBetaUrl'; + try { + if (Platform.isIOS) { + if (await canLaunchUrl(Uri.parse(AppConfig.iosUrl))) { + await launchUrl(Uri.parse(AppConfig.iosUrl)); + } else { + await _launchUrlOrThrow(AppConfig.appleBetaUrl); + } + } else if (Platform.isAndroid) { + if (await canLaunchUrl(Uri.parse(AppConfig.androidUrl))) { + await launchUrl(Uri.parse(AppConfig.androidUrl)); + } else { + await _launchUrlOrThrow(AppConfig.androidBetaUrl); + } } - } else if (Platform.isAndroid) { - final String playStoreUrl = - 'market://details?id=fr.tawkie.app'; // Direct link to the Play Store app - if (await canLaunchUrl(Uri.parse(playStoreUrl))) { - await launchUrl(Uri.parse(playStoreUrl)); - } else if (await canLaunchUrl(Uri.parse(androidBetaUrl))) { - await launchUrl(Uri.parse(androidBetaUrl)); - } else { - throw 'Could not launch $androidBetaUrl'; + } catch (e) { + if (kDebugMode) { + print('Error launching URL: $e'); } } } + Future _launchUrlOrThrow(String url) async { + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl(Uri.parse(url)); + } else { + throw 'Could not launch $url'; + } + } + Future joinGroup({ required BuildContext context, }) async { final client = Matrix.of(context).client; - const String roomAliasName = 'testbeta'; - const String roomAlias = '#$roomAliasName:staging.tawkie.fr'; + const String roomAlias = AppConfig.roomAlias; try { if (kDebugMode) { @@ -149,105 +146,15 @@ class BetaJoinPage extends StatelessWidget { L10n.of(context)!.betaJoinExplanation, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), - const SizedBox( - height: 20.0, - ), + const SizedBox(height: 20.0), Text( L10n.of(context)!.betaJoinBenefit, style: const TextStyle(fontSize: 16), ), - const SizedBox( - height: 20.0, - ), - if (Platform.isIOS) ...[ - Text( - L10n.of(context)!.iosInstructionsTitle, - style: - const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - L10n.of(context)!.installTestflight, - style: const TextStyle(fontSize: 16), - ), - const SizedBox( - height: 10.0, - ), - ElevatedButton( - onPressed: () async { - if (await canLaunchUrl(Uri.parse(testflightAppUrl))) { - await launchUrl(Uri.parse(testflightAppUrl)); - } else { - throw 'Could not launch $testflightAppUrl'; - } - }, - child: Text(L10n.of(context)!.downloadTestflightButton), - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaTitleIOS, - style: const TextStyle(fontSize: 16), - ), - const SizedBox( - height: 10.0, - ), - ElevatedButton( - onPressed: () async { - if (await canLaunchUrl(Uri.parse(appleBetaUrl))) { - await launchUrl(Uri.parse(appleBetaUrl)); - } else { - throw 'Could not launch $appleBetaUrl'; - } - }, - child: Text(L10n.of(context)!.downloadBetaIOSButton), - ), - const SizedBox( - height: 10.0, - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), - ], - if (Platform.isAndroid) ...[ - Text( - L10n.of(context)!.androidInstructionsTitle, - style: - const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - L10n.of(context)!.joinBetaPlayStore, - style: const TextStyle(fontSize: 16), - ), - const SizedBox( - height: 10.0, - ), - ElevatedButton( - onPressed: () async { - final String playStoreUrl = - 'market://details?id=fr.tawkie.app'; - if (await canLaunchUrl(Uri.parse(playStoreUrl))) { - await launchUrl(Uri.parse(playStoreUrl)); - } else if (await canLaunchUrl(Uri.parse(androidBetaUrl))) { - await launchUrl(Uri.parse(androidBetaUrl)); - } else { - throw 'Could not launch $androidBetaUrl'; - } - }, - child: Text(L10n.of(context)!.downloadBetaAndroidButton), - ), - const SizedBox( - height: 10.0, - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), - ], - const SizedBox( - height: 10.0, - ), + const SizedBox(height: 20.0), + if (Platform.isIOS) _buildIOSInstructions(context), + if (Platform.isAndroid) _buildAndroidInstructions(context), + const SizedBox(height: 10.0), ElevatedButton.icon( onPressed: () async { await joinGroup(context: context); @@ -260,4 +167,76 @@ class BetaJoinPage extends StatelessWidget { ), ); } + + Widget _buildIOSInstructions(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + L10n.of(context)!.iosInstructionsTitle, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + L10n.of(context)!.installTestflight, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + await _launchUrlOrThrow(AppConfig.testflightAppUrl); + }, + child: Text(L10n.of(context)!.downloadTestflightButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaTitleIOS, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + await _launchUrlOrThrow(AppConfig.appleBetaUrl); + }, + child: Text(L10n.of(context)!.downloadBetaIOSButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), + ), + ], + ); + } + + Widget _buildAndroidInstructions(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + L10n.of(context)!.androidInstructionsTitle, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + L10n.of(context)!.joinBetaPlayStore, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + try { + await _launchUrlOrThrow(AppConfig.playStoreUrl); + } catch (e) { + await _launchUrlOrThrow(AppConfig.androidBetaUrl); + } + }, + child: Text(L10n.of(context)!.downloadBetaAndroidButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), + ), + ], + ); + } } From 07ef37a064deeae9f140b0456bcb24d027be1d70 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Fri, 12 Jul 2024 17:48:56 +0200 Subject: [PATCH 11/18] accent correction --- assets/l10n/intl_fr.arb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/l10n/intl_fr.arb b/assets/l10n/intl_fr.arb index 0bbb75a0fc..a760031e5a 100644 --- a/assets/l10n/intl_fr.arb +++ b/assets/l10n/intl_fr.arb @@ -2499,7 +2499,7 @@ "privacyTextAnd": " et ", "privacyTextTerms": "conditions générales d’utilisation et de services", "createGroupLimitationWarning": "Seul.es les utilisateur.ices Tawkie peuvent être rajouté.es aux groupes.", - "joinBetaTitle": "Rejoindre la Bêta", + "joinBetaTitle": "Rejoindre la Beta", "betaJoinExplanation": "## Comment tester la version Beta et accéder aux nouvelles fonctionnalités en avance ?", "betaJoinBenefit": "Participer à la Beta permet d'avoir accès aux mises à jour de l'application en avance et tester en premier.ère les nouvelles fonctionnalités !", "iosInstructionsTitle": "Sous iOS :", From f92b4a90969f5ef2bda23699e5d237ab2c71ac95 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Tue, 16 Jul 2024 10:00:14 +0200 Subject: [PATCH 12/18] feat: peak error handling --- lib/pages/beta/beta.dart | 42 ++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 39f28e03b5..4d62613ce8 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -13,34 +13,23 @@ import 'package:url_launcher/url_launcher.dart'; class BetaJoinPage extends StatelessWidget { const BetaJoinPage({super.key}); - void joinBeta() async { + Future _launchUrl(String url, BuildContext context) async { try { - if (Platform.isIOS) { - if (await canLaunchUrl(Uri.parse(AppConfig.iosUrl))) { - await launchUrl(Uri.parse(AppConfig.iosUrl)); - } else { - await _launchUrlOrThrow(AppConfig.appleBetaUrl); - } - } else if (Platform.isAndroid) { - if (await canLaunchUrl(Uri.parse(AppConfig.androidUrl))) { - await launchUrl(Uri.parse(AppConfig.androidUrl)); - } else { - await _launchUrlOrThrow(AppConfig.androidBetaUrl); - } + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl(Uri.parse(url)); + return true; } } catch (e) { if (kDebugMode) { print('Error launching URL: $e'); } + final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + if (kDebugMode) { + print('Error launching Apple Beta URL: $e'); + } } - } - - Future _launchUrlOrThrow(String url) async { - if (await canLaunchUrl(Uri.parse(url))) { - await launchUrl(Uri.parse(url)); - } else { - throw 'Could not launch $url'; - } + return false; } Future joinGroup({ @@ -183,7 +172,7 @@ class BetaJoinPage extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - await _launchUrlOrThrow(AppConfig.testflightAppUrl); + await _launchUrl(AppConfig.testflightAppUrl, context); }, child: Text(L10n.of(context)!.downloadTestflightButton), ), @@ -195,7 +184,7 @@ class BetaJoinPage extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - await _launchUrlOrThrow(AppConfig.appleBetaUrl); + await _launchUrl(AppConfig.appleBetaUrl, context); }, child: Text(L10n.of(context)!.downloadBetaIOSButton), ), @@ -223,10 +212,9 @@ class BetaJoinPage extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - try { - await _launchUrlOrThrow(AppConfig.playStoreUrl); - } catch (e) { - await _launchUrlOrThrow(AppConfig.androidBetaUrl); + bool success = await _launchUrl(AppConfig.playStoreUrl, context); + if (!success) { + await _launchUrl(AppConfig.androidBetaUrl, context); } }, child: Text(L10n.of(context)!.downloadBetaAndroidButton), From 423db1d72db39ee6e2a2824943e6b9fd61f6a617 Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Tue, 16 Jul 2024 10:04:01 +0200 Subject: [PATCH 13/18] feat: delete room server --- lib/pages/beta/beta.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 4d62613ce8..6d63c87ba8 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -69,11 +69,9 @@ class BetaJoinPage extends StatelessWidget { context: context, future: () async { try { - // Retrieve participating servers - final servers = roomAliasResult.servers ?? ['staging.tawkie.fr']; final waitForRoom = client.waitForRoomInSync(roomId, join: true); - await client.joinRoom(roomId, serverName: servers); + await client.joinRoom(roomId); await waitForRoom; return roomId; From 22e8de19644a2942608f29da398d08b322f1f3ef Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 18 Jul 2024 10:07:45 +0200 Subject: [PATCH 14/18] feat: is mobile condition --- .../chat_list/client_chooser_button.dart | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 3cc639bbe1..3014cdbc1d 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -6,6 +6,7 @@ import 'package:go_router/go_router.dart'; import 'package:keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:matrix/matrix.dart'; import 'package:tawkie/utils/fluffy_share.dart'; +import 'package:tawkie/utils/platform_infos.dart'; import 'package:tawkie/widgets/avatar.dart'; import 'package:tawkie/widgets/matrix.dart'; @@ -79,16 +80,18 @@ class ClientChooserButton extends StatelessWidget { ], ), ), - PopupMenuItem( - value: SettingsAction.joinBeta, - child: Row( - children: [ - const Icon(Icons.new_releases), - const SizedBox(width: 18), - Text("Rejoindre la bêta"), - ], + // Check if the device is mobile + if (PlatformInfos.isMobile) + PopupMenuItem( + value: SettingsAction.joinBeta, + child: Row( + children: [ + const Icon(Icons.new_releases), + const SizedBox(width: 18), + Text("Rejoindre la bêta"), + ], + ), ), - ), PopupMenuItem( value: SettingsAction.settings, child: Row( From 528f0f07207387bfce75f403ca83503ba32a127e Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 18 Jul 2024 10:16:08 +0200 Subject: [PATCH 15/18] feat: L10n translate add/modify --- assets/l10n/intl_en.arb | 1 - assets/l10n/intl_fr.arb | 1 - lib/pages/beta/beta.dart | 2 +- lib/pages/chat_list/client_chooser_button.dart | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index e070f9c36d..9a4a11f3ff 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2689,7 +2689,6 @@ "iosInstructionsTitle": "On iOS:", "installTestflight": "- Install Apple Testflight", "downloadTestflightButton": "Download Apple Testflight", - "joinBetaTitleIOS": "- Join the Beta", "downloadBetaIOSButton": "Download the iOS Beta", "joinBetaGroup": "- Join the Tawkie Beta group: #beta", "androidInstructionsTitle": "On Android:", diff --git a/assets/l10n/intl_fr.arb b/assets/l10n/intl_fr.arb index a760031e5a..fc7e6ca077 100644 --- a/assets/l10n/intl_fr.arb +++ b/assets/l10n/intl_fr.arb @@ -2505,7 +2505,6 @@ "iosInstructionsTitle": "Sous iOS :", "installTestflight": "- Installer Apple Testflight", "downloadTestflightButton": "Télécharger Apple Testflight", - "joinBetaTitleIOS": "- Rejoindre la Beta", "downloadBetaIOSButton": "Télécharger la Beta iOS", "joinBetaGroup": "- Rejoindre le groupe Tawkie de la Beta : #beta", "androidInstructionsTitle": "Sous Android :", diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 6d63c87ba8..07e056bdc0 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -176,7 +176,7 @@ class BetaJoinPage extends StatelessWidget { ), const Divider(thickness: 1), Text( - L10n.of(context)!.joinBetaTitleIOS, + L10n.of(context)!.joinBetaTitle, style: const TextStyle(fontSize: 16), ), const SizedBox(height: 10.0), diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 3014cdbc1d..b0d2d13d67 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -88,7 +88,7 @@ class ClientChooserButton extends StatelessWidget { children: [ const Icon(Icons.new_releases), const SizedBox(width: 18), - Text("Rejoindre la bêta"), + Text(L10n.of(context)!.joinBetaTitle), ], ), ), From bbe965f407564a4a314e9d2721fb5f3792dbfeac Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 18 Jul 2024 10:31:31 +0200 Subject: [PATCH 16/18] feat: refact code --- lib/pages/beta/android_instructions.dart | 57 ++++++++++++++ lib/pages/beta/beta.dart | 98 ++---------------------- lib/pages/beta/ios_instructions.dart | 66 ++++++++++++++++ 3 files changed, 128 insertions(+), 93 deletions(-) create mode 100644 lib/pages/beta/android_instructions.dart create mode 100644 lib/pages/beta/ios_instructions.dart diff --git a/lib/pages/beta/android_instructions.dart b/lib/pages/beta/android_instructions.dart new file mode 100644 index 0000000000..4298af81ff --- /dev/null +++ b/lib/pages/beta/android_instructions.dart @@ -0,0 +1,57 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:tawkie/config/app_config.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class AndroidInstructions extends StatelessWidget { + const AndroidInstructions({super.key}); + + Future _launchUrl(String url, BuildContext context) async { + try { + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl(Uri.parse(url)); + return true; + } + } catch (e) { + if (kDebugMode) { + print('Error to lauch url: $e'); + } + final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + return false; + } + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + L10n.of(context)!.androidInstructionsTitle, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + L10n.of(context)!.joinBetaPlayStore, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + bool success = await _launchUrl(AppConfig.playStoreUrl, context); + if (!success) { + await _launchUrl(AppConfig.androidBetaUrl, context); + } + }, + child: Text(L10n.of(context)!.downloadBetaAndroidButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), + ), + ], + ); + } +} diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index 07e056bdc0..d4533773b2 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -8,30 +8,13 @@ import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; import 'package:tawkie/config/app_config.dart'; import 'package:tawkie/widgets/matrix.dart'; -import 'package:url_launcher/url_launcher.dart'; + +import 'android_instructions.dart'; +import 'ios_instructions.dart'; class BetaJoinPage extends StatelessWidget { const BetaJoinPage({super.key}); - Future _launchUrl(String url, BuildContext context) async { - try { - if (await canLaunchUrl(Uri.parse(url))) { - await launchUrl(Uri.parse(url)); - return true; - } - } catch (e) { - if (kDebugMode) { - print('Error launching URL: $e'); - } - final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - if (kDebugMode) { - print('Error launching Apple Beta URL: $e'); - } - } - return false; - } - Future joinGroup({ required BuildContext context, }) async { @@ -139,8 +122,8 @@ class BetaJoinPage extends StatelessWidget { style: const TextStyle(fontSize: 16), ), const SizedBox(height: 20.0), - if (Platform.isIOS) _buildIOSInstructions(context), - if (Platform.isAndroid) _buildAndroidInstructions(context), + if (Platform.isIOS) const IOSInstructions(), + if (Platform.isAndroid) const AndroidInstructions(), const SizedBox(height: 10.0), ElevatedButton.icon( onPressed: () async { @@ -154,75 +137,4 @@ class BetaJoinPage extends StatelessWidget { ), ); } - - Widget _buildIOSInstructions(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - L10n.of(context)!.iosInstructionsTitle, - style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - L10n.of(context)!.installTestflight, - style: const TextStyle(fontSize: 16), - ), - const SizedBox(height: 10.0), - ElevatedButton( - onPressed: () async { - await _launchUrl(AppConfig.testflightAppUrl, context); - }, - child: Text(L10n.of(context)!.downloadTestflightButton), - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaTitle, - style: const TextStyle(fontSize: 16), - ), - const SizedBox(height: 10.0), - ElevatedButton( - onPressed: () async { - await _launchUrl(AppConfig.appleBetaUrl, context); - }, - child: Text(L10n.of(context)!.downloadBetaIOSButton), - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), - ], - ); - } - - Widget _buildAndroidInstructions(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - L10n.of(context)!.androidInstructionsTitle, - style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - Text( - L10n.of(context)!.joinBetaPlayStore, - style: const TextStyle(fontSize: 16), - ), - const SizedBox(height: 10.0), - ElevatedButton( - onPressed: () async { - bool success = await _launchUrl(AppConfig.playStoreUrl, context); - if (!success) { - await _launchUrl(AppConfig.androidBetaUrl, context); - } - }, - child: Text(L10n.of(context)!.downloadBetaAndroidButton), - ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), - ], - ); - } } diff --git a/lib/pages/beta/ios_instructions.dart b/lib/pages/beta/ios_instructions.dart new file mode 100644 index 0000000000..21946f9918 --- /dev/null +++ b/lib/pages/beta/ios_instructions.dart @@ -0,0 +1,66 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:tawkie/config/app_config.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class IOSInstructions extends StatelessWidget { + const IOSInstructions({super.key}); + + Future _launchUrl(String url, BuildContext context) async { + try { + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl(Uri.parse(url)); + return true; + } + } catch (e) { + if (kDebugMode) { + print('Error to lauch url: $e'); + } + final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + return false; + } + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + L10n.of(context)!.iosInstructionsTitle, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + Text( + L10n.of(context)!.installTestflight, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + await _launchUrl(AppConfig.testflightAppUrl, context); + }, + child: Text(L10n.of(context)!.downloadTestflightButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaTitle, + style: const TextStyle(fontSize: 16), + ), + const SizedBox(height: 10.0), + ElevatedButton( + onPressed: () async { + await _launchUrl(AppConfig.appleBetaUrl, context); + }, + child: Text(L10n.of(context)!.downloadBetaIOSButton), + ), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), + ), + ], + ); + } +} From b07dbdc7810dd8f5a92d7c160d2f8867c58e0973 Mon Sep 17 00:00:00 2001 From: Paul ALNET Date: Tue, 23 Jul 2024 17:40:35 +0200 Subject: [PATCH 17/18] refactor: duplicate _launchUrl method --- lib/pages/beta/android_instructions.dart | 25 ++++-------------------- lib/pages/beta/instructions.dart | 25 ++++++++++++++++++++++++ lib/pages/beta/ios_instructions.dart | 25 ++++-------------------- 3 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 lib/pages/beta/instructions.dart diff --git a/lib/pages/beta/android_instructions.dart b/lib/pages/beta/android_instructions.dart index 4298af81ff..35535717df 100644 --- a/lib/pages/beta/android_instructions.dart +++ b/lib/pages/beta/android_instructions.dart @@ -1,28 +1,11 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:tawkie/config/app_config.dart'; -import 'package:url_launcher/url_launcher.dart'; +import 'package:tawkie/pages/beta/instructions.dart'; -class AndroidInstructions extends StatelessWidget { +class AndroidInstructions extends BetaInstructions { const AndroidInstructions({super.key}); - Future _launchUrl(String url, BuildContext context) async { - try { - if (await canLaunchUrl(Uri.parse(url))) { - await launchUrl(Uri.parse(url)); - return true; - } - } catch (e) { - if (kDebugMode) { - print('Error to lauch url: $e'); - } - final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - } - return false; - } - @override Widget build(BuildContext context) { return Column( @@ -39,9 +22,9 @@ class AndroidInstructions extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - bool success = await _launchUrl(AppConfig.playStoreUrl, context); + final bool success = await openUrl(AppConfig.playStoreUrl, context); if (!success) { - await _launchUrl(AppConfig.androidBetaUrl, context); + await openUrl(AppConfig.androidBetaUrl, context); } }, child: Text(L10n.of(context)!.downloadBetaAndroidButton), diff --git a/lib/pages/beta/instructions.dart b/lib/pages/beta/instructions.dart new file mode 100644 index 0000000000..e764543c71 --- /dev/null +++ b/lib/pages/beta/instructions.dart @@ -0,0 +1,25 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:url_launcher/url_launcher.dart'; + +abstract class BetaInstructions extends StatelessWidget { + const BetaInstructions({super.key}); + + // Launch url in browser or device app + Future openUrl(String url, BuildContext context) async { + try { + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl(Uri.parse(url)); + return true; + } + } catch (e) { + if (kDebugMode) { + print('Error to lauch url: $e'); + } + final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + return false; + } +} diff --git a/lib/pages/beta/ios_instructions.dart b/lib/pages/beta/ios_instructions.dart index 21946f9918..9e0e180df2 100644 --- a/lib/pages/beta/ios_instructions.dart +++ b/lib/pages/beta/ios_instructions.dart @@ -1,28 +1,11 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:tawkie/config/app_config.dart'; -import 'package:url_launcher/url_launcher.dart'; +import 'package:tawkie/pages/beta/instructions.dart'; -class IOSInstructions extends StatelessWidget { +class IOSInstructions extends BetaInstructions { const IOSInstructions({super.key}); - Future _launchUrl(String url, BuildContext context) async { - try { - if (await canLaunchUrl(Uri.parse(url))) { - await launchUrl(Uri.parse(url)); - return true; - } - } catch (e) { - if (kDebugMode) { - print('Error to lauch url: $e'); - } - final snackBar = SnackBar(content: Text(L10n.of(context)!.tryAgain)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - } - return false; - } - @override Widget build(BuildContext context) { return Column( @@ -39,7 +22,7 @@ class IOSInstructions extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - await _launchUrl(AppConfig.testflightAppUrl, context); + await openUrl(AppConfig.testflightAppUrl, context); }, child: Text(L10n.of(context)!.downloadTestflightButton), ), @@ -51,7 +34,7 @@ class IOSInstructions extends StatelessWidget { const SizedBox(height: 10.0), ElevatedButton( onPressed: () async { - await _launchUrl(AppConfig.appleBetaUrl, context); + await openUrl(AppConfig.appleBetaUrl, context); }, child: Text(L10n.of(context)!.downloadBetaIOSButton), ), From 0e78b683b32fab21bd56ea6adb9f005b8fb7264f Mon Sep 17 00:00:00 2001 From: Paul ALNET Date: Tue, 23 Jul 2024 17:44:49 +0200 Subject: [PATCH 18/18] refactor: duplicate beta join group text --- lib/pages/beta/android_instructions.dart | 5 ----- lib/pages/beta/beta.dart | 5 +++++ lib/pages/beta/ios_instructions.dart | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/pages/beta/android_instructions.dart b/lib/pages/beta/android_instructions.dart index 35535717df..b2e6b2f792 100644 --- a/lib/pages/beta/android_instructions.dart +++ b/lib/pages/beta/android_instructions.dart @@ -29,11 +29,6 @@ class AndroidInstructions extends BetaInstructions { }, child: Text(L10n.of(context)!.downloadBetaAndroidButton), ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), ], ); } diff --git a/lib/pages/beta/beta.dart b/lib/pages/beta/beta.dart index d4533773b2..5383da4317 100644 --- a/lib/pages/beta/beta.dart +++ b/lib/pages/beta/beta.dart @@ -124,6 +124,11 @@ class BetaJoinPage extends StatelessWidget { const SizedBox(height: 20.0), if (Platform.isIOS) const IOSInstructions(), if (Platform.isAndroid) const AndroidInstructions(), + const Divider(thickness: 1), + Text( + L10n.of(context)!.joinBetaGroup, + style: const TextStyle(fontSize: 16), + ), const SizedBox(height: 10.0), ElevatedButton.icon( onPressed: () async { diff --git a/lib/pages/beta/ios_instructions.dart b/lib/pages/beta/ios_instructions.dart index 9e0e180df2..49c549e342 100644 --- a/lib/pages/beta/ios_instructions.dart +++ b/lib/pages/beta/ios_instructions.dart @@ -38,11 +38,6 @@ class IOSInstructions extends BetaInstructions { }, child: Text(L10n.of(context)!.downloadBetaIOSButton), ), - const Divider(thickness: 1), - Text( - L10n.of(context)!.joinBetaGroup, - style: const TextStyle(fontSize: 16), - ), ], ); }