chore(settings_learning): check with user if they want to save unsave… (#1997)
* chore(settings_learning): check with user if they want to save unsaved changes * generated * chore: don't allow user to dismiss setting learning dialog by clicking background --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> Co-authored-by: ggurdin <ggurdin@gmail.com>
This commit is contained in:
parent
bf29c94ace
commit
cf1a420415
8 changed files with 55 additions and 5 deletions
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -291,6 +291,7 @@ class ClientChooserButton extends StatelessWidget {
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
break;
|
||||
case SettingsAction.joinWithClassCode:
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ class LearningProgressIndicatorsState
|
|||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
),
|
||||
l2: userL2?.langCode.toUpperCase(),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ class ITBarState extends State<ITBar> with SingleTickerProviderStateMixin {
|
|||
onPressed: () => showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class LanguagePermissionsButtons extends StatelessWidget {
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ class StartIGCButtonState extends State<StartIGCButton>
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
return;
|
||||
case AssistanceState.notFetched:
|
||||
|
|
@ -112,6 +113,7 @@ class StartIGCButtonState extends State<StartIGCButton>
|
|||
onLongPress: () => showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
|
|
|
|||
|
|
@ -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<SettingsLearning> {
|
|||
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<void> submit() async {
|
||||
if (selectedSourceLanguage?.langCodeShort ==
|
||||
selectedTargetLanguage?.langCodeShort) {
|
||||
|
|
@ -55,11 +97,11 @@ class SettingsLearningController extends State<SettingsLearning> {
|
|||
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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue