Skip to content

Commit

Permalink
add toggle for auto-playing messages in learning settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurdin committed Mar 25, 2024
1 parent 64f57e0 commit 0880f6d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
4 changes: 3 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3950,5 +3950,7 @@
},
"kickBotWarning": "Kicking Pangea Bot will remove the conversation bot from this chat.",
"joinToView": "Join this room to view details",
"refresh": "Refresh"
"refresh": "Refresh",
"autoPlayTitle": "Auto Play Messages",
"autoPlayDesc": "When enabled, the text-to-speech audio of messages will play automatically when selected."
}
5 changes: 4 additions & 1 deletion assets/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4583,5 +4583,8 @@
"selectToDefine": "Haga doble clic en una palabra para ver su definición.",
"kickBotWarning": "Patear Pangea Bot eliminará el bot de conversación de este chat.",
"activateTrial": "Activar prueba gratuita",
"refresh": "Actualizar"
"refresh": "Actualizar",
"joinToView": "Únete a esta sala para ver los detalles",
"autoPlayTitle": "Reproducción automática de mensajes",
"autoPlayDesc": "Cuando está activado, el audio de texto a voz de los mensajes se reproducirá automáticamente cuando se seleccione."
}
1 change: 1 addition & 0 deletions lib/pangea/constants/local.key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class PLocalKey {
static const String activatedTrialKey = '7C4EuKIsph';
static const String dismissedPaywall = 'dismissedPaywall';
static const String paywallBackoff = 'paywallBackoff';
static const String autoPlayMessages = 'autoPlayMessages';
}
19 changes: 14 additions & 5 deletions lib/pangea/pages/settings_learning/settings_learning_view.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import 'package:fluffychat/pangea/constants/local.key.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
import 'package:fluffychat/pangea/pages/settings_learning/settings_learning.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/widgets/user_settings/country_picker_tile.dart';
import 'package:fluffychat/pangea/widgets/user_settings/language_tile.dart';
import 'package:fluffychat/pangea/widgets/user_settings/p_settings_switch_list_tile.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import '../../../config/app_config.dart';

class SettingsLearningView extends StatelessWidget {
Expand Down Expand Up @@ -60,6 +60,15 @@ class SettingsLearningView extends StatelessWidget {
subtitle: setting.toolDescription(context),
pStoreKey: setting.toString(),
),
PSettingsSwitchListTile.adaptive(
defaultValue: controller.pangeaController.pStoreService.read(
PLocalKey.autoPlayMessages,
) ??
true,
title: L10n.of(context)!.autoPlayTitle,
subtitle: L10n.of(context)!.autoPlayDesc,
pStoreKey: PLocalKey.autoPlayMessages,
),
],
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/pangea/utils/get_chat_list_item_subtitle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class GetChatListItemSubtitle {
);

while (index < timeline.events.length &&
timeline.events[index].content.tryGet(ModelKey.transcription) !=
null) {
(timeline.events[index].content.tryGet(ModelKey.transcription) !=
null ||
timeline.events[index].type != EventTypes.Message)) {
index++;
}

Expand Down
9 changes: 8 additions & 1 deletion lib/pangea/widgets/chat/message_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pangea/constants/local.key.dart';
import 'package:fluffychat/pangea/models/pangea_message_event.dart';
import 'package:fluffychat/pangea/utils/any_state_holder.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
Expand Down Expand Up @@ -280,7 +281,13 @@ class MessageToolbarState extends State<MessageToolbar> {
});

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
updateMode(MessageMode.play);
final bool autoplay = MatrixState.pangeaController.pStoreService.read(
PLocalKey.autoPlayMessages,
) ??
true;
autoplay
? updateMode(MessageMode.play)
: updateMode(MessageMode.translation);
});

Timer? timer;
Expand Down

0 comments on commit 0880f6d

Please sign in to comment.