You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.3 KiB
151 lines
5.3 KiB
// import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../../../../routes/app_routes.dart';
|
|
import '../../../../data/services/ble_manager.dart';
|
|
|
|
/// 翻译中间层控制器
|
|
/// 负责管理翻译功能入口的导航和状态
|
|
class TranslationMiddlewareController extends GetxController {
|
|
final BleManager bleManager = Get.find<BleManager>(); //获取BLE管理器实例
|
|
|
|
/// 翻译功能选项列表
|
|
final List<TranslationOption> translationOptions = [
|
|
TranslationOption(
|
|
translationId: 'simultaneous',
|
|
title: 'simultaneousTranslation'.tr, // 实时翻译
|
|
// description: 'realtimeTranslationDescription', // 实时语音翻译,支持多种语言
|
|
icon: Icons.record_voice_over,
|
|
startColor: Colors.blue[400]!, // 亮蓝
|
|
endColor: Colors.blue[600]!, //深蓝
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.blue[500]!, // 主蓝
|
|
targetRoute: Routes.translation,
|
|
),
|
|
TranslationOption(
|
|
translationId: 'call',
|
|
title: 'callTranslation'.tr, // 通话翻译
|
|
// description: 'simultaneousTranslationInfo', // 双向对话翻译,面对面交流
|
|
icon: Icons.call,
|
|
startColor: Colors.green[400]!, // 绿色
|
|
endColor: Colors.green[600]!, // 深绿
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.green[500]!, // 主绿
|
|
targetRoute: Routes.translation,
|
|
),
|
|
TranslationOption(
|
|
translationId: 'faceToFace',
|
|
title: 'faceToFaceTranslation'.tr, // 面对面翻译
|
|
// description: 'faceToFaceTranslationDescription', // 面对面交流,支持多种语言
|
|
icon: Icons.people,
|
|
startColor: Colors.orange[400]!, // 橙色
|
|
endColor: Colors.orange[600]!, // 深橙
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.orange[500]!, // 主橙
|
|
targetRoute: Routes.translation,
|
|
),
|
|
TranslationOption(
|
|
translationId: 'audioVideo',
|
|
title: 'audioVideoTranslation'.tr, // 多媒体翻译
|
|
//description: 'audioVideoTranslationDescription', // 支持音频和视频翻译
|
|
icon: Icons.videocam,
|
|
startColor: Colors.purple[400]!, // 亮紫
|
|
endColor: Colors.purple[600]!, // 深紫
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.purple[500]!, // 主紫
|
|
targetRoute: Routes.translation,
|
|
),
|
|
TranslationOption(
|
|
translationId: 'picture_translator',
|
|
title: 'pictureTranslation'.tr, // 图片翻译
|
|
icon: Icons.image,
|
|
startColor: Colors.teal[400]!, // 青色
|
|
endColor: Colors.teal[600]!, // 深青
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.teal[500]!, // 主青
|
|
targetRoute: Routes.pictureTranslation,
|
|
),
|
|
TranslationOption(
|
|
translationId: 'text_translator',
|
|
title: 'textTranslation'.tr, // 文本翻译
|
|
icon: Icons.text_fields,
|
|
startColor: Colors.indigo[400]!, // 靛蓝
|
|
endColor: Colors.indigo[600]!, // 深靛
|
|
iconBgColor: Colors.white, // 白色
|
|
iconColor: Colors.indigo[500]!, // 主靛
|
|
targetRoute: Routes.textTranslation,
|
|
),
|
|
// TranslationOption(
|
|
// translationId: 'voice_replication',
|
|
// title: '声音复刻',
|
|
// icon: Icons.volume_up,
|
|
// startColor: Colors.pink[400]!, // 粉色
|
|
// endColor: Colors.pink[600]!, // 深粉
|
|
// iconBgColor: Colors.white, // 白色
|
|
// iconColor: Colors.pink[500]!, // 主粉
|
|
// targetRoute: Routes.voiceReplication,
|
|
// ),
|
|
];
|
|
|
|
/// 导航到指定的翻译功能
|
|
void navigateToTranslationFeature(TranslationOption option) {
|
|
// 不可用则提示用户连接设备
|
|
if (!isOptionEnabled(option)) {
|
|
// 连接设备 / 请连接 Voitrans 设备
|
|
Get.snackbar('connectDevice'.tr,
|
|
'pleaseConnectDeepSoundDevice'.tr, // 连接设备 / 请连接 Voitrans 设备
|
|
snackPosition: SnackPosition.TOP,
|
|
duration: const Duration(seconds: 1));
|
|
//EasyLoading.showInfo('connectDevice'.tr);
|
|
return;
|
|
}
|
|
Get.toNamed(option.targetRoute,
|
|
arguments: {'translationId': option.translationId});
|
|
}
|
|
|
|
/// 获取翻译选项的本地化标题
|
|
String getLocalizedTitle(TranslationOption option) {
|
|
return option.title.tr;
|
|
}
|
|
|
|
/// 获取翻译选项的本地化描述
|
|
String getLocalizedDescription(TranslationOption option) {
|
|
// return option.description.tr;
|
|
return '';
|
|
}
|
|
|
|
/// 判断选项是否可用(音视频/通话依赖BLE连接)
|
|
bool isOptionEnabled(TranslationOption option) {
|
|
// 当 translationId 为 audioVideo 或 call 时,需要 BLE 已连接
|
|
if (option.translationId == 'audioVideo' ||
|
|
option.translationId == 'call') {
|
|
return bleManager.isConnected;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/// 翻译功能选项数据模型
|
|
class TranslationOption {
|
|
final String translationId;
|
|
final String title;
|
|
// final String description;
|
|
final IconData icon;
|
|
final Color startColor;
|
|
final Color endColor;
|
|
final Color iconBgColor;
|
|
final Color iconColor;
|
|
final String targetRoute;
|
|
|
|
TranslationOption({
|
|
required this.translationId,
|
|
required this.title,
|
|
// required this.description,
|
|
required this.icon,
|
|
required this.startColor,
|
|
required this.endColor,
|
|
required this.iconBgColor,
|
|
required this.iconColor,
|
|
required this.targetRoute,
|
|
});
|
|
}
|
|
|