From 90ec07b7a542e834308a4f4aaaab411eaa98e5a0 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 18 Sep 2023 07:55:07 -0700 Subject: [PATCH] Format and API Cleanup --- lib/l10n/custom_material_delegate.dart | 4 ++++ lib/models/contact.dart | 5 ++++ lib/models/profile.dart | 17 ++++++++++++++ lib/themes/opaque.dart | 2 +- lib/views/addeditprofileview.dart | 32 +++++++++++++++----------- lib/views/contactsview.dart | 32 +++++++++++++++++++++++++- 6 files changed, 76 insertions(+), 16 deletions(-) diff --git a/lib/l10n/custom_material_delegate.dart b/lib/l10n/custom_material_delegate.dart index fd43bb95..59041c9c 100644 --- a/lib/l10n/custom_material_delegate.dart +++ b/lib/l10n/custom_material_delegate.dart @@ -644,4 +644,8 @@ class MaterialLocalizationLu extends MaterialLocalizations { // TODO: implement scrimOnTapHint throw UnimplementedError(); } + + @override + // TODO: implement scanTextButtonLabel + String get scanTextButtonLabel => throw UnimplementedError(); } diff --git a/lib/models/contact.dart b/lib/models/contact.dart index d370ddb6..ae9dc713 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -431,6 +431,9 @@ class ContactInfoState extends ChangeNotifier { return theme.portraitOnlineAwayColor; case ProfileStatusMenu.busy: return theme.portraitOnlineBusyColor; + default: + // noop not a valid status... + break; } } return theme.portraitOfflineBorderColor; @@ -462,6 +465,8 @@ class ContactInfoState extends ChangeNotifier { return AppLocalizations.of(context)!.availabilityStatusAway; case ProfileStatusMenu.busy: return AppLocalizations.of(context)!.availabilityStatusBusy; + default: + throw UnimplementedError("not a valid status"); } } } diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 63860da1..081b5aaa 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -4,8 +4,10 @@ import 'package:cwtch/config.dart'; import 'package:cwtch/models/remoteserver.dart'; import 'package:cwtch/models/search.dart'; import 'package:flutter/widgets.dart'; +import 'package:provider/provider.dart'; import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; +import '../main.dart'; import '../themes/opaque.dart'; import '../views/contactsview.dart'; import 'contact.dart'; @@ -472,6 +474,21 @@ class ProfileInfoState extends ChangeNotifier { return theme.portraitOnlineAwayColor; case ProfileStatusMenu.busy: return theme.portraitOnlineBusyColor; + default: + throw UnimplementedError("not a valid status"); } } + + // during deactivation it is possible that the event bus is cleaned up prior to statuses being updated + // this method nicely cleans up our current state so that the UI functions as expected. + // FIXME: Cwtch should be sending these events prior to shutting down the engine... + void deactivatePeerEngine(BuildContext context) { + Provider.of(context, listen: false).cwtch.DeactivatePeerEngine(onion); + this.contactList.contacts.forEach((element) { + element.status = "Disconnected"; + }); + this.serverList.servers.forEach((element) { + element.status = "Disconnected"; + }); + } } diff --git a/lib/themes/opaque.dart b/lib/themes/opaque.dart index b607e0bf..9e3f7e6d 100644 --- a/lib/themes/opaque.dart +++ b/lib/themes/opaque.dart @@ -192,7 +192,7 @@ ThemeData mkThemeData(Settings opaque) { ), ), - scrollbarTheme: ScrollbarThemeData(isAlwaysShown: false, thumbColor: MaterialStateProperty.all(opaque.current().scrollbarDefaultColor)), + scrollbarTheme: ScrollbarThemeData(thumbVisibility: MaterialStateProperty.all(false), thumbColor: MaterialStateProperty.all(opaque.current().scrollbarDefaultColor)), tabBarTheme: TabBarTheme( labelColor: opaque.current().mainTextColor, unselectedLabelColor: opaque.current().mainTextColor, diff --git a/lib/views/addeditprofileview.dart b/lib/views/addeditprofileview.dart index 8a0419cf..2d1478a1 100644 --- a/lib/views/addeditprofileview.dart +++ b/lib/views/addeditprofileview.dart @@ -234,14 +234,14 @@ class _AddEditProfileViewState extends State { subtitle: Text(AppLocalizations.of(context)!.profileEnabledDescription), value: Provider.of(context).enabled, onChanged: (bool value) { - Provider.of(context).enabled = value; + Provider.of(context, listen: false).enabled = value; if (value) { - Provider.of(context, listen: false).cwtch.ActivatePeerEngine(Provider.of(context).onion); - if (Provider.of(context).appearOffline == false) { - Provider.of(context, listen: false).cwtch.ConfigureConnections(Provider.of(context).onion, true, true, true); + Provider.of(context, listen: false).cwtch.ActivatePeerEngine(Provider.of(context, listen: false).onion); + if (Provider.of(context, listen: false).appearOffline == false) { + Provider.of(context, listen: false).cwtch.ConfigureConnections(Provider.of(context, listen: false).onion, true, true, true); } } else { - Provider.of(context, listen: false).cwtch.DeactivatePeerEngine(Provider.of(context).onion); + Provider.of(context, listen: false).deactivatePeerEngine(context); } }, activeTrackColor: Provider.of(context).theme.defaultButtonColor, @@ -255,12 +255,12 @@ class _AddEditProfileViewState extends State { subtitle: Text(AppLocalizations.of(context)!.profileAutostartDescription), value: Provider.of(context).autostart, onChanged: (bool value) { - Provider.of(context).autostart = value; + Provider.of(context, listen: false).autostart = value; - if (!Provider.of(context).onion.isEmpty) { + if (!Provider.of(context, listen: false).onion.isEmpty) { Provider.of(context, listen: false) .cwtch - .SetProfileAttribute(Provider.of(context).onion, "profile.autostart", value ? "true" : "false"); + .SetProfileAttribute(Provider.of(context, listen: false).onion, "profile.autostart", value ? "true" : "false"); } }, activeTrackColor: Provider.of(context).theme.defaultButtonColor, @@ -274,12 +274,16 @@ class _AddEditProfileViewState extends State { subtitle: Text(AppLocalizations.of(context)!.profileAppearOfflineDescription), value: Provider.of(context).appearOffline, onChanged: (bool value) { - Provider.of(context).appearOffline = value; - - if (!Provider.of(context).onion.isEmpty) { - Provider.of(context, listen: false) - .cwtch - .SetProfileAttribute(Provider.of(context).onion, "profile.appear-offline", value ? "true" : "false"); + Provider.of(context, listen: false).appearOffline = value; + var onion = Provider.of(context, listen: false).onion; + if (!onion.isEmpty) { + Provider.of(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.appear-offline", value ? "true" : "false"); + // if the profile is already enabled, then cycle the peer engine... + if (value == true && Provider.of(context, listen: false).enabled) { + Provider.of(context, listen: false).deactivatePeerEngine(context); + Provider.of(context, listen: false).cwtch.ActivatePeerEngine(onion); + Provider.of(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false); + } } }, activeTrackColor: Provider.of(context).theme.defaultButtonColor, diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 3799ce74..78dbc60e 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -25,11 +25,12 @@ import 'addcontactview.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:qr_flutter/qr_flutter.dart'; +import 'addeditprofileview.dart'; import 'messageview.dart'; enum ShareMenu { copyCode, qrcode } -enum ProfileStatusMenu { available, away, busy } +enum ProfileStatusMenu { available, away, busy, appearOffline, editProfile } class ContactsView extends StatefulWidget { const ContactsView({Key? key}) : super(key: key); @@ -179,6 +180,26 @@ class _ContactsViewState extends State { case ProfileStatusMenu.busy: Provider.of(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "busy"); break; + case ProfileStatusMenu.appearOffline: + Provider.of(context, listen: false).deactivatePeerEngine(context); + Provider.of(context, listen: false).cwtch.ActivatePeerEngine(onion); + Provider.of(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false); + break; + case ProfileStatusMenu.editProfile: + Navigator.of(context).push( + PageRouteBuilder( + pageBuilder: (bcontext, a1, a2) { + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: Provider.of(context, listen: false)), + ], + builder: (context, widget) => AddEditProfileView(key: Key('addprofile')), + ); + }, + transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child), + transitionDuration: Duration(milliseconds: 200), + ), + ); } }, itemBuilder: (BuildContext context) => >[ @@ -194,6 +215,15 @@ class _ContactsViewState extends State { value: ProfileStatusMenu.busy, child: Text(AppLocalizations.of(context)!.availabilityStatusBusy!, style: Provider.of(context, listen: false).scaleFonts(defaultTextButtonStyle)), ), + PopupMenuItem( + value: ProfileStatusMenu.appearOffline, + child: Text(AppLocalizations.of(context)!.profileAppearOffline!, style: Provider.of(context, listen: false).scaleFonts(defaultTextButtonStyle)), + ), + PopupMenuDivider(), + PopupMenuItem( + value: ProfileStatusMenu.editProfile, + child: Text(AppLocalizations.of(context)!.editProfile!, style: Provider.of(context, listen: false).scaleFonts(defaultTextButtonStyle)), + ), ], ), SizedBox(