From 7b91d14870bb9cd104c72b4e38b1d328cf984285 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:09:52 -0500 Subject: [PATCH 1/5] translation updates --- lib/pangea/constants/model_keys.dart | 2 ++ lib/pangea/repo/full_text_translation_repo.dart | 6 ++++++ lib/pangea/widgets/chat/message_text_selection.dart | 2 ++ lib/pangea/widgets/chat/message_translation_card.dart | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pangea/constants/model_keys.dart b/lib/pangea/constants/model_keys.dart index d027bce1d..6f0649dbb 100644 --- a/lib/pangea/constants/model_keys.dart +++ b/lib/pangea/constants/model_keys.dart @@ -51,6 +51,8 @@ class ModelKey { static const String word = "word"; static const String lang = "lang"; static const String deepL = "deepl"; + static const String offset = "offset"; + static const String length = "length"; static const String langCode = 'lang_code'; static const String wordLang = "word_lang"; static const String lemma = "lemma"; diff --git a/lib/pangea/repo/full_text_translation_repo.dart b/lib/pangea/repo/full_text_translation_repo.dart index a781b4b0d..704bb9d63 100644 --- a/lib/pangea/repo/full_text_translation_repo.dart +++ b/lib/pangea/repo/full_text_translation_repo.dart @@ -37,6 +37,8 @@ class FullTextTranslationRequestModel { String userL1; String userL2; bool? deepL; + int? offset; + int? length; FullTextTranslationRequestModel({ required this.text, @@ -45,6 +47,8 @@ class FullTextTranslationRequestModel { required this.userL2, required this.userL1, this.deepL = false, + this.offset, + this.length, }); //PTODO throw error for null @@ -56,6 +60,8 @@ class FullTextTranslationRequestModel { ModelKey.userL2: userL2, ModelKey.userL1: userL1, ModelKey.deepL: deepL, + ModelKey.offset: offset, + ModelKey.length: length, }; } diff --git a/lib/pangea/widgets/chat/message_text_selection.dart b/lib/pangea/widgets/chat/message_text_selection.dart index b41d62cbe..6263738f4 100644 --- a/lib/pangea/widgets/chat/message_text_selection.dart +++ b/lib/pangea/widgets/chat/message_text_selection.dart @@ -32,4 +32,6 @@ class MessageTextSelection { } selectionStream.add(selectedText); } + + int get offset => messageText.indexOf(selectedText!); } diff --git a/lib/pangea/widgets/chat/message_translation_card.dart b/lib/pangea/widgets/chat/message_translation_card.dart index c963dd251..ec24668e3 100644 --- a/lib/pangea/widgets/chat/message_translation_card.dart +++ b/lib/pangea/widgets/chat/message_translation_card.dart @@ -73,11 +73,13 @@ class MessageTranslationCardState extends State { final resp = await FullTextTranslationRepo.translate( accessToken: accessToken, request: FullTextTranslationRequestModel( - text: widget.selection.selectedText!, + text: widget.selection.messageText, tgtLang: translationLangCode()!, userL1: l1Code!, userL2: l2Code!, srcLang: widget.messageEvent.messageDisplayLangCode, + length: widget.selection.selectedText!.length, + offset: widget.selection.offset, ), ); From 40c7ef49c566e0e4882dc11790d5ff3b3a5368e4 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:35:23 -0500 Subject: [PATCH 2/5] update toolbar after highlight change --- lib/pangea/widgets/chat/message_toolbar.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 5b91181c1..aa8a1de7b 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -247,14 +247,16 @@ class MessageToolbarState extends State { updateMode(mode); }); + Timer? timer; + selectionStream = widget.textSelection.selectionStream.stream.listen((value) { - final bool shouldSetState = - value != null && !hasSelectedText || value == null && hasSelectedText; - hasSelectedText = value != null; - if (shouldSetState) { - setState(() {}); - } + timer?.cancel(); + timer = Timer(const Duration(milliseconds: 750), () { + if (currentMode != null || value != null && value.isNotEmpty) { + updateMode(currentMode ?? MessageMode.translation); + } + }); }); } From c24619beb1b76621031fd1685522ca094ab29d22 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:39:16 -0500 Subject: [PATCH 3/5] autoplay audio in toolbar --- lib/pages/chat/events/audio_player.dart | 19 ++++++++++++++++++- .../widgets/chat/message_audio_card.dart | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 8617303b0..0593c6122 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -15,12 +15,22 @@ import '../../../utils/matrix_sdk_extensions/event_extension.dart'; class AudioPlayerWidget extends StatefulWidget { final Color color; final Event event; + // #Pangea + final bool autoplay; + // Pangea# static String? currentId; static const int wavesCount = 40; - const AudioPlayerWidget(this.event, {this.color = Colors.black, super.key}); + const AudioPlayerWidget( + this.event, { + this.color = Colors.black, + super.key, + // #Pangea + this.autoplay = false, + // Pangea# + }); @override AudioPlayerState createState() => AudioPlayerState(); @@ -205,6 +215,13 @@ class AudioPlayerState extends State { void initState() { super.initState(); waveform = _getWaveform(); + // #Pangea + if (widget.autoplay) { + status == AudioPlayerStatus.downloaded + ? _playAction() + : _downloadAction(); + // Pangea# + } } @override diff --git a/lib/pangea/widgets/chat/message_audio_card.dart b/lib/pangea/widgets/chat/message_audio_card.dart index 05f8ffee2..aac21f66d 100644 --- a/lib/pangea/widgets/chat/message_audio_card.dart +++ b/lib/pangea/widgets/chat/message_audio_card.dart @@ -95,6 +95,7 @@ class MessageAudioCardState extends State { AudioPlayerWidget( localAudioEvent!, color: Theme.of(context).colorScheme.onPrimaryContainer, + autoplay: true, ), ], ), From 119789211c689a605f25ddc993f1b943449a2a97 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:46:50 -0500 Subject: [PATCH 4/5] switched to wordnet data --- lib/pangea/widgets/chat/message_toolbar.dart | 2 +- lib/pangea/widgets/igc/word_data_card.dart | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index aa8a1de7b..913c77e4a 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -222,7 +222,7 @@ class MessageToolbarState extends State { wordLang: widget.pangeaMessageEvent.messageDisplayLangCode, fullText: widget.textSelection.messageText, fullTextLang: widget.pangeaMessageEvent.messageDisplayLangCode, - hasInfo: false, + hasInfo: true, room: widget.room, ); } diff --git a/lib/pangea/widgets/igc/word_data_card.dart b/lib/pangea/widgets/igc/word_data_card.dart index 9cf3da98f..7f68db5ea 100644 --- a/lib/pangea/widgets/igc/word_data_card.dart +++ b/lib/pangea/widgets/igc/word_data_card.dart @@ -7,9 +7,7 @@ import 'package:fluffychat/pangea/models/language_model.dart'; import 'package:fluffychat/pangea/utils/bot_style.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/firebase_analytics.dart'; -import 'package:fluffychat/pangea/widgets/common/bot_face_svg.dart'; import 'package:fluffychat/pangea/widgets/common/p_circular_loader.dart'; -import 'package:fluffychat/pangea/widgets/igc/card_header.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -183,10 +181,6 @@ class WordDataCardView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ - CardHeader( - text: controller.widget.word, - botExpression: BotExpression.down, - ), if (controller.widget.choiceFeedback != null) Text( controller.widget.choiceFeedback!, From 2bf855028b9472edc35f27a6e3e5373f478e8567 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:51:29 -0500 Subject: [PATCH 5/5] card error widget --- .../widgets/chat/message_audio_card.dart | 6 ++---- .../chat/message_translation_card.dart | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/pangea/widgets/chat/message_audio_card.dart b/lib/pangea/widgets/chat/message_audio_card.dart index aac21f66d..a7caba153 100644 --- a/lib/pangea/widgets/chat/message_audio_card.dart +++ b/lib/pangea/widgets/chat/message_audio_card.dart @@ -2,6 +2,7 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/chat/events/audio_player.dart'; import 'package:fluffychat/pangea/models/pangea_message_event.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:fluffychat/pangea/widgets/igc/card_error_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; @@ -100,10 +101,7 @@ class MessageAudioCardState extends State { ], ), ) - : Padding( - padding: const EdgeInsets.only(left: 8), - child: playButton, - ), + : const CardErrorWidget(), ); } } diff --git a/lib/pangea/widgets/chat/message_translation_card.dart b/lib/pangea/widgets/chat/message_translation_card.dart index ec24668e3..50f6ff371 100644 --- a/lib/pangea/widgets/chat/message_translation_card.dart +++ b/lib/pangea/widgets/chat/message_translation_card.dart @@ -4,9 +4,9 @@ import 'package:fluffychat/pangea/repo/full_text_translation_repo.dart'; import 'package:fluffychat/pangea/utils/bot_style.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/widgets/chat/message_text_selection.dart'; +import 'package:fluffychat/pangea/widgets/igc/card_error_widget.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; class MessageTranslationCard extends StatefulWidget { final PangeaMessageEvent messageEvent; @@ -131,6 +131,12 @@ class MessageTranslationCardState extends State { @override Widget build(BuildContext context) { + if (!_fetchingRepresentation && + repEvent == null && + selectionTranslation == null) { + return const CardErrorWidget(); + } + return Padding( padding: const EdgeInsets.all(8), child: _fetchingRepresentation @@ -147,15 +153,10 @@ class MessageTranslationCardState extends State { selectionTranslation!, style: BotStyle.text(context), ) - : repEvent != null - ? Text( - repEvent!.text, - style: BotStyle.text(context), - ) - : Text( - L10n.of(context)!.oopsSomethingWentWrong, - style: BotStyle.text(context), - ), + : Text( + repEvent!.text, + style: BotStyle.text(context), + ), ); } }