show overlay and play maudio with one click

This commit is contained in:
ggurdin 2025-06-10 14:37:59 -04:00
parent 4a7e9dade9
commit f7d8a09845
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
7 changed files with 29 additions and 29 deletions

View file

@ -22,7 +22,7 @@ import 'package:fluffychat/utils/file_description.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import '../../../widgets/fluffy_chat_app.dart';
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import '../../../widgets/matrix.dart';
class AudioPlayerWidget extends StatefulWidget {
@ -36,9 +36,10 @@ class AudioPlayerWidget extends StatefulWidget {
final String roomId;
final String senderId;
final PangeaAudioFile? matrixFile;
final Function(bool)? setIsPlayingAudio;
final ChatController chatController;
final MessageOverlayController? overlayController;
final VoidCallback? onPlay;
final bool autoplay;
// Pangea#
static const int wavesCount = 40;
@ -53,9 +54,10 @@ class AudioPlayerWidget extends StatefulWidget {
required this.roomId,
required this.senderId,
this.matrixFile,
this.setIsPlayingAudio,
required this.chatController,
this.overlayController,
this.onPlay,
this.autoplay = false,
// Pangea#
super.key,
});
@ -76,9 +78,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
String? _durationString;
// #Pangea
StreamSubscription? _onShowToolbar;
StreamSubscription? _onAudioPositionChanged;
StreamSubscription? _onPlayerStateChanged;
// Pangea#
@override
@ -163,9 +163,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
audioPlayer.dispose();
matrix.voiceMessageEventId.value = matrix.audioPlayer = null;
// #Pangea
_onShowToolbar?.cancel();
_onAudioPositionChanged?.cancel();
_onPlayerStateChanged?.cancel();
// Pangea#
}
}
@ -253,6 +251,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
// #Pangea
// if (matrix.voiceMessageEventId.value != widget.event.eventId) return;
if (matrix.voiceMessageEventId.value != widget.eventId) return;
matrix.audioPlayer?.dispose();
// Pangea#
final audioPlayer = matrix.audioPlayer = AudioPlayer();
@ -269,13 +269,6 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
);
}
});
_onPlayerStateChanged?.cancel();
_onPlayerStateChanged = audioPlayer.playingStream.listen(
(isPlaying) => setState(() {
widget.setIsPlayingAudio?.call(isPlaying);
}),
);
// Pangea#
// #Pangea
@ -394,6 +387,10 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
final duration = Duration(milliseconds: durationInt);
_durationString = duration.minuteSecondString;
}
// #Pangea
if (widget.autoplay) _onButtonTap();
// Pangea#
}
@override
@ -465,7 +462,11 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
onLongPress: () =>
widget.event?.saveFile(context),
// Pangea#
onTap: _onButtonTap,
onTap: () {
widget.onPlay != null
? widget.onPlay!.call()
: _onButtonTap();
},
child: Material(
color: widget.color.withAlpha(64),
borderRadius: BorderRadius.circular(64),

View file

@ -225,6 +225,15 @@ class MessageContent extends StatelessWidget {
eventId: event.eventId,
roomId: event.room.id,
senderId: event.senderId,
onPlay: overlayController == null
? () {
controller.showToolbar(
pangeaMessageEvent!.event,
pangeaMessageEvent: pangeaMessageEvent,
);
}
: null,
autoplay: overlayController != null,
// Pangea#
);
}

View file

@ -74,7 +74,6 @@ class MatchActivityCard extends StatelessWidget {
MessageAudioCard(
messageEvent: overlayController.pangeaMessageEvent!,
overlayController: overlayController,
setIsPlayingAudio: overlayController.setIsPlayingAudio,
),
Wrap(
alignment: WrapAlignment.center,

View file

@ -18,14 +18,12 @@ import 'package:fluffychat/pangea/toolbar/widgets/message_selection_overlay.dart
class MessageAudioCard extends StatefulWidget {
final PangeaMessageEvent messageEvent;
final MessageOverlayController overlayController;
final Function(bool) setIsPlayingAudio;
final VoidCallback? onError;
const MessageAudioCard({
super.key,
required this.messageEvent,
required this.overlayController,
required this.setIsPlayingAudio,
this.onError,
});
@ -91,7 +89,6 @@ class MessageAudioCardState extends State<MessageAudioCard> {
senderId: widget.messageEvent.senderId,
matrixFile: audioFile,
color: Theme.of(context).colorScheme.onPrimaryContainer,
setIsPlayingAudio: widget.setIsPlayingAudio,
fontSize: AppConfig.messageFontSize * AppConfig.fontSizeFactor,
chatController: widget.overlayController.widget.chatController,
overlayController: widget.overlayController,

View file

@ -86,7 +86,6 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
List<PangeaTokenText>? _highlightedTokens;
bool initialized = false;
bool isPlayingAudio = false;
final GlobalKey<ReadingAssistanceContentState> wordZoomKey = GlobalKey();
@ -575,12 +574,6 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
);
}
void setIsPlayingAudio(bool isPlaying) {
if (mounted) {
setState(() => isPlayingAudio = isPlaying);
}
}
void setShowTranslation(bool show, String? translation) {
if (showTranslation == show) return;
if (show && translation == null) return;

View file

@ -138,6 +138,9 @@ class MessageSelectionPositionerState extends State<MessageSelectionPositioner>
void dispose() {
_animationController.dispose();
_reactionSubscription?.cancel();
MatrixState.pangeaController.matrixState.audioPlayer
?..stop()
..dispose();
super.dispose();
}

View file

@ -236,7 +236,6 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
messageEvent:
widget.practiceCardController.widget.pangeaMessageEvent,
overlayController: widget.overlayController,
setIsPlayingAudio: widget.overlayController.setIsPlayingAudio,
onError: widget.onError,
),
ChoicesArray(
@ -247,8 +246,7 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
choices: choices(context),
isActive: true,
id: currentRecordModel?.hashCode.toString(),
enableAudio: !widget.overlayController.isPlayingAudio &&
practiceActivity.activityType.includeTTSOnClick,
enableAudio: practiceActivity.activityType.includeTTSOnClick,
langCode:
MatrixState.pangeaController.languageController.activeL2Code(),
getDisplayCopy: _getDisplayCopy,