feat: Bring back language setting in bot avatar popup
This commit is contained in:
parent
f1bede9de2
commit
f511371aa9
10 changed files with 125 additions and 103 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);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
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/models/bot_options_model.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/common/widgets/dropdown_text_button.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';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class BotChatSettingsDialog extends StatefulWidget {
|
||||
final Room room;
|
||||
|
|
@ -48,66 +50,65 @@ class BotChatSettingsDialogState extends State<BotChatSettingsDialog> {
|
|||
|
||||
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;
|
||||
});
|
||||
|
||||
final model = widget.room.botOptions ?? const BotOptionsModel();
|
||||
model.targetLanguage = lang?.langCode;
|
||||
model.targetVoice = null;
|
||||
|
||||
try {
|
||||
await widget.room.setBotOptions(model);
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: s,
|
||||
data: {
|
||||
'roomId': widget.room.id,
|
||||
'langCode': lang?.langCode,
|
||||
},
|
||||
);
|
||||
}
|
||||
await _update((model) {
|
||||
model.userSettings.targetLanguage = lang.langCode;
|
||||
model.userSettings.voice = null;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setLevel(LanguageLevelTypeEnum? level) async {
|
||||
if (level == null) return;
|
||||
|
||||
if (level == null || level == _userProfile.userSettings.cefrLevel) return;
|
||||
setState(() => _selectedLevel = level);
|
||||
final model = widget.room.botOptions ?? const BotOptionsModel();
|
||||
model.languageLevel = level;
|
||||
try {
|
||||
await widget.room.setBotOptions(model);
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: s,
|
||||
data: {
|
||||
'roomId': widget.room.id,
|
||||
'level': level.name,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
await _update((model) {
|
||||
model.userSettings.cefrLevel = level;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setVoice(String? voice) async {
|
||||
if (voice == _userProfile.userSettings.voice) return;
|
||||
|
||||
setState(() => _selectedVoice = voice);
|
||||
final model = widget.room.botOptions ?? const BotOptionsModel();
|
||||
model.targetVoice = voice;
|
||||
try {
|
||||
await widget.room.setBotOptions(model);
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: s,
|
||||
data: {
|
||||
'roomId': widget.room.id,
|
||||
'voice': voice,
|
||||
},
|
||||
);
|
||||
}
|
||||
await _update((model) {
|
||||
model.userSettings.voice = voice;
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -151,38 +152,17 @@ class BotChatSettingsDialogState extends State<BotChatSettingsDialog> {
|
|||
initialLevel: _selectedLevel,
|
||||
onChanged: _setLevel,
|
||||
enabled: !widget.room.isActivitySession,
|
||||
width: 300,
|
||||
maxHeight: 300,
|
||||
// width: 300,
|
||||
// maxHeight: 300,
|
||||
),
|
||||
DropdownButtonFormField2<String>(
|
||||
customButton: _selectedVoice != null
|
||||
? CustomDropdownTextButton(text: _selectedVoice!)
|
||||
: null,
|
||||
menuItemStyleData: const MenuItemStyleData(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: L10n.of(context).voice,
|
||||
),
|
||||
isExpanded: true,
|
||||
dropdownStyleData: DropdownStyleData(
|
||||
maxHeight: 250,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(14.0),
|
||||
),
|
||||
),
|
||||
items: (_selectedLang?.voices ?? <String>[]).map((voice) {
|
||||
return DropdownMenuItem(
|
||||
value: voice,
|
||||
child: Text(voice),
|
||||
);
|
||||
}).toList(),
|
||||
VoiceDropdown(
|
||||
onChanged: _setVoice,
|
||||
value: _selectedVoice,
|
||||
language: _selectedLang,
|
||||
enabled: !widget.room.isActivitySession ||
|
||||
(_selectedLang != null &&
|
||||
_selectedLang ==
|
||||
MatrixState.pangeaController.userController.userL2),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
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';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class BotSettingsLanguageIcon extends StatelessWidget {
|
||||
final User user;
|
||||
|
|
|
|||
|
|
@ -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