Format and API Cleanup
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2023-09-18 07:55:07 -07:00
parent 9c9fa2f88f
commit 90ec07b7a5
6 changed files with 76 additions and 16 deletions

View File

@ -644,4 +644,8 @@ class MaterialLocalizationLu extends MaterialLocalizations {
// TODO: implement scrimOnTapHint
throw UnimplementedError();
}
@override
// TODO: implement scanTextButtonLabel
String get scanTextButtonLabel => throw UnimplementedError();
}

View File

@ -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");
}
}
}

View File

@ -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<FlwtchState>(context, listen: false).cwtch.DeactivatePeerEngine(onion);
this.contactList.contacts.forEach((element) {
element.status = "Disconnected";
});
this.serverList.servers.forEach((element) {
element.status = "Disconnected";
});
}
}

View File

@ -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,

View File

@ -234,14 +234,14 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
subtitle: Text(AppLocalizations.of(context)!.profileEnabledDescription),
value: Provider.of<ProfileInfoState>(context).enabled,
onChanged: (bool value) {
Provider.of<ProfileInfoState>(context).enabled = value;
Provider.of<ProfileInfoState>(context, listen: false).enabled = value;
if (value) {
Provider.of<FlwtchState>(context, listen: false).cwtch.ActivatePeerEngine(Provider.of<ProfileInfoState>(context).onion);
if (Provider.of<ProfileInfoState>(context).appearOffline == false) {
Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(Provider.of<ProfileInfoState>(context).onion, true, true, true);
Provider.of<FlwtchState>(context, listen: false).cwtch.ActivatePeerEngine(Provider.of<ProfileInfoState>(context, listen: false).onion);
if (Provider.of<ProfileInfoState>(context, listen: false).appearOffline == false) {
Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(Provider.of<ProfileInfoState>(context, listen: false).onion, true, true, true);
}
} else {
Provider.of<FlwtchState>(context, listen: false).cwtch.DeactivatePeerEngine(Provider.of<ProfileInfoState>(context).onion);
Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
}
},
activeTrackColor: Provider.of<Settings>(context).theme.defaultButtonColor,
@ -255,12 +255,12 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
subtitle: Text(AppLocalizations.of(context)!.profileAutostartDescription),
value: Provider.of<ProfileInfoState>(context).autostart,
onChanged: (bool value) {
Provider.of<ProfileInfoState>(context).autostart = value;
Provider.of<ProfileInfoState>(context, listen: false).autostart = value;
if (!Provider.of<ProfileInfoState>(context).onion.isEmpty) {
if (!Provider.of<ProfileInfoState>(context, listen: false).onion.isEmpty) {
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.SetProfileAttribute(Provider.of<ProfileInfoState>(context).onion, "profile.autostart", value ? "true" : "false");
.SetProfileAttribute(Provider.of<ProfileInfoState>(context, listen: false).onion, "profile.autostart", value ? "true" : "false");
}
},
activeTrackColor: Provider.of<Settings>(context).theme.defaultButtonColor,
@ -274,12 +274,16 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
subtitle: Text(AppLocalizations.of(context)!.profileAppearOfflineDescription),
value: Provider.of<ProfileInfoState>(context).appearOffline,
onChanged: (bool value) {
Provider.of<ProfileInfoState>(context).appearOffline = value;
if (!Provider.of<ProfileInfoState>(context).onion.isEmpty) {
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.SetProfileAttribute(Provider.of<ProfileInfoState>(context).onion, "profile.appear-offline", value ? "true" : "false");
Provider.of<ProfileInfoState>(context, listen: false).appearOffline = value;
var onion = Provider.of<ProfileInfoState>(context, listen: false).onion;
if (!onion.isEmpty) {
Provider.of<FlwtchState>(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<ProfileInfoState>(context, listen: false).enabled) {
Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
Provider.of<FlwtchState>(context, listen: false).cwtch.ActivatePeerEngine(onion);
Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
}
}
},
activeTrackColor: Provider.of<Settings>(context).theme.defaultButtonColor,

View File

@ -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<ContactsView> {
case ProfileStatusMenu.busy:
Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "busy");
break;
case ProfileStatusMenu.appearOffline:
Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
Provider.of<FlwtchState>(context, listen: false).cwtch.ActivatePeerEngine(onion);
Provider.of<FlwtchState>(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<ProfileInfoState>(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) => <PopupMenuEntry<ProfileStatusMenu>>[
@ -194,6 +215,15 @@ class _ContactsViewState extends State<ContactsView> {
value: ProfileStatusMenu.busy,
child: Text(AppLocalizations.of(context)!.availabilityStatusBusy!, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
),
PopupMenuItem<ProfileStatusMenu>(
value: ProfileStatusMenu.appearOffline,
child: Text(AppLocalizations.of(context)!.profileAppearOffline!, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
),
PopupMenuDivider(),
PopupMenuItem<ProfileStatusMenu>(
value: ProfileStatusMenu.editProfile,
child: Text(AppLocalizations.of(context)!.editProfile!, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
),
],
),
SizedBox(