diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index ebfd384bc..db5041623 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -486,10 +486,11 @@ class ChatController extends State void setReadMarker({String? eventId}) { // #Pangea - if (eventId != null && - (eventId.contains("web") || - eventId.contains("android") || - eventId.contains("ios"))) { + if (room.client.userID == null || + eventId != null && + (eventId.contains("web") || + eventId.contains("android") || + eventId.contains("ios"))) { return; } // Pangea# diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index a5e60687d..ba8e35ae2 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -186,7 +186,11 @@ class Message extends StatelessWidget { if (animateIn && resetAnimateIn != null) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { animateIn = false; - setState(resetAnimateIn); + // #Pangea + if (context.mounted) { + // Pangea# + setState(resetAnimateIn); + } }); } return AnimatedSize( diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 34fda564b..0ac5ff0a8 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -214,62 +214,71 @@ class ClientChooserButton extends StatelessWidget { var clientCount = 0; matrix.accountBundles.forEach((key, value) => clientCount += value.length); - return FutureBuilder( - future: matrix.client.fetchOwnProfile(), - builder: (context, snapshot) => Stack( - alignment: Alignment.center, - children: [ - // #Pangea - // ...List.generate( - // clientCount, - // (index) => KeyBoardShortcuts( - // keysToPress: _buildKeyboardShortcut(index + 1), - // helpLabel: L10n.of(context)!.switchToAccount(index + 1), - // onKeysPressed: () => _handleKeyboardShortcut( - // matrix, - // index, - // context, - // ), - // child: const SizedBox.shrink(), - // ), - // ), - // KeyBoardShortcuts( - // keysToPress: { - // LogicalKeyboardKey.controlLeft, - // LogicalKeyboardKey.tab, - // }, - // helpLabel: L10n.of(context)!.nextAccount, - // onKeysPressed: () => _nextAccount(matrix, context), - // child: const SizedBox.shrink(), - // ), - // KeyBoardShortcuts( - // keysToPress: { - // LogicalKeyboardKey.controlLeft, - // LogicalKeyboardKey.shiftLeft, - // LogicalKeyboardKey.tab, - // }, - // helpLabel: L10n.of(context)!.previousAccount, - // onKeysPressed: () => _previousAccount(matrix, context), - // child: const SizedBox.shrink(), - // ), - // Pangea# - PopupMenuButton( - onSelected: (o) => _clientSelected(o, context), - itemBuilder: _bundleMenuItems, - child: Material( - color: Colors.transparent, - borderRadius: BorderRadius.circular(99), - child: Avatar( - mxContent: snapshot.data?.avatarUrl, - name: snapshot.data?.displayName ?? - matrix.client.userID!.localpart, - size: 32, - ), + // #Pangea + return matrix.client.userID == null + ? const SizedBox( + height: 16, + width: 16, + child: CircularProgressIndicator.adaptive(), + ) + : + // Pangea# + FutureBuilder( + future: matrix.client.fetchOwnProfile(), + builder: (context, snapshot) => Stack( + alignment: Alignment.center, + children: [ + // #Pangea + // ...List.generate( + // clientCount, + // (index) => KeyBoardShortcuts( + // keysToPress: _buildKeyboardShortcut(index + 1), + // helpLabel: L10n.of(context)!.switchToAccount(index + 1), + // onKeysPressed: () => _handleKeyboardShortcut( + // matrix, + // index, + // context, + // ), + // child: const SizedBox.shrink(), + // ), + // ), + // KeyBoardShortcuts( + // keysToPress: { + // LogicalKeyboardKey.controlLeft, + // LogicalKeyboardKey.tab, + // }, + // helpLabel: L10n.of(context)!.nextAccount, + // onKeysPressed: () => _nextAccount(matrix, context), + // child: const SizedBox.shrink(), + // ), + // KeyBoardShortcuts( + // keysToPress: { + // LogicalKeyboardKey.controlLeft, + // LogicalKeyboardKey.shiftLeft, + // LogicalKeyboardKey.tab, + // }, + // helpLabel: L10n.of(context)!.previousAccount, + // onKeysPressed: () => _previousAccount(matrix, context), + // child: const SizedBox.shrink(), + // ), + // Pangea# + PopupMenuButton( + onSelected: (o) => _clientSelected(o, context), + itemBuilder: _bundleMenuItems, + child: Material( + color: Colors.transparent, + borderRadius: BorderRadius.circular(99), + child: Avatar( + mxContent: snapshot.data?.avatarUrl, + name: snapshot.data?.displayName ?? + matrix.client.userID!.localpart, + size: 32, + ), + ), + ), + ], ), - ), - ], - ), - ); + ); } Set? _buildKeyboardShortcut(int index) { diff --git a/lib/pangea/enum/instructions_enum.dart b/lib/pangea/enum/instructions_enum.dart index e1a403526..a42a01643 100644 --- a/lib/pangea/enum/instructions_enum.dart +++ b/lib/pangea/enum/instructions_enum.dart @@ -4,7 +4,6 @@ import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; enum InstructionsEnum { @@ -19,24 +18,16 @@ enum InstructionsEnum { } extension InstructionsEnumExtension on InstructionsEnum { - String title(BuildContext context) { - if (!context.mounted) { - ErrorHandler.logError( - e: Exception("Context not mounted"), - m: 'InstructionsEnumExtension.title for $this', - ); - debugger(when: kDebugMode); - return ''; - } + String title(L10n l10n) { switch (this) { case InstructionsEnum.itInstructions: - return L10n.of(context)!.itInstructionsTitle; + return l10n.itInstructionsTitle; case InstructionsEnum.clickMessage: - return L10n.of(context)!.clickMessageTitle; + return l10n.clickMessageTitle; case InstructionsEnum.blurMeansTranslate: - return L10n.of(context)!.blurMeansTranslateTitle; + return l10n.blurMeansTranslateTitle; case InstructionsEnum.tooltipInstructions: - return L10n.of(context)!.tooltipInstructionsTitle; + return l10n.tooltipInstructionsTitle; case InstructionsEnum.clickAgainToDeselect: case InstructionsEnum.speechToText: case InstructionsEnum.l1Translation: @@ -53,46 +44,30 @@ extension InstructionsEnumExtension on InstructionsEnum { } } - String body(BuildContext context) { - if (!context.mounted) { - ErrorHandler.logError( - e: Exception("Context not mounted"), - m: 'InstructionsEnumExtension.body for $this', - ); - debugger(when: kDebugMode); - return ""; - } + String body(L10n l10n) { switch (this) { case InstructionsEnum.itInstructions: - return L10n.of(context)!.itInstructionsBody; + return l10n.itInstructionsBody; case InstructionsEnum.clickMessage: - return L10n.of(context)!.clickMessageBody; + return l10n.clickMessageBody; case InstructionsEnum.blurMeansTranslate: - return L10n.of(context)!.blurMeansTranslateBody; + return l10n.blurMeansTranslateBody; case InstructionsEnum.speechToText: - return L10n.of(context)!.speechToTextBody; + return l10n.speechToTextBody; case InstructionsEnum.l1Translation: - return L10n.of(context)!.l1TranslationBody; + return l10n.l1TranslationBody; case InstructionsEnum.translationChoices: - return L10n.of(context)!.translationChoicesBody; + return l10n.translationChoicesBody; case InstructionsEnum.clickAgainToDeselect: - return L10n.of(context)!.clickTheWordAgainToDeselect; + return l10n.clickTheWordAgainToDeselect; case InstructionsEnum.tooltipInstructions: return PlatformInfos.isMobile - ? L10n.of(context)!.tooltipInstructionsMobileBody - : L10n.of(context)!.tooltipInstructionsBrowserBody; + ? l10n.tooltipInstructionsMobileBody + : l10n.tooltipInstructionsBrowserBody; } } - bool toggledOff(BuildContext context) { - if (!context.mounted) { - ErrorHandler.logError( - e: Exception("Context not mounted"), - m: 'InstructionsEnumExtension.toggledOff for $this', - ); - debugger(when: kDebugMode); - return false; - } + bool toggledOff() { final instructionSettings = MatrixState.pangeaController.userController.profile.instructionSettings; switch (this) { diff --git a/lib/pangea/utils/inline_tooltip.dart b/lib/pangea/utils/inline_tooltip.dart index 26ec05426..4c81e1bbd 100644 --- a/lib/pangea/utils/inline_tooltip.dart +++ b/lib/pangea/utils/inline_tooltip.dart @@ -2,6 +2,7 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; class InlineTooltip extends StatelessWidget { final InstructionsEnum instructionsEnum; @@ -15,7 +16,7 @@ class InlineTooltip extends StatelessWidget { @override Widget build(BuildContext context) { - if (instructionsEnum.toggledOff(context)) { + if (instructionsEnum.toggledOff()) { return const SizedBox(); } @@ -42,7 +43,7 @@ class InlineTooltip extends StatelessWidget { // Text in the middle Center( child: Text( - instructionsEnum.body(context), + instructionsEnum.body(L10n.of(context)!), style: TextStyle( color: Theme.of(context).colorScheme.onSurface, height: 1.5, diff --git a/lib/pangea/utils/instructions.dart b/lib/pangea/utils/instructions.dart index 31b552384..681c0de08 100644 --- a/lib/pangea/utils/instructions.dart +++ b/lib/pangea/utils/instructions.dart @@ -80,7 +80,7 @@ class InstructionsController { } _instructionsShown[key.toString()] = true; - if (key.toggledOff(context)) { + if (key.toggledOff()) { return; } if (L10n.of(context) == null) { @@ -94,33 +94,36 @@ class InstructionsController { final botStyle = BotStyle.text(context); Future.delayed( const Duration(seconds: 1), - () => OverlayUtil.showPositionedCard( - context: context, - backDropToDismiss: false, - cardToShow: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - CardHeader( - text: key.title(context), - botExpression: BotExpression.idle, - onClose: () => {_instructionsClosed[key.toString()] = true}, - ), - const SizedBox(height: 10.0), - Padding( - padding: const EdgeInsets.all(6.0), - child: Text( - key.body(context), - style: botStyle, + () { + if (!context.mounted) return; + OverlayUtil.showPositionedCard( + context: context, + backDropToDismiss: false, + cardToShow: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + CardHeader( + text: key.title(L10n.of(context)!), + botExpression: BotExpression.idle, + onClose: () => {_instructionsClosed[key.toString()] = true}, ), - ), - if (showToggle) InstructionsToggle(instructionsKey: key), - ], - ), - maxHeight: 300, - maxWidth: 300, - transformTargetId: transformTargetKey, - closePrevOverlay: false, - ), + const SizedBox(height: 10.0), + Padding( + padding: const EdgeInsets.all(6.0), + child: Text( + key.body(L10n.of(context)!), + style: botStyle, + ), + ), + if (showToggle) InstructionsToggle(instructionsKey: key), + ], + ), + maxHeight: 300, + maxWidth: 300, + transformTargetId: transformTargetKey, + closePrevOverlay: false, + ); + }, ); } } @@ -152,7 +155,7 @@ class InstructionsToggleState extends State { return SwitchListTile.adaptive( activeColor: AppConfig.activeToggleColor, title: Text(L10n.of(context)!.doNotShowAgain), - value: widget.instructionsKey.toggledOff(context), + value: widget.instructionsKey.toggledOff(), onChanged: ((value) async { pangeaController.instructions.setToggledOff( widget.instructionsKey,