inlined tooltip

This commit is contained in:
William Jordan-Cooley 2024-06-27 12:30:25 -04:00
parent 10c8936fdf
commit d975e52a04
6 changed files with 64 additions and 12 deletions

View file

@ -46,7 +46,7 @@ class ChatEventList extends StatelessWidget {
// card, attach it on top of the first shown message
WidgetsBinding.instance.addPostFrameCallback((_) {
if (events.isEmpty) return;
controller.pangeaController.instructions.show(
controller.pangeaController.instructions.showInstructionsPopup(
context,
InstructionsEnum.clickMessage,
events[0].eventId,

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/utils/instructions.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import '../../widgets/common/bot_face_svg.dart';
import '../controllers/choreographer.dart';
import '../controllers/it_controller.dart';
@ -37,7 +37,7 @@ class ITBotButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
choreographer.pangeaController.instructions.show(
choreographer.pangeaController.instructions.showInstructionsPopup(
context,
InstructionsEnum.itInstructions,
choreographer.itBotTransformTargetKey,
@ -46,7 +46,8 @@ class ITBotButton extends StatelessWidget {
return IconButton(
icon: const BotFace(width: 40.0, expression: BotExpression.right),
onPressed: () => choreographer.pangeaController.instructions.show(
onPressed: () =>
choreographer.pangeaController.instructions.showInstructionsPopup(
context,
InstructionsEnum.itInstructions,
choreographer.itBotTransformTargetKey,

View file

@ -305,6 +305,7 @@ class MyAnalyticsController extends BaseController {
// if there's new content to be sent, or if lastUpdated hasn't been
// set yet for this room, send the analytics events
if (summaryContent.isNotEmpty || lastUpdated == null) {
await SummaryAnalyticsEvent.sendSummaryAnalyticsEvent(
analyticsRoom,

View file

@ -14,17 +14,26 @@ import 'overlay.dart';
class InstructionsController {
late PangeaController _pangeaController;
/// Instruction popup was closed by the user
final Map<InstructionsEnum, bool> _instructionsClosed = {};
/// Instructions that were shown in that session
final Map<InstructionsEnum, bool> _instructionsShown = {};
/// Returns true if the instructions were turned off by the user via the toggle switch
bool? toggledOff(InstructionsEnum key) =>
_pangeaController.pStoreService.read(key.toString());
/// We have these three methods to make sure that the instructions are not shown too much
InstructionsController(PangeaController pangeaController) {
_pangeaController = pangeaController;
}
/// Returns true if the instructions were turned off by the user
/// via the toggle switch
bool wereInstructionsTurnedOff(InstructionsEnum key) =>
_pangeaController.pStoreService.read(key.toString()) ??
_instructionsClosed[key] ??
false;
toggledOff(key) ?? _instructionsClosed[key] ?? false;
Future<void> updateEnableInstructions(
InstructionsEnum key,
@ -35,7 +44,30 @@ class InstructionsController {
value,
);
Future<void> show(
// return a text widget with constainer that expands to fill a parent container
// and displays instructions text defined in the enum extension
Future<Widget> getInlineTooltip(
BuildContext context,
InstructionsEnum key,
) async {
if (wereInstructionsTurnedOff(key)) {
return const SizedBox();
}
if (L10n.of(context) == null) {
ErrorHandler.logError(
m: "null context in ITBotButton.showCard",
s: StackTrace.current,
);
return const SizedBox();
}
if (_instructionsShown[key] ?? false) {
return const SizedBox();
}
return key.inlineTooltip(context);
}
Future<void> showInstructionsPopup(
BuildContext context,
InstructionsEnum key,
String transformTargetKey, [
@ -135,6 +167,22 @@ extension Copy on InstructionsEnum {
: L10n.of(context)!.tooltipInstructionsBrowserBody;
}
}
Widget inlineTooltip(BuildContext context) {
switch (this) {
case InstructionsEnum.itInstructions:
return Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
body(context),
style: BotStyle.text(context),
),
);
default:
print('inlineTooltip not implemented for $this');
return const SizedBox();
}
}
}
class InstructionsToggle extends StatefulWidget {

View file

@ -172,7 +172,8 @@ class MessageSpeechToTextCardState extends State<MessageSpeechToTextCard> {
number:
"${selectedToken?.confidence ?? speechToTextResponse!.transcript.confidence}%",
toolTip: L10n.of(context)!.accuracy,
onPressed: () => MatrixState.pangeaController.instructions.show(
onPressed: () => MatrixState.pangeaController.instructions
.showInstructionsPopup(
context,
InstructionsEnum.tooltipInstructions,
widget.messageEvent.eventId,
@ -184,7 +185,8 @@ class MessageSpeechToTextCardState extends State<MessageSpeechToTextCard> {
number:
wordsPerMinuteString != null ? "$wordsPerMinuteString" : "??",
toolTip: L10n.of(context)!.wordsPerMinute,
onPressed: () => MatrixState.pangeaController.instructions.show(
onPressed: () => MatrixState.pangeaController.instructions
.showInstructionsPopup(
context,
InstructionsEnum.tooltipInstructions,
widget.messageEvent.eventId,

View file

@ -115,7 +115,7 @@ class PangeaRichTextState extends State<PangeaRichText> {
@override
Widget build(BuildContext context) {
if (blur > 0) {
pangeaController.instructions.show(
pangeaController.instructions.showInstructionsPopup(
context,
InstructionsEnum.blurMeansTranslate,
widget.pangeaMessageEvent.eventId,