From 9e3111f97c68c347cc5aa67cf6df197e3a63bb0a Mon Sep 17 00:00:00 2001 From: ggurdin Date: Thu, 24 Oct 2024 14:16:39 -0400 Subject: [PATCH] don't play token text if null message audio is playing --- lib/pages/chat/events/audio_player.dart | 11 +++++++++-- lib/pangea/widgets/chat/message_audio_card.dart | 6 +++++- .../widgets/chat/message_selection_overlay.dart | 15 ++++++++++++--- lib/pangea/widgets/chat/message_toolbar.dart | 1 + pubspec.yaml | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 4a4f6fac9..c79fc9cb3 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -21,6 +21,7 @@ class AudioPlayerWidget extends StatefulWidget { final Event? event; final PangeaAudioFile? matrixFile; final bool autoplay; + final Function(bool)? setIsPlayingAudio; // Pangea# static String? currentId; @@ -41,6 +42,7 @@ class AudioPlayerWidget extends StatefulWidget { this.autoplay = false, this.sectionStartMS, this.sectionEndMS, + this.setIsPlayingAudio, // Pangea# super.key, }); @@ -204,8 +206,13 @@ class AudioPlayerState extends State { if (max == null || max == Duration.zero) return; setState(() => maxPosition = max.inMilliseconds.toDouble()); }); - onPlayerStateChanged ??= - audioPlayer.playingStream.listen((_) => setState(() {})); + onPlayerStateChanged ??= audioPlayer.playingStream.listen( + (isPlaying) => setState(() { + // #Pangea + widget.setIsPlayingAudio?.call(isPlaying); + // Pangea# + }), + ); final audioFile = this.audioFile; if (audioFile != null) { audioPlayer.setFilePath(audioFile.path); diff --git a/lib/pangea/widgets/chat/message_audio_card.dart b/lib/pangea/widgets/chat/message_audio_card.dart index e66e69477..47cb41af8 100644 --- a/lib/pangea/widgets/chat/message_audio_card.dart +++ b/lib/pangea/widgets/chat/message_audio_card.dart @@ -22,12 +22,14 @@ class MessageAudioCard extends StatefulWidget { final MessageOverlayController overlayController; final PangeaTokenText? selection; final TtsController tts; + final Function(bool) setIsPlayingAudio; const MessageAudioCard({ super.key, required this.messageEvent, required this.overlayController, required this.tts, + required this.setIsPlayingAudio, this.selection, }); @@ -56,7 +58,7 @@ class MessageAudioCardState extends State { @override void didUpdateWidget(covariant oldWidget) { - if (oldWidget.selection != widget.selection) { + if (oldWidget.selection != widget.selection && widget.selection != null) { debugPrint('selection changed'); setSectionStartAndEndFromSelection(); playSelectionAudio(); @@ -65,6 +67,7 @@ class MessageAudioCardState extends State { } Future playSelectionAudio() async { + if (widget.selection == null) return; final PangeaTokenText selection = widget.selection!; final tokenText = selection.content; @@ -203,6 +206,7 @@ class MessageAudioCardState extends State { sectionEndMS: sectionEndMS, color: Theme.of(context).colorScheme.onPrimaryContainer, + setIsPlayingAudio: widget.setIsPlayingAudio, ), widget.tts.missingVoiceButton, ], diff --git a/lib/pangea/widgets/chat/message_selection_overlay.dart b/lib/pangea/widgets/chat/message_selection_overlay.dart index dbce6f2b8..a8022b1cc 100644 --- a/lib/pangea/widgets/chat/message_selection_overlay.dart +++ b/lib/pangea/widgets/chat/message_selection_overlay.dart @@ -66,6 +66,7 @@ class MessageOverlayController extends State PangeaMessageEvent get pangeaMessageEvent => widget._pangeaMessageEvent; final TtsController tts = TtsController(); + bool isPlayingAudio = false; @override void initState() { @@ -200,9 +201,10 @@ class MessageOverlayController extends State PangeaToken token, ) { if ([ - MessageMode.practiceActivity, - // MessageMode.textToSpeech - ].contains(toolbarMode)) { + MessageMode.practiceActivity, + // MessageMode.textToSpeech + ].contains(toolbarMode) || + isPlayingAudio) { return; } @@ -273,6 +275,13 @@ class MessageOverlayController extends State double get reactionsHeight => hasReactions ? 28 : 0; double get belowMessageHeight => toolbarButtonsHeight + reactionsHeight; + void setIsPlayingAudio(bool isPlaying) { + if (mounted) { + setState(() => isPlayingAudio = isPlaying); + debugPrint("IS PLAYING AUDIO: $isPlaying"); + } + } + @override void didChangeDependencies() { super.didChangeDependencies(); diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 2f2f2b736..071a99f69 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -54,6 +54,7 @@ class MessageToolbar extends StatelessWidget { overlayController: overLayController, selection: overLayController.selectedSpan, tts: tts, + setIsPlayingAudio: overLayController.setIsPlayingAudio, ); case MessageMode.speechToText: return MessageSpeechToTextCard( diff --git a/pubspec.yaml b/pubspec.yaml index 377087387..80906d77c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ description: Learn a language while texting your friends. # Pangea# publish_to: none # On version bump also increase the build number for F-Droid -version: 1.22.5+3555 +version: 1.22.6+3556 environment: sdk: ">=3.0.0 <4.0.0"