From 5c7a1f554b113df86c6b9b1b09e2eb89a2c04f87 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Tue, 20 Aug 2024 14:48:44 -0400 Subject: [PATCH] added tooltip toggle status to matrix profile to prevent showing again after it's been dismissed --- lib/pangea/enum/instructions_enum.dart | 13 ++++++++++ lib/pangea/models/user_model.dart | 34 ++++++++++++++++++++++++++ lib/pangea/utils/instructions.dart | 21 +++++++++++++--- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/pangea/enum/instructions_enum.dart b/lib/pangea/enum/instructions_enum.dart index 007f60f37..48544925e 100644 --- a/lib/pangea/enum/instructions_enum.dart +++ b/lib/pangea/enum/instructions_enum.dart @@ -72,4 +72,17 @@ extension InlineInstructionsExtension on InlineInstructions { return L10n.of(context)!.translationChoicesBody; } } + + bool get toggledOff { + final instructionSettings = + MatrixState.pangeaController.userController.profile.instructionSettings; + switch (this) { + case InlineInstructions.speechToText: + return instructionSettings.showedSpeechToTextTooltip; + case InlineInstructions.l1Translation: + return instructionSettings.showedL1TranslationTooltip; + case InlineInstructions.translationChoices: + return instructionSettings.showedTranslationChoicesTooltip; + } + } } diff --git a/lib/pangea/models/user_model.dart b/lib/pangea/models/user_model.dart index 180422576..24db180dc 100644 --- a/lib/pangea/models/user_model.dart +++ b/lib/pangea/models/user_model.dart @@ -186,11 +186,18 @@ class UserInstructions { bool showedBlurMeansTranslate; bool showedTooltipInstructions; + bool showedSpeechToTextTooltip; + bool showedL1TranslationTooltip; + bool showedTranslationChoicesTooltip; + UserInstructions({ this.showedItInstructions = false, this.showedClickMessage = false, this.showedBlurMeansTranslate = false, this.showedTooltipInstructions = false, + this.showedSpeechToTextTooltip = false, + this.showedL1TranslationTooltip = false, + this.showedTranslationChoicesTooltip = false, }); factory UserInstructions.fromJson(Map json) => @@ -203,6 +210,12 @@ class UserInstructions { json[InstructionsEnum.blurMeansTranslate.toString()] ?? false, showedTooltipInstructions: json[InstructionsEnum.tooltipInstructions.toString()] ?? false, + showedL1TranslationTooltip: + json[InlineInstructions.l1Translation.toString()] ?? false, + showedTranslationChoicesTooltip: + json[InlineInstructions.translationChoices.toString()] ?? false, + showedSpeechToTextTooltip: + json[InlineInstructions.speechToText.toString()] ?? false, ); Map toJson() { @@ -213,6 +226,12 @@ class UserInstructions { showedBlurMeansTranslate; data[InstructionsEnum.tooltipInstructions.toString()] = showedTooltipInstructions; + data[InlineInstructions.l1Translation.toString()] = + showedL1TranslationTooltip; + data[InlineInstructions.translationChoices.toString()] = + showedTranslationChoicesTooltip; + data[InlineInstructions.speechToText.toString()] = + showedSpeechToTextTooltip; return data; } @@ -238,6 +257,21 @@ class UserInstructions { ?.content[InstructionsEnum.tooltipInstructions.toString()] as bool?) ?? false, + showedL1TranslationTooltip: + (accountData[InlineInstructions.l1Translation.toString()] + ?.content[InlineInstructions.l1Translation.toString()] + as bool?) ?? + false, + showedTranslationChoicesTooltip: (accountData[ + InlineInstructions.translationChoices.toString()] + ?.content[InlineInstructions.translationChoices.toString()] + as bool?) ?? + false, + showedSpeechToTextTooltip: + (accountData[InlineInstructions.speechToText.toString()] + ?.content[InlineInstructions.speechToText.toString()] + as bool?) ?? + false, ); } } diff --git a/lib/pangea/utils/instructions.dart b/lib/pangea/utils/instructions.dart index 165bfa460..78dab6f6c 100644 --- a/lib/pangea/utils/instructions.dart +++ b/lib/pangea/utils/instructions.dart @@ -25,9 +25,15 @@ class InstructionsController { final Map _instructionsShown = {}; /// Returns true if the user requested this popup not be shown again - bool? toggledOff(String key) => InstructionsEnum.values - .firstWhereOrNull((value) => value.toString() == key) - ?.toggledOff; + bool? toggledOff(String key) { + final bool? instruction = InstructionsEnum.values + .firstWhereOrNull((value) => value.toString() == key) + ?.toggledOff; + final bool? tooltip = InlineInstructions.values + .firstWhereOrNull((value) => value.toString() == key) + ?.toggledOff; + return instruction ?? tooltip; + } InstructionsController(PangeaController pangeaController) { _pangeaController = pangeaController; @@ -58,6 +64,15 @@ class InstructionsController { if (key == InstructionsEnum.tooltipInstructions.toString()) { profile.instructionSettings.showedTooltipInstructions = value; } + if (key == InlineInstructions.speechToText.toString()) { + profile.instructionSettings.showedSpeechToTextTooltip = value; + } + if (key == InlineInstructions.l1Translation.toString()) { + profile.instructionSettings.showedL1TranslationTooltip = value; + } + if (key == InlineInstructions.translationChoices.toString()) { + profile.instructionSettings.showedTranslationChoicesTooltip = value; + } return profile; }); }