Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

weicu
tanlongsheng 12 months ago
parent
commit
65f2b6cff0
  1. 2
      lib/core/translations/language/en_us.dart
  2. 2
      lib/core/translations/language/zh_cn.dart
  3. 40
      lib/data/services/version_update_service.dart
  4. 4
      lib/modules/translation/controllers/translation_controller.dart
  5. 225
      lib/modules/translation/views/translation_view.dart

2
lib/core/translations/language/en_us.dart

@ -984,6 +984,8 @@ const Map<String, String> enUS = {
"phoneUser": "Phone User", "phoneUser": "Phone User",
"selectSourceLanguage": "Select Source Language", "selectSourceLanguage": "Select Source Language",
"selectTargetLanguage": "Select Target Language", "selectTargetLanguage": "Select Target Language",
"me": "Me", //我
"counterPart": "Counterpart", //对方
// 翻译历史页 // 翻译历史页
"noTranslationHistory": "No translation history", "noTranslationHistory": "No translation history",

2
lib/core/translations/language/zh_cn.dart

@ -904,6 +904,8 @@ const Map<String, String> zhCN = {
"phoneUser": "手机用户", "phoneUser": "手机用户",
"selectSourceLanguage": "选择源语言", "selectSourceLanguage": "选择源语言",
"selectTargetLanguage": "选择目标语言", "selectTargetLanguage": "选择目标语言",
"me": "我", //我
"counterPart": "对方", //对方
// 翻译历史页 (translation_history_view.dart) // 翻译历史页 (translation_history_view.dart)
"noTranslationHistory": "暂无历史记录", "noTranslationHistory": "暂无历史记录",

40
lib/data/services/version_update_service.dart

@ -83,6 +83,13 @@ class VersionUpdateService extends GetxService {
final Logger _logger = Logger(); final Logger _logger = Logger();
// @override
// void onInit() {
// getCurrentVersion();
// getCurrentPlatformInfo();
// super.onInit();
// }
/// 获取当前应用版本信息 /// 获取当前应用版本信息
Future<String> getCurrentVersion() async { Future<String> getCurrentVersion() async {
try { try {
@ -224,9 +231,14 @@ class VersionUpdateService extends GetxService {
_latestVersion = appInfo.version; _latestVersion = appInfo.version;
_updateUrl = appInfo.address; _updateUrl = appInfo.address;
// 设置游客登录显示状态 // 设置游客登录显示状态(先用当前渠道结果作为回退,再用.env渠道覆盖以保持一致)
_isShowTourists = appInfo.tourists; _isShowTourists = appInfo.tourists;
_logger.d('从服务器获取游客登录配置: ${appInfo.tourists}'); if (_channel != platformInfo.channel) {
//[4]当前渠道与.env渠道不同,需要从.env渠道获取游客登录配置
await _refreshTouristsFromEnv();
}
_logger.d('从服务器获取游客登录配置(最终): ${_isShowTourists}');
// if (channelAppResponse.code != 0 || channelAppResponse.data == null) { // if (channelAppResponse.code != 0 || channelAppResponse.data == null) {
// _logger.w('获取版本信息失败: ${channelAppResponse.msg}'); // _logger.w('获取版本信息失败: ${channelAppResponse.msg}');
@ -269,6 +281,30 @@ class VersionUpdateService extends GetxService {
} }
} }
/// 从.env文件刷新游客登录配置
Future<void> _refreshTouristsFromEnv() async {
try {
final envChannelName = dotenv.env['Channel'];
if (envChannelName == null || envChannelName.isEmpty) {
_logger.w('未配置.env Channel,沿用当前渠道的游客配置: ${_isShowTourists}');
return;
}
final envChannel = UserChannel.fromName(envChannelName);
final resp = await Api.getChannelApp({'channel': envChannel.value});
if (resp != null && resp.containsKey('app')) {
final envAppInfo = AppInfo.fromJson(resp['app']);
_isShowTourists = envAppInfo.tourists;
_logger.d(
'游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName)');
} else {
_logger.w('按.env渠道获取游客配置失败:响应为空或不含app字段');
}
} catch (e) {
_logger.w('按.env渠道同步游客配置失败: $e');
}
}
/// 判断是否需要强制更新 /// 判断是否需要强制更新
/// 当主版本号(第一位数字)不同时返回true /// 当主版本号(第一位数字)不同时返回true
bool _shouldForceUpdate(String current, String latest) { bool _shouldForceUpdate(String current, String latest) {

4
lib/modules/translation/controllers/translation_controller.dart

@ -212,10 +212,10 @@ class TranslationController extends GetxController with WidgetsBindingObserver {
final sourceLanguageName = final sourceLanguageName =
_languageManager.getChineseNameByAsrCode(item.sourceLanguageCode) ?? _languageManager.getChineseNameByAsrCode(item.sourceLanguageCode) ??
'未知'; 'unknown';
final targetLanguageName = final targetLanguageName =
_languageManager.getChineseNameByAsrCode(item.targetLanguageCode) ?? _languageManager.getChineseNameByAsrCode(item.targetLanguageCode) ??
'未知'; 'unknown';
final data = FloatingWindowData( final data = FloatingWindowData(
sourceText: item.sourceText, sourceText: item.sourceText,

225
lib/modules/translation/views/translation_view.dart

@ -208,8 +208,9 @@ class TranslationView extends GetView<TranslationController> {
children: [ children: [
// 悬浮窗切换按钮(仅在支持的模式下显示) // 悬浮窗切换按钮(仅在支持的模式下显示)
Obx(() { Obx(() {
if (controller.currentMode.value == 'call' || if (Platform.isAndroid &&
controller.currentMode.value == 'audioVideo') { (controller.currentMode.value == 'call' ||
controller.currentMode.value == 'audioVideo')) {
return IconButton( return IconButton(
icon: Icon( icon: Icon(
controller.isFloatingWindowEnabled.value controller.isFloatingWindowEnabled.value
@ -269,106 +270,150 @@ class TranslationView extends GetView<TranslationController> {
}), }),
], ],
bottom: PreferredSize( bottom: PreferredSize(
preferredSize: Size.fromHeight(50.h), preferredSize: Size.fromHeight(
controller.currentMode.value == 'call' ? 70.h : 50.h,
),
child: Padding( child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
child: Row( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min,
children: [ children: [
// 源语言选择 // 原语言选择行
Expanded( Row(
child: GestureDetector( mainAxisAlignment: MainAxisAlignment.center,
onTap: () => LanguageSelectionDialog.show(true, isDarkMode), children: [
child: Container( // 源语言选择
padding: Expanded(
EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h), child: GestureDetector(
decoration: BoxDecoration( onTap: () =>
color: isDarkMode LanguageSelectionDialog.show(true, isDarkMode),
? Colors.white.withOpacity(0.1) child: Container(
: Colors.grey[100], padding: EdgeInsets.symmetric(
borderRadius: BorderRadius.circular(16.r), horizontal: 8.w, vertical: 4.h),
decoration: BoxDecoration(
color: isDarkMode
? Colors.white.withOpacity(0.1)
: Colors.grey[100],
borderRadius: BorderRadius.circular(16.r),
),
child: Obx(() => Text(
'${controller.sourceLanguage.value.split(' ')[0]}'
.tr,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.white : Colors.black,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
)),
),
), ),
child: Obx(() => Text(
'${controller.sourceLanguage.value.split(' ')[0]}'
.tr, // Just show the Chinese part
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.white : Colors.black,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
)),
), ),
),
),
// 语言互换按钮 // 语言互换按钮
GestureDetector( GestureDetector(
onTap: controller.swapLanguages, onTap: controller.swapLanguages,
child: Container( child: Container(
margin: EdgeInsets.symmetric(horizontal: 8.w), margin: EdgeInsets.symmetric(horizontal: 8.w),
padding: EdgeInsets.all(4.r), padding: EdgeInsets.all(4.r),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isDarkMode color: isDarkMode
? AppColors.primary.withOpacity(0.2) ? AppColors.primary.withOpacity(0.2)
: Colors.blue[50], : Colors.blue[50],
shape: BoxShape.circle, shape: BoxShape.circle,
),
child: Icon(
Icons.swap_horiz,
color: isDarkMode ? AppColors.primary : Colors.blue,
size: 20.sp,
),
),
), ),
child: Icon(
Icons.swap_horiz, // 目标语言选择
color: isDarkMode ? AppColors.primary : Colors.blue, Expanded(
size: 20.sp, child: GestureDetector(
onTap: () =>
LanguageSelectionDialog.show(false, isDarkMode),
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 8.w, vertical: 4.h),
decoration: BoxDecoration(
color: isDarkMode
? Colors.white.withOpacity(0.1)
: Colors.grey[100],
borderRadius: BorderRadius.circular(16.r),
),
child: Obx(() => Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Text(
'${controller.targetLanguage.value.split(' ')[0]}'
.tr,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode
? Colors.white
: Colors.black,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
),
//只在通话翻译模式下显示电话图标
if (controller.currentMode.value == 'call') ...[
SizedBox(width: 4.w),
Icon(
Icons.phone_in_talk,
size: 20.sp,
color: isDarkMode
? Colors.white70
: Colors.grey[600],
),
],
],
)),
),
),
), ),
), ],
), ),
// 目标语言选择 // 通话模式下的“对方 / 我”标签行
Expanded( if (controller.currentMode.value == 'call') ...[
child: GestureDetector( SizedBox(height: 6.h),
onTap: () => LanguageSelectionDialog.show(false, isDarkMode), Row(
child: Container( children: [
padding: Expanded(
EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h), child: Text(
decoration: BoxDecoration( 'me'.tr, //我
color: isDarkMode style: TextStyle(
? Colors.white.withOpacity(0.1) fontSize: 12.sp,
: Colors.grey[100], color: isDarkMode ? Colors.white70 : Colors.black54,
borderRadius: BorderRadius.circular(16.r), fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
), ),
child: Obx(() => Row( // 预留与上方互换按钮大致等宽的间距,保证对齐
mainAxisAlignment: MainAxisAlignment.center, SizedBox(width: 44.w),
children: [ Expanded(
Flexible( child: Text(
child: Text( 'counterPart'.tr, //对方
'${controller.targetLanguage.value.split(' ')[0]}' style: TextStyle(
.tr, fontSize: 12.sp,
style: TextStyle( color: isDarkMode ? Colors.white70 : Colors.black54,
fontSize: 16.sp, fontWeight: FontWeight.w500,
fontWeight: FontWeight.w600, ),
color: textAlign: TextAlign.center,
isDarkMode ? Colors.white : Colors.black, ),
), ),
textAlign: TextAlign.center, ],
overflow: TextOverflow.ellipsis,
),
),
//只在通话翻译模式下显示电话图标
if (controller.currentMode.value == 'call') ...[
SizedBox(width: 4.w),
Icon(
Icons.phone_in_talk,
size: 20.sp,
color: isDarkMode
? Colors.white70
: Colors.grey[600],
),
],
],
)),
),
), ),
), ],
], ],
), ),
), ),

Loading…
Cancel
Save