diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 8ba82fe36..99e2345bb 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -4828,6 +4828,8 @@ "ttsDisbledTitle": "Text-to-speech disabled", "ttsDisabledBody": "You can enable text-to-speech in your learning settings", "noSpaceDescriptionYet": "No space description created yet.", + "tooLargeToSend": "This message is too large to send", + "exitWithoutSaving": "Are you sure you want to leave without saving?", "enableAutocorrectPopupTitle": "Add your target language keyboard by going to:", "enableAutocorrectPopupSteps": " \u2022 Settings\n \u2022 General\n \u2022 Keyboard\n \u2022 Keyboards\n \u2022 Add New Keyboard", "enableAutocorrectPopupDescription": "Once the language is selected, you can click the small globe icon on the bottom left of your keyboard to activate the newly installed keyboard.", diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index f056c1069..2387f9788 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -291,6 +291,7 @@ class ClientChooserButton extends StatelessWidget { showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ); break; case SettingsAction.joinWithClassCode: diff --git a/lib/pangea/analytics_summary/learning_progress_indicators.dart b/lib/pangea/analytics_summary/learning_progress_indicators.dart index 728ce1a21..1d536c399 100644 --- a/lib/pangea/analytics_summary/learning_progress_indicators.dart +++ b/lib/pangea/analytics_summary/learning_progress_indicators.dart @@ -127,6 +127,7 @@ class LearningProgressIndicatorsState onTap: () => showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ), l2: userL2?.langCode.toUpperCase(), ), diff --git a/lib/pangea/choreographer/widgets/it_bar.dart b/lib/pangea/choreographer/widgets/it_bar.dart index e25627673..9eaba2beb 100644 --- a/lib/pangea/choreographer/widgets/it_bar.dart +++ b/lib/pangea/choreographer/widgets/it_bar.dart @@ -174,6 +174,7 @@ class ITBarState extends State with SingleTickerProviderStateMixin { onPressed: () => showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ), ), ), diff --git a/lib/pangea/choreographer/widgets/language_permissions_warning_buttons.dart b/lib/pangea/choreographer/widgets/language_permissions_warning_buttons.dart index cdbad2fb8..789f34685 100644 --- a/lib/pangea/choreographer/widgets/language_permissions_warning_buttons.dart +++ b/lib/pangea/choreographer/widgets/language_permissions_warning_buttons.dart @@ -54,6 +54,7 @@ class LanguagePermissionsButtons extends StatelessWidget { showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ); }, ), diff --git a/lib/pangea/choreographer/widgets/start_igc_button.dart b/lib/pangea/choreographer/widgets/start_igc_button.dart index b29753276..8363e7278 100644 --- a/lib/pangea/choreographer/widgets/start_igc_button.dart +++ b/lib/pangea/choreographer/widgets/start_igc_button.dart @@ -85,6 +85,7 @@ class StartIGCButtonState extends State showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ); return; case AssistanceState.notFetched: @@ -112,6 +113,7 @@ class StartIGCButtonState extends State onLongPress: () => showDialog( context: context, builder: (c) => const SettingsLearning(), + barrierDismissible: false, ), child: Stack( alignment: Alignment.center, diff --git a/lib/pangea/learning_settings/pages/settings_learning.dart b/lib/pangea/learning_settings/pages/settings_learning.dart index 3c26fd9e7..6e3624202 100644 --- a/lib/pangea/learning_settings/pages/settings_learning.dart +++ b/lib/pangea/learning_settings/pages/settings_learning.dart @@ -11,6 +11,7 @@ import 'package:fluffychat/pangea/learning_settings/utils/language_list_util.dar import 'package:fluffychat/pangea/spaces/models/space_model.dart'; import 'package:fluffychat/pangea/toolbar/controllers/tts_controller.dart'; import 'package:fluffychat/pangea/user/models/user_model.dart'; +import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -42,6 +43,47 @@ class SettingsLearningController extends State { super.dispose(); } + // compare settings in _profile with the settings in the userController + // if they are different, return true, else return false + bool get haveSettingsBeenChanged { + for (final setting in _profile.userSettings.toJson().entries) { + if (setting.value != + pangeaController.userController.profile.userSettings + .toJson()[setting.key]) { + return true; + } + } + for (final setting in _profile.toolSettings.toJson().entries) { + if (setting.value != + pangeaController.userController.profile.toolSettings + .toJson()[setting.key]) { + return true; + } + } + return false; + } + + // if the settings have been changed, show a dialog the user wants to exit without saving + // if the settings have not been changed, just close the settings page + void onSettingsClose() { + if (haveSettingsBeenChanged) { + showOkCancelAlertDialog( + title: L10n.of(context).exitWithoutSaving, + okLabel: L10n.of(context).submit, + cancelLabel: L10n.of(context).leave, + context: context, + ).then((value) { + if (value == OkCancelResult.ok) { + submit(); + } else { + Navigator.of(context).pop(); + } + }); + } else { + Navigator.of(context).pop(); + } + } + Future submit() async { if (selectedSourceLanguage?.langCodeShort == selectedTargetLanguage?.langCodeShort) { @@ -55,11 +97,11 @@ class SettingsLearningController extends State { languageMatchError = null; // Clear error if languages don't match }); - if (formKey.currentState!.validate()) { - if (!isTTSSupported) { - updateToolSetting(ToolSetting.enableTTS, false); - } + if (!isTTSSupported) { + updateToolSetting(ToolSetting.enableTTS, false); + } + if (formKey.currentState!.validate()) { await showFutureLoadingDialog( context: context, future: () async => pangeaController.userController.updateProfile( diff --git a/lib/pangea/learning_settings/pages/settings_learning_view.dart b/lib/pangea/learning_settings/pages/settings_learning_view.dart index 73fb7c3b9..970a910c2 100644 --- a/lib/pangea/learning_settings/pages/settings_learning_view.dart +++ b/lib/pangea/learning_settings/pages/settings_learning_view.dart @@ -113,7 +113,7 @@ class SettingsLearningView extends StatelessWidget { ), leading: IconButton( icon: const Icon(Icons.close), - onPressed: Navigator.of(context).pop, + onPressed: controller.onSettingsClose, ), ), body: ListTileTheme(