Merge pull request #5441 from pangeachat/5410-bring-back-language-setting-in-bot-avatar-popup
5410 bring back language setting in bot avatar popup
This commit is contained in:
commit
b6fc70069d
10 changed files with 290 additions and 21 deletions
|
|
@ -210,8 +210,6 @@ class HtmlMessage extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
debugPrint("Results: $result");
|
||||
|
||||
int position = 0;
|
||||
final tokenPositions = tokens != null
|
||||
? TokensUtil.getAdjacentTokenPositions(event.eventId, tokens!)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import 'package:fluffychat/pages/chat/events/room_creation_state_event.dart';
|
|||
import 'package:fluffychat/pangea/activity_sessions/activity_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/activity_sessions/activity_session_chat/activity_roles_event_widget.dart';
|
||||
import 'package:fluffychat/pangea/activity_sessions/activity_summary_widget.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/bot/widgets/bot_settings_language_icon.dart';
|
||||
import 'package:fluffychat/pangea/chat/extensions/custom_room_display_extension.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/pressable_button.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/shimmer_background.dart';
|
||||
|
|
@ -476,6 +478,18 @@ class Message extends StatelessWidget {
|
|||
presenceBackgroundColor: wallpaperMode
|
||||
? Colors.transparent
|
||||
: null,
|
||||
// #Pangea
|
||||
miniIcon:
|
||||
user.id == BotName.byEnvironment
|
||||
? BotSettingsLanguageIcon(
|
||||
user: user,
|
||||
)
|
||||
: null,
|
||||
presenceOffset:
|
||||
user.id == BotName.byEnvironment
|
||||
? const Offset(0, 0)
|
||||
: null,
|
||||
// Pangea#
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import 'package:cached_network_image/cached_network_image.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/bot/widgets/bot_settings_language_icon.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/shimmer_background.dart';
|
||||
import 'package:fluffychat/utils/string_color.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
|
|
@ -67,6 +69,14 @@ class ActivityParticipantIndicator extends StatelessWidget {
|
|||
name: userId!.localpart,
|
||||
size: 60.0,
|
||||
userId: userId,
|
||||
miniIcon:
|
||||
room != null && userId == BotName.byEnvironment
|
||||
? BotSettingsLanguageIcon(user: user!)
|
||||
: null,
|
||||
presenceOffset:
|
||||
room != null && userId == BotName.byEnvironment
|
||||
? const Offset(0, 0)
|
||||
: null,
|
||||
)
|
||||
: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
|
|
|
|||
|
|
@ -332,7 +332,6 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
|
|||
AnalyticsPractice.bypassExitConfirmation = false;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("ERROR");
|
||||
AnalyticsPractice.bypassExitConfirmation = true;
|
||||
activityState.value = AsyncState.error(e);
|
||||
} finally {
|
||||
|
|
@ -359,7 +358,6 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
|
|||
activityState.value = AsyncState.loaded(res);
|
||||
AnalyticsPractice.bypassExitConfirmation = false;
|
||||
} catch (e) {
|
||||
debugPrint("ERROR");
|
||||
AnalyticsPractice.bypassExitConfirmation = true;
|
||||
if (!mounted) return;
|
||||
activityState.value = AsyncState.error(e);
|
||||
|
|
|
|||
172
lib/pangea/bot/widgets/bot_chat_settings_dialog.dart
Normal file
172
lib/pangea/bot/widgets/bot_chat_settings_dialog.dart
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/activity_sessions/activity_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/utils/bot_client_extension.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/widgets/language_level_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/languages/language_model.dart';
|
||||
import 'package:fluffychat/pangea/languages/p_language_store.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/language_level_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/p_language_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/voice_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/user/user_model.dart' as user;
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class BotChatSettingsDialog extends StatefulWidget {
|
||||
final Room room;
|
||||
|
||||
const BotChatSettingsDialog({
|
||||
required this.room,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
BotChatSettingsDialogState createState() => BotChatSettingsDialogState();
|
||||
}
|
||||
|
||||
class BotChatSettingsDialogState extends State<BotChatSettingsDialog> {
|
||||
LanguageModel? _selectedLang;
|
||||
LanguageLevelTypeEnum? _selectedLevel;
|
||||
String? _selectedVoice;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
final botSettings = widget.room.botOptions;
|
||||
final activityPlan = _isActivity ? widget.room.activityPlan : null;
|
||||
|
||||
_selectedLevel = activityPlan?.req.cefrLevel ?? botSettings?.languageLevel;
|
||||
_selectedVoice = botSettings?.targetVoice;
|
||||
final lang =
|
||||
activityPlan?.req.targetLanguage ?? botSettings?.targetLanguage;
|
||||
if (lang != null) {
|
||||
_selectedLang = PLanguageStore.byLangCode(lang);
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
bool get _isActivity => widget.room.isActivitySession;
|
||||
|
||||
user.Profile get _userProfile =>
|
||||
MatrixState.pangeaController.userController.profile;
|
||||
|
||||
Future<void> _update(user.Profile Function(user.Profile) update) async {
|
||||
try {
|
||||
await MatrixState.pangeaController.userController
|
||||
.updateProfile(update, waitForDataInSync: true)
|
||||
.timeout(const Duration(seconds: 15));
|
||||
await Matrix.of(context).client.updateBotOptions(
|
||||
_userProfile.userSettings,
|
||||
);
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: s,
|
||||
data: {
|
||||
'roomId': widget.room.id,
|
||||
'model': _userProfile.toJson(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setLanguage(LanguageModel? lang) async {
|
||||
if (lang == null ||
|
||||
lang.langCode == _userProfile.userSettings.targetLanguage) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_selectedLang = lang;
|
||||
_selectedVoice = null;
|
||||
});
|
||||
|
||||
await _update((model) {
|
||||
model.userSettings.targetLanguage = lang.langCode;
|
||||
model.userSettings.voice = null;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setLevel(LanguageLevelTypeEnum? level) async {
|
||||
if (level == null || level == _userProfile.userSettings.cefrLevel) return;
|
||||
setState(() => _selectedLevel = level);
|
||||
|
||||
await _update((model) {
|
||||
model.userSettings.cefrLevel = level;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setVoice(String? voice) async {
|
||||
if (voice == _userProfile.userSettings.voice) return;
|
||||
|
||||
setState(() => _selectedVoice = voice);
|
||||
await _update((model) {
|
||||
model.userSettings.voice = voice;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Column(
|
||||
spacing: 12.0,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.room.isActivitySession)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.all(0.0),
|
||||
minLeadingWidth: 12.0,
|
||||
leading: Icon(
|
||||
Icons.info_outline,
|
||||
size: 12.0,
|
||||
color: Theme.of(context).disabledColor,
|
||||
),
|
||||
title: Text(
|
||||
L10n.of(context).activitySettingsOverrideWarning,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).disabledColor,
|
||||
fontSize: 12.0,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox(),
|
||||
PLanguageDropdown(
|
||||
onChange: _setLanguage,
|
||||
initialLanguage: _selectedLang,
|
||||
languages:
|
||||
MatrixState.pangeaController.pLanguageStore.targetOptions,
|
||||
isL2List: true,
|
||||
decorationText: L10n.of(context).targetLanguage,
|
||||
enabled: !widget.room.isActivitySession,
|
||||
),
|
||||
LanguageLevelDropdown(
|
||||
initialLevel: _selectedLevel,
|
||||
onChanged: _setLevel,
|
||||
enabled: !widget.room.isActivitySession,
|
||||
// width: 300,
|
||||
// maxHeight: 300,
|
||||
),
|
||||
VoiceDropdown(
|
||||
onChanged: _setVoice,
|
||||
value: _selectedVoice,
|
||||
language: _selectedLang,
|
||||
enabled: !widget.room.isActivitySession ||
|
||||
(_selectedLang != null &&
|
||||
_selectedLang ==
|
||||
MatrixState.pangeaController.userController.userL2),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
57
lib/pangea/bot/widgets/bot_settings_language_icon.dart
Normal file
57
lib/pangea/bot/widgets/bot_settings_language_icon.dart
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/activity_sessions/activity_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/member_actions_popup_menu_button.dart';
|
||||
|
||||
class BotSettingsLanguageIcon extends StatelessWidget {
|
||||
final User user;
|
||||
|
||||
const BotSettingsLanguageIcon({
|
||||
super.key,
|
||||
required this.user,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final room = user.room;
|
||||
String? langCode = room.botOptions?.targetLanguage;
|
||||
if (room.isActivitySession && room.activityPlan != null) {
|
||||
langCode = room.activityPlan!.req.targetLanguage;
|
||||
}
|
||||
if (langCode == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
langCode = langCode.split('-').first;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(32.0),
|
||||
onTap: room.isRoomAdmin
|
||||
? () => showMemberActionsPopupMenu(
|
||||
context: context,
|
||||
user: user,
|
||||
room: room,
|
||||
)
|
||||
: null,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
child: Text(
|
||||
langCode,
|
||||
style: TextStyle(
|
||||
fontSize: 10.0,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,11 +6,13 @@ import 'package:fluffychat/pangea/learning_settings/language_level_type_enum.dar
|
|||
class LanguageLevelDropdown extends StatelessWidget {
|
||||
final LanguageLevelTypeEnum? initialLevel;
|
||||
final Function(LanguageLevelTypeEnum)? onChanged;
|
||||
final bool enabled;
|
||||
|
||||
const LanguageLevelDropdown({
|
||||
super.key,
|
||||
this.initialLevel = LanguageLevelTypeEnum.a1,
|
||||
this.onChanged,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -30,9 +32,11 @@ class LanguageLevelDropdown extends StatelessWidget {
|
|||
isExpanded: true,
|
||||
dropdownColor: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(14.0),
|
||||
onChanged: (value) {
|
||||
if (value != null) onChanged?.call(value);
|
||||
},
|
||||
onChanged: enabled
|
||||
? (value) {
|
||||
if (value != null) onChanged?.call(value);
|
||||
}
|
||||
: null,
|
||||
initialValue: initialLevel,
|
||||
items: LanguageLevelTypeEnum.values
|
||||
.map((LanguageLevelTypeEnum levelOption) {
|
||||
|
|
|
|||
|
|
@ -10,19 +10,25 @@ class VoiceDropdown extends StatelessWidget {
|
|||
final String? value;
|
||||
final LanguageModel? language;
|
||||
final Function(String?) onChanged;
|
||||
final bool enabled;
|
||||
|
||||
const VoiceDropdown({
|
||||
super.key,
|
||||
this.value,
|
||||
this.language,
|
||||
required this.onChanged,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final voices = (language?.voices ?? <String>[]);
|
||||
final value =
|
||||
this.value != null && voices.contains(this.value) ? this.value : null;
|
||||
|
||||
return DropdownButtonFormField2<String>(
|
||||
customButton:
|
||||
value != null ? CustomDropdownTextButton(text: value!) : null,
|
||||
value != null ? CustomDropdownTextButton(text: value) : null,
|
||||
menuItemStyleData: const MenuItemStyleData(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
|
|
@ -40,14 +46,14 @@ class VoiceDropdown extends StatelessWidget {
|
|||
borderRadius: BorderRadius.circular(14.0),
|
||||
),
|
||||
),
|
||||
items: (language?.voices ?? <String>[]).map((voice) {
|
||||
items: voices.map((voice) {
|
||||
return DropdownMenuItem(
|
||||
value: voice,
|
||||
child: Text(voice),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: onChanged,
|
||||
value: value,
|
||||
onChanged: enabled ? onChanged : null,
|
||||
value: voices.contains(value) ? value : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class Avatar extends StatelessWidget {
|
|||
|
||||
final double? presenceSize;
|
||||
final Offset? presenceOffset;
|
||||
final Widget? miniIcon;
|
||||
// Pangea#
|
||||
|
||||
const Avatar({
|
||||
|
|
@ -47,6 +48,7 @@ class Avatar extends StatelessWidget {
|
|||
this.userId,
|
||||
this.presenceSize,
|
||||
this.presenceOffset,
|
||||
this.miniIcon,
|
||||
// Pangea#
|
||||
super.key,
|
||||
});
|
||||
|
|
@ -138,7 +140,13 @@ class Avatar extends StatelessWidget {
|
|||
),
|
||||
// #Pangea
|
||||
// if (presenceUserId != null)
|
||||
if (presenceUserId != null && size >= 32.0 && showPresence)
|
||||
if (miniIcon != null)
|
||||
Positioned(
|
||||
bottom: presenceOffset?.dy ?? -3,
|
||||
right: presenceOffset?.dx ?? -3,
|
||||
child: miniIcon!,
|
||||
)
|
||||
else if (presenceUserId != null && size >= 32.0 && showPresence)
|
||||
// Pangea#
|
||||
PresenceBuilder(
|
||||
client: client,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import 'package:matrix/matrix.dart';
|
|||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/level_display_name.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/bot/widgets/bot_chat_settings_dialog.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/permission_slider_dialog.dart';
|
||||
import 'adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
|
|
@ -106,15 +108,15 @@ void showMemberActionsPopupMenu({
|
|||
],
|
||||
),
|
||||
),
|
||||
// if (user.id == BotName.byEnvironment && room != null && room.isRoomAdmin)
|
||||
// PopupMenuItem(
|
||||
// enabled: false,
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 12.0,
|
||||
// right: 12.0,
|
||||
// ),
|
||||
// child: BotChatSettingsDialog(room: room),
|
||||
// ),
|
||||
if (user.id == BotName.byEnvironment && room != null && room.isRoomAdmin)
|
||||
PopupMenuItem(
|
||||
enabled: false,
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12.0,
|
||||
right: 12.0,
|
||||
),
|
||||
child: BotChatSettingsDialog(room: room),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
// #Pangea
|
||||
if (user.room.client.userID != user.id)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue