From ef1ded4494743d66ebef9e6b645180c38772c450 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 17 Mar 2025 22:00:26 -0400 Subject: [PATCH] updates and cleanup --- assets/i18n/en.json | 5 +- lib/chat/cubits/chat_component_cubit.dart | 15 +++-- lib/contacts/views/contact_item_widget.dart | 16 ++++- lib/contacts/views/contacts_browser.dart | 14 ++--- lib/contacts/views/contacts_dialog.dart | 2 +- lib/settings/settings_page.dart | 66 ++++++++++++--------- lib/theme/views/brightness_preferences.dart | 35 +++++------ lib/theme/views/color_preferences.dart | 39 ++++++------ lib/theme/views/wallpaper_preferences.dart | 35 +++++------ pubspec.lock | 13 ++-- pubspec.yaml | 10 ++-- 11 files changed, 142 insertions(+), 108 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index 31316d3..61bb802 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -100,7 +100,8 @@ "yes": "Yes", "no": "No", "update": "Update", - "waiting_for_network": "Waiting For Network" + "waiting_for_network": "Waiting For Network", + "chat": "Chat" }, "toast": { "error": "Error", @@ -127,7 +128,7 @@ "contacts": "Contacts", "edit_contact": "Edit Contact", "invitations": "Invitations", - "no_contact_selected": "Double-click a contact to edit it", + "no_contact_selected": "Select a contact to view or edit", "new_chat": "Open Chat", "close_contact": "Close Contact" }, diff --git a/lib/chat/cubits/chat_component_cubit.dart b/lib/chat/cubits/chat_component_cubit.dart index 326a597..9e50e02 100644 --- a/lib/chat/cubits/chat_component_cubit.dart +++ b/lib/chat/cubits/chat_component_cubit.dart @@ -50,8 +50,11 @@ class ChatComponentCubit extends Cubit { messageWindow: const AsyncLoading(), title: '', )) { + // Immediate Init + _init(); + // Async Init - _initWait.add(_init); + _initWait.add(_initAsync); } factory ChatComponentCubit.singleContact( @@ -68,7 +71,7 @@ class ChatComponentCubit extends Cubit { messagesCubit: messagesCubit, ); - Future _init(Completer _cancel) async { + void _init() { // Get local user info and account record cubit _localUserIdentityKey = _accountInfo.identityTypedPublicKey; @@ -77,9 +80,6 @@ class ChatComponentCubit extends Cubit { _accountRecordCubit.stream.listen(_onChangedAccountRecord); _onChangedAccountRecord(_accountRecordCubit.state); - // Subscribe to remote user info - await _updateConversationSubscriptions(); - // Subscribe to messages _messagesSubscription = _messagesCubit.stream.listen(_onChangedMessages); _onChangedMessages(_messagesCubit.state); @@ -90,6 +90,11 @@ class ChatComponentCubit extends Cubit { _onChangedContacts(_contactListCubit.state); } + Future _initAsync(Completer _cancel) async { + // Subscribe to remote user info + await _updateConversationSubscriptions(); + } + @override Future close() async { await _initWait(); diff --git a/lib/contacts/views/contact_item_widget.dart b/lib/contacts/views/contact_item_widget.dart index a0f2fbc..4614f27 100644 --- a/lib/contacts/views/contact_item_widget.dart +++ b/lib/contacts/views/contact_item_widget.dart @@ -68,15 +68,27 @@ class ContactItemWidget extends StatelessWidget { : () => singleFuture((this, _kOnTap), () async { await _onTap(_contact); }), - endActions: [ + startActions: [ if (_onDoubleTap != null) + SliderTileAction( + //icon: Icons.edit, + label: translate('button.chat'), + actionScale: ScaleKind.secondary, + onPressed: (_context) => + singleFuture((this, _kOnTap), () async { + await _onDoubleTap(_contact); + }), + ), + ], + endActions: [ + if (_onTap != null) SliderTileAction( //icon: Icons.edit, label: translate('button.edit'), actionScale: ScaleKind.secondary, onPressed: (_context) => singleFuture((this, _kOnTap), () async { - await _onDoubleTap(_contact); + await _onTap(_contact); }), ), if (_onDelete != null) diff --git a/lib/contacts/views/contacts_browser.dart b/lib/contacts/views/contacts_browser.dart index 7040af5..c5a6b22 100644 --- a/lib/contacts/views/contacts_browser.dart +++ b/lib/contacts/views/contacts_browser.dart @@ -39,14 +39,14 @@ class ContactsBrowserElement { class ContactsBrowser extends StatefulWidget { const ContactsBrowser( {required this.onContactSelected, - required this.onChatStarted, + required this.onStartChat, this.selectedContactRecordKey, super.key}); @override State createState() => _ContactsBrowserState(); final Future Function(proto.Contact? contact) onContactSelected; - final Future Function(proto.Contact contact) onChatStarted; + final Future Function(proto.Contact contact) onStartChat; final TypedKey? selectedContactRecordKey; @override @@ -60,7 +60,7 @@ class ContactsBrowser extends StatefulWidget { 'onContactSelected', onContactSelected)) ..add( ObjectFlagProperty Function(proto.Contact contact)>.has( - 'onChatStarted', onChatStarted)); + 'onStartChat', onStartChat)); } } @@ -238,8 +238,8 @@ class _ContactsBrowserState extends State selected: widget.selectedContactRecordKey == contact.localConversationRecordKey.toVeilid(), disabled: false, - onDoubleTap: _onTapContact, - onTap: _onStartChat, + onDoubleTap: _onStartChat, + onTap: _onSelectContact, onDelete: _onDeleteContact) .paddingLTRB(0, 4, 0, 0); case ContactsBrowserElementKind.invitation: @@ -293,12 +293,12 @@ class _ContactsBrowserState extends State ]); } - Future _onTapContact(proto.Contact contact) async { + Future _onSelectContact(proto.Contact contact) async { await widget.onContactSelected(contact); } Future _onStartChat(proto.Contact contact) async { - await widget.onChatStarted(contact); + await widget.onStartChat(contact); } Future _onDeleteContact(proto.Contact contact) async { diff --git a/lib/contacts/views/contacts_dialog.dart b/lib/contacts/views/contacts_dialog.dart index ec85df3..721043e 100644 --- a/lib/contacts/views/contacts_dialog.dart +++ b/lib/contacts/views/contacts_dialog.dart @@ -135,7 +135,7 @@ class _ContactsDialogState extends State { ?.localConversationRecordKey .toVeilid(), onContactSelected: _onContactSelected, - onChatStarted: _onChatStarted, + onStartChat: _onChatStarted, ).paddingLTRB(8, 0, 8, 8)))), if (enableRight && enableLeft) Container( diff --git a/lib/settings/settings_page.dart b/lib/settings/settings_page.dart index f164992..2a05f08 100644 --- a/lib/settings/settings_page.dart +++ b/lib/settings/settings_page.dart @@ -31,34 +31,42 @@ class SettingsPageState extends State { @override Widget build(BuildContext context) => AsyncBlocBuilder( - builder: (context, state) => StyledScaffold( - appBar: DefaultAppBar( - title: Text(translate('settings_page.titlebar')), - leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () => GoRouterHelper(context).pop(), - ), - actions: [ - const SignalStrengthMeterWidget().paddingLTRB(16, 0, 16, 0), - ]), - body: ThemeSwitchingArea( - child: FormBuilder( - key: _formKey, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - buildSettingsPageColorPreferences( + builder: (context, state) => ThemeSwitcher.withTheme( + builder: (_, switcher, theme) => StyledScaffold( + appBar: DefaultAppBar( + title: Text(translate('settings_page.titlebar')), + leading: IconButton( + icon: const Icon(Icons.arrow_back), + onPressed: () => GoRouterHelper(context).pop(), + ), + actions: [ + const SignalStrengthMeterWidget() + .paddingLTRB(16, 0, 16, 0), + ]), + body: ThemeSwitchingArea( + child: FormBuilder( + key: _formKey, + child: ListView( + padding: const EdgeInsets.all(8), + children: [ + buildSettingsPageColorPreferences( + context: context, + switcher: switcher, + onChanged: () => setState(() {})) + .paddingLTRB(0, 8, 0, 0), + buildSettingsPageBrightnessPreferences( context: context, - onChanged: () => setState(() {})) - .paddingLTRB(0, 8, 0, 0), - buildSettingsPageBrightnessPreferences( - context: context, onChanged: () => setState(() {})), - buildSettingsPageWallpaperPreferences( - context: context, onChanged: () => setState(() {})), - buildSettingsPageNotificationPreferences( - context: context, onChanged: () => setState(() {})), - ].map((x) => x.paddingLTRB(0, 0, 0, 8)).toList(), - ), - ).paddingSymmetric(horizontal: 8, vertical: 8), - ))); + switcher: switcher, + onChanged: () => setState(() {})), + buildSettingsPageWallpaperPreferences( + context: context, + switcher: switcher, + onChanged: () => setState(() {})), + buildSettingsPageNotificationPreferences( + context: context, + onChanged: () => setState(() {})), + ].map((x) => x.paddingLTRB(0, 0, 0, 8)).toList(), + ), + ).paddingSymmetric(horizontal: 8, vertical: 8), + )))); } diff --git a/lib/theme/views/brightness_preferences.dart b/lib/theme/views/brightness_preferences.dart index 0c39976..7a1bb1d 100644 --- a/lib/theme/views/brightness_preferences.dart +++ b/lib/theme/views/brightness_preferences.dart @@ -22,24 +22,25 @@ List> _getBrightnessDropdownItems() { } Widget buildSettingsPageBrightnessPreferences( - {required BuildContext context, required void Function() onChanged}) { + {required BuildContext context, + required void Function() onChanged, + required ThemeSwitcherState switcher}) { final preferencesRepository = PreferencesRepository.instance; final themePreferences = preferencesRepository.value.themePreference; - return ThemeSwitcher.withTheme( - builder: (_, switcher, theme) => FormBuilderDropdown( - name: formFieldBrightness, - decoration: InputDecoration( - label: Text(translate('settings_page.brightness_mode'))), - items: _getBrightnessDropdownItems(), - initialValue: themePreferences.brightnessPreference, - onChanged: (value) async { - final newThemePrefs = themePreferences.copyWith( - brightnessPreference: value as BrightnessPreference); - final newPrefs = preferencesRepository.value - .copyWith(themePreference: newThemePrefs); + return FormBuilderDropdown( + name: formFieldBrightness, + decoration: InputDecoration( + label: Text(translate('settings_page.brightness_mode'))), + items: _getBrightnessDropdownItems(), + initialValue: themePreferences.brightnessPreference, + onChanged: (value) async { + final newThemePrefs = themePreferences.copyWith( + brightnessPreference: value as BrightnessPreference); + final newPrefs = preferencesRepository.value + .copyWith(themePreference: newThemePrefs); - await preferencesRepository.set(newPrefs); - switcher.changeTheme(theme: newThemePrefs.themeData()); - onChanged(); - })); + await preferencesRepository.set(newPrefs); + switcher.changeTheme(theme: newThemePrefs.themeData()); + onChanged(); + }); } diff --git a/lib/theme/views/color_preferences.dart b/lib/theme/views/color_preferences.dart index ce03c0a..a9a8841 100644 --- a/lib/theme/views/color_preferences.dart +++ b/lib/theme/views/color_preferences.dart @@ -1,4 +1,5 @@ import 'package:animated_theme_switcher/animated_theme_switcher.dart'; +import 'package:async_tools/async_tools.dart'; import 'package:flutter/material.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_translate/flutter_translate.dart'; @@ -7,6 +8,7 @@ import '../../settings/settings.dart'; import '../models/models.dart'; const String formFieldTheme = 'theme'; +const String _kSwitchTheme = 'switchTheme'; List> _getThemeDropdownItems() { const colorPrefs = ColorPreference.values; @@ -32,24 +34,27 @@ List> _getThemeDropdownItems() { } Widget buildSettingsPageColorPreferences( - {required BuildContext context, required void Function() onChanged}) { + {required BuildContext context, + required void Function() onChanged, + required ThemeSwitcherState switcher}) { final preferencesRepository = PreferencesRepository.instance; final themePreferences = preferencesRepository.value.themePreference; - return ThemeSwitcher.withTheme( - builder: (_, switcher, theme) => FormBuilderDropdown( - name: formFieldTheme, - decoration: InputDecoration( - label: Text(translate('settings_page.color_theme'))), - items: _getThemeDropdownItems(), - initialValue: themePreferences.colorPreference, - onChanged: (value) async { - final newThemePrefs = themePreferences.copyWith( - colorPreference: value as ColorPreference); - final newPrefs = preferencesRepository.value - .copyWith(themePreference: newThemePrefs); + return FormBuilderDropdown( + name: formFieldTheme, + decoration: + InputDecoration(label: Text(translate('settings_page.color_theme'))), + items: _getThemeDropdownItems(), + initialValue: themePreferences.colorPreference, + onChanged: (value) { + singleFuture(_kSwitchTheme, () async { + final newThemePrefs = themePreferences.copyWith( + colorPreference: value as ColorPreference); + final newPrefs = preferencesRepository.value + .copyWith(themePreference: newThemePrefs); - await preferencesRepository.set(newPrefs); - switcher.changeTheme(theme: newThemePrefs.themeData()); - onChanged(); - })); + await preferencesRepository.set(newPrefs); + switcher.changeTheme(theme: newThemePrefs.themeData()); + onChanged(); + }); + }); } diff --git a/lib/theme/views/wallpaper_preferences.dart b/lib/theme/views/wallpaper_preferences.dart index 1c2e9de..48f0a6a 100644 --- a/lib/theme/views/wallpaper_preferences.dart +++ b/lib/theme/views/wallpaper_preferences.dart @@ -9,24 +9,25 @@ import '../models/models.dart'; const String formFieldEnableWallpaper = 'enable_wallpaper'; Widget buildSettingsPageWallpaperPreferences( - {required BuildContext context, required void Function() onChanged}) { + {required BuildContext context, + required void Function() onChanged, + required ThemeSwitcherState switcher}) { final preferencesRepository = PreferencesRepository.instance; final themePreferences = preferencesRepository.value.themePreference; - return ThemeSwitcher.withTheme( - builder: (_, switcher, theme) => FormBuilderCheckbox( - name: formFieldEnableWallpaper, - title: Text(translate('settings_page.enable_wallpaper')), - initialValue: themePreferences.enableWallpaper, - onChanged: (value) async { - if (value != null) { - final newThemePrefs = - themePreferences.copyWith(enableWallpaper: value); - final newPrefs = preferencesRepository.value - .copyWith(themePreference: newThemePrefs); + return FormBuilderCheckbox( + name: formFieldEnableWallpaper, + title: Text(translate('settings_page.enable_wallpaper')), + initialValue: themePreferences.enableWallpaper, + onChanged: (value) async { + if (value != null) { + final newThemePrefs = + themePreferences.copyWith(enableWallpaper: value); + final newPrefs = preferencesRepository.value + .copyWith(themePreference: newThemePrefs); - await preferencesRepository.set(newPrefs); - switcher.changeTheme(theme: newThemePrefs.themeData()); - onChanged(); - } - })); + await preferencesRepository.set(newPrefs); + switcher.changeTheme(theme: newThemePrefs.themeData()); + onChanged(); + } + }); } diff --git a/pubspec.lock b/pubspec.lock index 349a58b..93fdce8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -92,10 +92,11 @@ packages: async_tools: dependency: "direct main" description: - path: "../dart_async_tools" - relative: true - source: path - version: "0.1.7" + name: async_tools + sha256: a258558160d6adc18612d0c635ce0d18ceabc022f7933ce78ca4806075d79578 + url: "https://pub.dev" + source: hosted + version: "0.1.8" auto_size_text: dependency: "direct main" description: @@ -156,10 +157,10 @@ packages: dependency: "direct main" description: name: bloc_advanced_tools - sha256: d8a680d8a0469456399fb26bae9f7a1d2a1420b5bdf75e204e0fadab9edb0811 + sha256: "977f3c7e3f9a19aec2f2c734ae99c8f0799c1b78f9fd7e4dce91a2dbf773e11b" url: "https://pub.dev" source: hosted - version: "0.1.8" + version: "0.1.9" blurry_modal_progress_hud: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5f924ba..8b4a0a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,13 +15,13 @@ dependencies: animated_theme_switcher: ^2.0.10 ansicolor: ^2.0.3 archive: ^4.0.4 - async_tools: ^0.1.7 + async_tools: ^0.1.8 auto_size_text: ^3.0.0 awesome_extensions: ^2.0.21 badges: ^3.1.2 basic_utils: ^5.8.2 bloc: ^8.1.4 - bloc_advanced_tools: ^0.1.8 + bloc_advanced_tools: ^0.1.9 blurry_modal_progress_hud: ^1.1.1 change_case: ^2.2.0 charcode: ^1.4.0 @@ -112,9 +112,9 @@ dependencies: xterm: ^4.0.0 zxing2: ^0.2.3 -dependency_overrides: - async_tools: - path: ../dart_async_tools +#dependency_overrides: +# async_tools: +# path: ../dart_async_tools # bloc_advanced_tools: # path: ../bloc_advanced_tools # searchable_listview: