From abbcd41064d98dda9c4b32f4c41d253887f2ec5f Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Thu, 22 Feb 2024 11:25:27 -0500 Subject: [PATCH] toolbar updates --- assets/l10n/intl_en.arb | 7 ++- assets/l10n/intl_es.arb | 60 ++++++++++++++++++- lib/pangea/widgets/chat/message_toolbar.dart | 50 +++++++++------- .../chat/message_unsubscribed_card.dart | 47 +++++++++++++++ lib/pangea/widgets/igc/word_data_card.dart | 17 ++++++ 5 files changed, 158 insertions(+), 23 deletions(-) create mode 100644 lib/pangea/widgets/chat/message_unsubscribed_card.dart diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 6fd305baf..533af850b 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3932,5 +3932,10 @@ "subscriptionPopupDesc": "Subscribe today to unlock translation and grammar correction!", "seeOptions": "See options", "continuedWithoutSubscription": "Continue without subscribing", - "trialPeriodExpired": "Your trial period has expired" + "trialPeriodExpired": "Your trial period has expired", + "selectToDefine": "To define a word in this message, just select it!", + "translation": "translation", + "audio": "message audio", + "definitions": "definitions", + "subscribedToUnlockTools": "Subscribe to unlock language tools, including" } \ No newline at end of file diff --git a/assets/l10n/intl_es.arb b/assets/l10n/intl_es.arb index 71daf4635..f2452d581 100644 --- a/assets/l10n/intl_es.arb +++ b/assets/l10n/intl_es.arb @@ -4543,5 +4543,61 @@ "conversationTopic": "Tema de conversación", "enableModeration": "Activar la moderación", "enableModerationDesc": "Activar la moderación automática para revisar los mensajes antes de enviarlos", - "conversationLanguageLevel": "¿Cuál es el nivel lingüístico de esta conversación?" -} \ No newline at end of file + "conversationLanguageLevel": "¿Cuál es el nivel lingüístico de esta conversación?", + "errorGettingAudio": "Error al recibir audio. Por favor, actualice e inténtelo de nuevo.", + "define": "Defina", + "listen": "Listas", + "showDefinition": "Mostrar definición", + "acceptedKeyVerification": "{sender} verificación de clave aceptada", + "@acceptedKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "canceledKeyVerification": "{sender} canceló la verificación de claves", + "@canceledKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "completedKeyVerification": "{sender} verificación de claves completada", + "@canceledKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "isReadyForKeyVerification": "{sender} está listo para la verificación de claves", + "@canceledKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "requestedKeyVerification": "{sender} solicitó verificación de claves", + "@canceledKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "startedKeyVerification": "{sender} ha iniciado la verificación de claves", + "@canceledKeyVerification": { + "type": "text", + "placeholders": { + "sender": {} + } + }, + "subscriptionPopupTitle": "Esta frase podría tener un error gramatical...", + "subscriptionPopupDesc": "Suscríbase hoy mismo para desbloquear la traducción y la corrección gramatical.", + "seeOptions": "Ver opciones", + "continuedWithoutSubscription": "Continuar sin suscribirse", + "trialPeriodExpired": "Su periodo de prueba ha expirado", + "selectToDefine": "Para definir una palabra en este mensaje, ¡sólo tiene que seleccionarla!", + "translation": "traducción", + "audio": "mensaje de audio", + "definitions": "definiciones", + "subscribedToUnlockTools": "Suscríbase para desbloquear herramientas lingüísticas, como" +} diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 913c77e4a..0b27f41e2 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -9,10 +9,12 @@ import 'package:fluffychat/pangea/utils/overlay.dart'; import 'package:fluffychat/pangea/widgets/chat/message_audio_card.dart'; import 'package:fluffychat/pangea/widgets/chat/message_text_selection.dart'; import 'package:fluffychat/pangea/widgets/chat/message_translation_card.dart'; +import 'package:fluffychat/pangea/widgets/chat/message_unsubscribed_card.dart'; import 'package:fluffychat/pangea/widgets/chat/overlay_message.dart'; import 'package:fluffychat/pangea/widgets/igc/word_data_card.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; enum MessageMode { translation, play, definition } @@ -162,35 +164,43 @@ class MessageToolbarState extends State { } } - bool enabledButton(MessageMode mode) { + String getModeTitle(MessageMode mode) { switch (mode) { case MessageMode.translation: - return true; + return L10n.of(context)!.translation; case MessageMode.play: - return true; + return L10n.of(context)!.audio; case MessageMode.definition: - return widget.textSelection.selectedText != null; - // return true; + return L10n.of(context)!.definitions; default: - return false; + return L10n.of(context)! + .oopsSomethingWentWrong; // Title to indicate an error or unsupported mode } } void updateMode(MessageMode newMode) { debugPrint("updating toolbar mode"); + final bool subscribed = + MatrixState.pangeaController.subscriptionController.isSubscribed; setState(() => currentMode = newMode); - switch (currentMode) { - case MessageMode.translation: - showTranslation(); - break; - case MessageMode.play: - playAudio(); - break; - case MessageMode.definition: - showDefinition(); - break; - default: - break; + if (!subscribed) { + child = MessageUnsubscribedCard( + languageTool: getModeTitle(newMode), + ); + } else { + switch (currentMode) { + case MessageMode.translation: + showTranslation(); + break; + case MessageMode.play: + playAudio(); + break; + case MessageMode.definition: + showDefinition(); + break; + default: + break; + } } setState(() {}); } @@ -214,6 +224,7 @@ class MessageToolbarState extends State { void showDefinition() { if (widget.textSelection.selectedText == null || widget.textSelection.selectedText!.isEmpty) { + child = const SelectToDefine(); return; } @@ -312,8 +323,7 @@ class MessageToolbarState extends State { color: currentMode == mode ? Theme.of(context).colorScheme.primary : null, - onPressed: - enabledButton(mode) ? () => updateMode(mode) : null, + onPressed: () => updateMode(mode), ); }).toList() + [ diff --git a/lib/pangea/widgets/chat/message_unsubscribed_card.dart b/lib/pangea/widgets/chat/message_unsubscribed_card.dart new file mode 100644 index 000000000..542fb85e6 --- /dev/null +++ b/lib/pangea/widgets/chat/message_unsubscribed_card.dart @@ -0,0 +1,47 @@ +import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pangea/utils/bot_style.dart'; +import 'package:fluffychat/widgets/matrix.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; + +class MessageUnsubscribedCard extends StatelessWidget { + final String languageTool; + + const MessageUnsubscribedCard({ + super.key, + required this.languageTool, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.fromLTRB(10, 10, 10, 0), + child: Column( + children: [ + Text( + style: BotStyle.text(context), + "${L10n.of(context)!.subscribedToUnlockTools} $languageTool", + textAlign: TextAlign.center, + ), + const SizedBox(height: 10), + SizedBox( + width: double.infinity, + child: TextButton( + onPressed: () { + MatrixState.pangeaController.subscriptionController + .showPaywall(context); + MatrixState.pAnyState.closeOverlay(); + }, + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + (AppConfig.primaryColor).withOpacity(0.1), + ), + ), + child: Text(L10n.of(context)!.getAccess), + ), + ), + ], + ), + ); + } +} diff --git a/lib/pangea/widgets/igc/word_data_card.dart b/lib/pangea/widgets/igc/word_data_card.dart index 7f68db5ea..4b567be03 100644 --- a/lib/pangea/widgets/igc/word_data_card.dart +++ b/lib/pangea/widgets/igc/word_data_card.dart @@ -381,3 +381,20 @@ class PartOfSpeechBlock extends StatelessWidget { ); } } + +class SelectToDefine extends StatelessWidget { + const SelectToDefine({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(8), + child: Text( + L10n.of(context)!.selectToDefine, + style: BotStyle.text(context), + ), + ); + } +}