From 0d1e7bb5a02c60c51eb838f6297ed950f61a8e9b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 12 Apr 2022 12:14:47 -0700 Subject: [PATCH] Add Hook into Add Contact Flow to better Gauge Intent (This the future we can expand this, use this information to better guide people) --- lib/l10n/intl_cy.arb | 3 +- lib/l10n/intl_da.arb | 3 +- lib/l10n/intl_de.arb | 3 +- lib/l10n/intl_el.arb | 3 +- lib/l10n/intl_en.arb | 3 +- lib/l10n/intl_es.arb | 3 +- lib/l10n/intl_fr.arb | 7 +-- lib/l10n/intl_it.arb | 3 +- lib/l10n/intl_lb.arb | 3 +- lib/l10n/intl_no.arb | 3 +- lib/l10n/intl_pl.arb | 3 +- lib/l10n/intl_pt.arb | 3 +- lib/l10n/intl_ro.arb | 3 +- lib/l10n/intl_ru.arb | 3 +- lib/licenses.dart | 1 - lib/views/addcontactview.dart | 69 +++++++++++----------------- lib/views/contactsview.dart | 85 +++++++++++++++++++++++++++++++++-- 17 files changed, 139 insertions(+), 62 deletions(-) diff --git a/lib/l10n/intl_cy.arb b/lib/l10n/intl_cy.arb index 8607bd1e..77e5a083 100644 --- a/lib/l10n/intl_cy.arb +++ b/lib/l10n/intl_cy.arb @@ -1,6 +1,7 @@ { "@@locale": "cy", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_da.arb b/lib/l10n/intl_da.arb index 37254a40..a07fca58 100644 --- a/lib/l10n/intl_da.arb +++ b/lib/l10n/intl_da.arb @@ -1,6 +1,7 @@ { "@@locale": "da", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index f9db6b7e..3deedbba 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -1,6 +1,7 @@ { "@@locale": "de", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_el.arb b/lib/l10n/intl_el.arb index 9abb7ca3..b6e196f6 100644 --- a/lib/l10n/intl_el.arb +++ b/lib/l10n/intl_el.arb @@ -1,6 +1,7 @@ { "@@locale": "el", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 48afba83..a924c3b4 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1,6 +1,7 @@ { "@@locale": "en", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index 7afe99f1..075a16e9 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -1,6 +1,7 @@ { "@@locale": "es", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index cce76738..4e134d74 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -1,8 +1,9 @@ { "@@locale": "fr", - "@@last_modified": "2022-04-06T22:31:33+02:00", - "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", - "formattingExperiment": "Message Formatting", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", + "messageFormattingDescription": "Activer la mise en forme de texte enrichi dans les messages affichés, par exemple **gras** et *italique*", + "formattingExperiment": "Mise en forme des messages", "clickableLinksWarning": "L'ouverture de cette URL lancera une application en dehors de Cwtch et peut révéler des métadonnées ou compromettre la sécurité de Cwtch. N'ouvrez que les URLs de personnes en qui vous avez confiance. Êtes-vous sûr de vouloir continuer ?", "clickableLinksCopy": "Copier l'URL", "clickableLinkOpen": "Ouvrir l'URL", diff --git a/lib/l10n/intl_it.arb b/lib/l10n/intl_it.arb index a244db96..34fd3fa9 100644 --- a/lib/l10n/intl_it.arb +++ b/lib/l10n/intl_it.arb @@ -1,6 +1,7 @@ { "@@locale": "it", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_lb.arb b/lib/l10n/intl_lb.arb index 8124b189..cf33de01 100644 --- a/lib/l10n/intl_lb.arb +++ b/lib/l10n/intl_lb.arb @@ -1,6 +1,7 @@ { "@@locale": "lb", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_no.arb b/lib/l10n/intl_no.arb index 16e70ade..295c2538 100644 --- a/lib/l10n/intl_no.arb +++ b/lib/l10n/intl_no.arb @@ -1,6 +1,7 @@ { "@@locale": "no", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_pl.arb b/lib/l10n/intl_pl.arb index 5654c4c0..ce83b136 100644 --- a/lib/l10n/intl_pl.arb +++ b/lib/l10n/intl_pl.arb @@ -1,6 +1,7 @@ { "@@locale": "pl", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_pt.arb b/lib/l10n/intl_pt.arb index 9a3fd2a9..a48754a3 100644 --- a/lib/l10n/intl_pt.arb +++ b/lib/l10n/intl_pt.arb @@ -1,6 +1,7 @@ { "@@locale": "pt", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_ro.arb b/lib/l10n/intl_ro.arb index ac447d71..051e69b8 100644 --- a/lib/l10n/intl_ro.arb +++ b/lib/l10n/intl_ro.arb @@ -1,6 +1,7 @@ { "@@locale": "ro", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index cc1025cc..b7be29a1 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -1,6 +1,7 @@ { "@@locale": "ru", - "@@last_modified": "2022-04-06T22:31:33+02:00", + "@@last_modified": "2022-04-12T20:56:53+02:00", + "thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings", "messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*", "formattingExperiment": "Message Formatting", "clickableLinkError": "Error encountered while attempting to open URL", diff --git a/lib/licenses.dart b/lib/licenses.dart index 1d58b39c..c1cc96e0 100644 --- a/lib/licenses.dart +++ b/lib/licenses.dart @@ -343,5 +343,4 @@ SOFTWARE.'''); See the License for the specific language governing permissions and limitations under the License. '''); - } diff --git a/lib/views/addcontactview.dart b/lib/views/addcontactview.dart index c84864e0..1a8bf56a 100644 --- a/lib/views/addcontactview.dart +++ b/lib/views/addcontactview.dart @@ -21,6 +21,10 @@ import '../main.dart'; /// NOTE: This view makes use of the global Error Handler to receive events from the Cwtch Library (for validating /// error states caused by incorrect import string or duplicate requests to add a specific contact) class AddContactView extends StatefulWidget { + final newGroup; + + const AddContactView({Key? key, this.newGroup}) : super(key: key); + @override _AddContactViewState createState() => _AddContactViewState(); } @@ -52,9 +56,10 @@ class _AddContactViewState extends State { ctrlrOnion.text = Provider.of(context).onion; /// We display a different number of tabs depending on the experiment setup - bool groupsEnabled = Provider.of(context).isExperimentEnabled(TapirGroupsExperiment); - return Consumer(builder: (context, globalErrorHandler, child) { + bool groupsEnabled = Provider.of(context, listen: false).isExperimentEnabled(TapirGroupsExperiment); + return Consumer(builder: (bcontext, globalErrorHandler, child) { return DefaultTabController( + initialIndex: widget.newGroup && groupsEnabled ? 1 : 0, length: groupsEnabled ? 2 : 1, child: Column(children: [ (groupsEnabled ? getTabBarWithGroups() : getTabBarWithAddPeerOnly()), @@ -62,10 +67,10 @@ class _AddContactViewState extends State { child: TabBarView( children: (groupsEnabled ? [ - addPeerTab(), - addGroupTab(), + addPeerTab(bcontext), + addGroupTab(bcontext), ] - : [addPeerTab()]), + : [addPeerTab(bcontext)]), )), ])); }); @@ -105,7 +110,7 @@ class _AddContactViewState extends State { /// The Add Peer Tab allows a peer to add a specific non-group peer to their contact lists /// We also provide a convenient way to copy their onion. - Widget addPeerTab() { + Widget addPeerTab(bcontext) { return Scrollbar( child: SingleChildScrollView( clipBehavior: Clip.antiAlias, @@ -152,18 +157,18 @@ class _AddContactViewState extends State { return null; }, onChanged: (String importBundle) async { - var profileOnion = Provider.of(context, listen: false).onion; - Provider.of(context, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", "")); + var profileOnion = Provider.of(bcontext, listen: false).onion; + Provider.of(bcontext, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", "")); Future.delayed(const Duration(milliseconds: 500), () { if (globalErrorHandler.importBundleSuccess) { // TODO: This isn't ideal, but because onChange can be fired during this future check // and because the context can change after being popped we have this kind of double assertion... // There is probably a better pattern to handle this... - if (AppLocalizations.of(context) != null) { - final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - Navigator.popUntil(context, (route) => route.settings.name == "conversations"); + if (AppLocalizations.of(bcontext) != null) { + final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle)); + ScaffoldMessenger.of(bcontext).showSnackBar(snackBar); + Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations"); } } }); @@ -174,10 +179,10 @@ class _AddContactViewState extends State { } /// TODO Add Group Pane - Widget addGroupTab() { + Widget addGroupTab(bcontext) { // TODO We should replace with with a "Paste in Server Key Bundle" - if (Provider.of(context).serverList.servers.isEmpty) { - return Text(AppLocalizations.of(context)!.addServerFirst); + if (Provider.of(bcontext).serverList.servers.isEmpty) { + return Text(AppLocalizations.of(bcontext)!.addServerFirst); } return Scrollbar( @@ -205,11 +210,7 @@ class _AddContactViewState extends State { }, isExpanded: true, // magic property value: server, - items: Provider.of(context) - .serverList - .servers - .where((serverInfo) => serverInfo.status == "Synced") - .map>((RemoteServerInfoState serverInfo) { + items: Provider.of(bcontext).serverList.servers.map>((RemoteServerInfoState serverInfo) { return DropdownMenuItem( value: serverInfo.onion, child: Text( @@ -221,13 +222,13 @@ class _AddContactViewState extends State { SizedBox( height: 20, ), - CwtchLabel(label: AppLocalizations.of(context)!.groupNameLabel), + CwtchLabel(label: AppLocalizations.of(bcontext)!.groupNameLabel), SizedBox( height: 20, ), CwtchTextField( controller: ctrlrGroupName, - hintText: AppLocalizations.of(context)!.groupNameLabel, + hintText: AppLocalizations.of(bcontext)!.groupNameLabel, onChanged: (newValue) {}, validator: (value) {}, ), @@ -236,12 +237,12 @@ class _AddContactViewState extends State { ), ElevatedButton( onPressed: () { - var profileOnion = Provider.of(context, listen: false).onion; - Provider.of(context, listen: false).cwtch.CreateGroup(profileOnion, server, ctrlrGroupName.text); + var profileOnion = Provider.of(bcontext, listen: false).onion; + Provider.of(bcontext, listen: false).cwtch.CreateGroup(profileOnion, server, ctrlrGroupName.text); Future.delayed(const Duration(milliseconds: 500), () { final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + " " + ctrlrGroupName.text)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - Navigator.pop(context); + ScaffoldMessenger.of(bcontext).showSnackBar(snackBar); + Navigator.pop(bcontext); }); }, child: Text(AppLocalizations.of(context)!.createGroupBtn), @@ -249,20 +250,4 @@ class _AddContactViewState extends State { ], ))))); } - - /// TODO Manage Servers Tab - Widget manageServersTab() { - final tiles = Provider.of(context).serverList.servers.map((RemoteServerInfoState server) { - return ChangeNotifierProvider.value( - value: server, - child: ListTile( - title: Text(server.onion), - )); - }); - final divided = ListTile.divideTiles( - context: context, - tiles: tiles, - ).toList(); - return ListView(children: divided); - } } diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 1724e6b6..4109f39f 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -128,7 +128,7 @@ class _ContactsViewState extends State { actions: getActions(context), ), floatingActionButton: FloatingActionButton( - onPressed: _pushAddContact, + onPressed: _modalAddImportChoice, tooltip: AppLocalizations.of(context)!.tooltipAddContact, child: const Icon(CwtchIcons.person_add_alt_1_24px), ), @@ -204,14 +204,18 @@ class _ContactsViewState extends State { return RepaintBoundary(child: ListView(children: divided)); } - void _pushAddContact() { + void _pushAddContact(bool newGroup) { + // close modal + Navigator.popUntil(context, (route) => route.settings.name == "conversations"); + + // open add contact / create group pane Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext bcontext) { return MultiProvider( providers: [ ChangeNotifierProvider.value(value: Provider.of(context)), ], - child: AddContactView(), + child: AddContactView(newGroup: newGroup), ); }, )); @@ -228,4 +232,79 @@ class _ContactsViewState extends State { }, )); } + + void _modalAddImportChoice() { + bool groupsEnabled = Provider.of(context, listen: false).isExperimentEnabled(TapirGroupsExperiment); + + showModalBottomSheet( + context: context, + isScrollControlled: true, + builder: (BuildContext context) { + return Padding( + padding: MediaQuery.of(context).viewInsets, + child: RepaintBoundary( + child: Container( + height: 200, // bespoke value courtesy of the [TextField] docs + child: Center( + child: Padding( + padding: EdgeInsets.all(10.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Spacer(), + Expanded( + child: Tooltip( + message: AppLocalizations.of(context)!.tooltipAddContact, + child: ElevatedButton( + child: Text(AppLocalizations.of(context)!.addContact, semanticsLabel: AppLocalizations.of(context)!.addContact), + onPressed: () { + _pushAddContact(false); + }, + ))), + Spacer() + ]), + SizedBox( + height: 20, + ), + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Spacer(), + Expanded( + child: Tooltip( + message: groupsEnabled ? AppLocalizations.of(context)!.addServerTooltip : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled, + child: ElevatedButton( + child: Text(AppLocalizations.of(context)!.addServerTitle, semanticsLabel: AppLocalizations.of(context)!.addServerTitle), + onPressed: groupsEnabled + ? () { + _pushAddContact(false); + } + : null, + )), + ), + Spacer() + ]), + SizedBox( + height: 20, + ), + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Spacer(), + Expanded( + child: Tooltip( + message: groupsEnabled ? AppLocalizations.of(context)!.createGroupTitle : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled, + child: ElevatedButton( + child: Text(AppLocalizations.of(context)!.createGroupTitle, semanticsLabel: AppLocalizations.of(context)!.createGroupTitle), + onPressed: groupsEnabled + ? () { + _pushAddContact(true); + } + : null, + ))), + Spacer() + ]), + ], + ))), + ))); + }); + } }