diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index bd6e62c21..aec4ee17a 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -615,7 +615,7 @@ class ChatController extends State inputFocus.removeListener(_inputFocusListener); onFocusSub?.cancel(); //#Pangea - choreographer.stateListener.close(); + choreographer.stateStream.close(); choreographer.dispose(); clearSelectedEvents(); MatrixState.pAnyState.closeOverlay(); diff --git a/lib/pangea/chat/widgets/chat_floating_action_button.dart b/lib/pangea/chat/widgets/chat_floating_action_button.dart index 3131995b3..a024d5b97 100644 --- a/lib/pangea/chat/widgets/chat_floating_action_button.dart +++ b/lib/pangea/chat/widgets/chat_floating_action_button.dart @@ -48,8 +48,7 @@ class ChatFloatingActionButtonState extends State { } // Rebuild the widget each time there's an update from choreo (i.e., an error). - _choreoSub = - widget.controller.choreographer.stateListener.stream.listen((_) { + _choreoSub = widget.controller.choreographer.stateStream.stream.listen((_) { setState(() {}); }); diff --git a/lib/pangea/chat/widgets/chat_view_background.dart b/lib/pangea/chat/widgets/chat_view_background.dart index 1eadb40a8..ad9def96c 100644 --- a/lib/pangea/chat/widgets/chat_view_background.dart +++ b/lib/pangea/chat/widgets/chat_view_background.dart @@ -19,7 +19,7 @@ class ChatViewBackgroundState extends State { @override void initState() { // Rebuild the widget each time there's an update from choreo - _choreoSub = widget.choreographer.stateListener.stream.listen((_) { + _choreoSub = widget.choreographer.stateStream.stream.listen((_) { setState(() {}); }); super.initState(); diff --git a/lib/pangea/chat/widgets/input_bar_wrapper.dart b/lib/pangea/chat/widgets/input_bar_wrapper.dart index bcf9a26be..85835e630 100644 --- a/lib/pangea/chat/widgets/input_bar_wrapper.dart +++ b/lib/pangea/chat/widgets/input_bar_wrapper.dart @@ -25,8 +25,7 @@ class ChatInputRowWrapperState extends State { @override void initState() { // Rebuild the widget each time there's an update from choreo - _choreoSub = - widget.controller.choreographer.stateListener.stream.listen((_) { + _choreoSub = widget.controller.choreographer.stateStream.stream.listen((_) { setState(() {}); }); super.initState(); diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index bc62d1f93..d52961316 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -55,8 +55,10 @@ class Choreographer { // last checked by IGC or translation String? _lastChecked; ChoreoMode choreoMode = ChoreoMode.igc; - final StreamController stateListener = StreamController.broadcast(); - StreamSubscription? trialStream; + + final StreamController stateStream = StreamController.broadcast(); + StreamSubscription? _trialStream; + StreamSubscription? _languageStream; Choreographer(this.pangeaController, this.chatController) { _initialize(); @@ -74,9 +76,20 @@ class Choreographer { errorService = ErrorService(this); altTranslator = AlternativeTranslator(this); _textController.addListener(_onChangeListener); - trialStream = pangeaController + _trialStream = pangeaController .subscriptionController.trialActivationStream.stream .listen((_) => _onChangeListener); + _languageStream = + pangeaController.userController.stateStream.listen((update) { + if (update is Map && + update['prev_target_lang'] is LanguageModel) { + clear(); + } + + // refresh on any profile update, to account + // for changes like enabling autocorrect + setState(); + }); clear(); } @@ -560,7 +573,9 @@ class Choreographer { dispose() { _textController.dispose(); - trialStream?.cancel(); + _trialStream?.cancel(); + _languageStream?.cancel(); + stateStream.close(); tts.dispose(); } @@ -617,8 +632,8 @@ class Choreographer { bool get editTypeIsKeyboard => EditType.keyboard == _textController.editType; setState() { - if (!stateListener.isClosed) { - stateListener.add(0); + if (!stateStream.isClosed) { + stateStream.add(0); } } diff --git a/lib/pangea/choreographer/widgets/it_bar.dart b/lib/pangea/choreographer/widgets/it_bar.dart index 9eaba2beb..537d829f2 100644 --- a/lib/pangea/choreographer/widgets/it_bar.dart +++ b/lib/pangea/choreographer/widgets/it_bar.dart @@ -46,7 +46,7 @@ class ITBarState extends State with SingleTickerProviderStateMixin { super.initState(); // Rebuild the widget each time there's an update from choreo. - _choreoSub = widget.choreographer.stateListener.stream.listen((_) { + _choreoSub = widget.choreographer.stateStream.stream.listen((_) { if (itController.willOpen != wasOpen) { itController.willOpen ? _controller.forward() : _controller.reverse(); } diff --git a/lib/pangea/choreographer/widgets/send_button.dart b/lib/pangea/choreographer/widgets/send_button.dart index 7c3088255..69e6e65b2 100644 --- a/lib/pangea/choreographer/widgets/send_button.dart +++ b/lib/pangea/choreographer/widgets/send_button.dart @@ -26,8 +26,7 @@ class ChoreographerSendButtonState extends State { void initState() { // Rebuild the widget each time there's an update from // choreo. This keeps the spin up-to-date. - _choreoSub = - widget.controller.choreographer.stateListener.stream.listen((_) { + _choreoSub = widget.controller.choreographer.stateStream.stream.listen((_) { setState(() {}); }); super.initState(); diff --git a/lib/pangea/choreographer/widgets/start_igc_button.dart b/lib/pangea/choreographer/widgets/start_igc_button.dart index 8363e7278..94e31d0f8 100644 --- a/lib/pangea/choreographer/widgets/start_igc_button.dart +++ b/lib/pangea/choreographer/widgets/start_igc_button.dart @@ -35,7 +35,7 @@ class StartIGCButtonState extends State vsync: this, duration: const Duration(seconds: 2), ); - _choreoListener = widget.controller.choreographer.stateListener.stream + _choreoListener = widget.controller.choreographer.stateStream.stream .listen(_updateSpinnerState); super.initState(); } diff --git a/lib/pangea/user/controllers/user_controller.dart b/lib/pangea/user/controllers/user_controller.dart index 07b8d73cf..e354293e1 100644 --- a/lib/pangea/user/controllers/user_controller.dart +++ b/lib/pangea/user/controllers/user_controller.dart @@ -85,10 +85,11 @@ class UserController extends BaseController { final Profile updatedProfile = update(profile); await updatedProfile.saveProfileData(waitForDataInSync: waitForDataInSync); - - if (prevTargetLang != _pangeaController.languageController.userL2) { - setState({'prev_target_lang': prevTargetLang}); - } + setState( + prevTargetLang != _pangeaController.languageController.userL2 + ? {'prev_target_lang': prevTargetLang} + : null, + ); } /// A completer for the profile model of a user. diff --git a/lib/pangea/writing_assistance/writing_assistance_input_row.dart b/lib/pangea/writing_assistance/writing_assistance_input_row.dart index 40a14616e..0c8be567f 100644 --- a/lib/pangea/writing_assistance/writing_assistance_input_row.dart +++ b/lib/pangea/writing_assistance/writing_assistance_input_row.dart @@ -41,7 +41,7 @@ class WritingAssistanceInputRowState extends State { @override void initState() { // Rebuild the widget each time there's an update from choreo - _choreoSub = choreographer.stateListener.stream.listen((_) { + _choreoSub = choreographer.stateStream.stream.listen((_) { setSuggestions(); }); setSuggestions();