commit
7a38608002
8 changed files with 54 additions and 29 deletions
|
|
@ -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<AudioPlayerWidget> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
waveform = _getWaveform();
|
||||
// #Pangea
|
||||
if (widget.autoplay) {
|
||||
status == AudioPlayerStatus.downloaded
|
||||
? _playAction()
|
||||
: _downloadAction();
|
||||
// Pangea#
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -95,14 +96,12 @@ class MessageAudioCardState extends State<MessageAudioCard> {
|
|||
AudioPlayerWidget(
|
||||
localAudioEvent!,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
autoplay: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(left: 8),
|
||||
child: playButton,
|
||||
),
|
||||
: const CardErrorWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,6 @@ class MessageTextSelection {
|
|||
}
|
||||
selectionStream.add(selectedText);
|
||||
}
|
||||
|
||||
int get offset => messageText.indexOf(selectedText!);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ class MessageToolbarState extends State<MessageToolbar> {
|
|||
wordLang: widget.pangeaMessageEvent.messageDisplayLangCode,
|
||||
fullText: widget.textSelection.messageText,
|
||||
fullTextLang: widget.pangeaMessageEvent.messageDisplayLangCode,
|
||||
hasInfo: false,
|
||||
hasInfo: true,
|
||||
room: widget.room,
|
||||
);
|
||||
}
|
||||
|
|
@ -247,14 +247,16 @@ class MessageToolbarState extends State<MessageToolbar> {
|
|||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -73,11 +73,13 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
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,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
@ -129,6 +131,12 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_fetchingRepresentation &&
|
||||
repEvent == null &&
|
||||
selectionTranslation == null) {
|
||||
return const CardErrorWidget();
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: _fetchingRepresentation
|
||||
|
|
@ -145,15 +153,10 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue