From 6366bf0ef1ff6d636852586c98bf8ce8294fb923 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 21 May 2025 19:58:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=AF=BC=E8=88=AA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/translations/language/zh_cn.dart | 6 + lib/modules/agent/views/message_bubble.dart | 132 ++++++++++-------- .../amap_service/NavigationActivity.kt | 3 +- 3 files changed, 80 insertions(+), 61 deletions(-) diff --git a/lib/core/translations/language/zh_cn.dart b/lib/core/translations/language/zh_cn.dart index 5a7b3b7d5..a67bac4f3 100644 --- a/lib/core/translations/language/zh_cn.dart +++ b/lib/core/translations/language/zh_cn.dart @@ -332,6 +332,12 @@ const Map zhCN = { "你好!我是 Emma,很高兴成为你的私人助理。我可以帮你处理各种任务,比如时间管理、目标规划、信息整理等。有什么我可以帮你的吗?", "personalAssistantVoiceWelcome": "我在呢!", + // 导航 + "driving": "驾车", + "walking": "步行", + "bicycling": "骑行", + "tsransit": "公交", + // 同声传译 Lucy "interpreterName": "同声传译", "interpreterDescription": diff --git a/lib/modules/agent/views/message_bubble.dart b/lib/modules/agent/views/message_bubble.dart index e2cae94cd..0d945fc65 100644 --- a/lib/modules/agent/views/message_bubble.dart +++ b/lib/modules/agent/views/message_bubble.dart @@ -284,6 +284,7 @@ class MessageBubble extends GetView { // 旅游 return _buildTravelContent(context, travellist); } else if (meta!.keys.contains('card_navigation')) { + final destination = meta!['card_navigation']['destination'] as String; final rawList = meta!['card_navigation']['items'] as List; final list = rawList.map((e) => Map.from(e)).toList(); final rawNavigation = meta!['card_navigation']['navigation']; @@ -291,7 +292,8 @@ class MessageBubble extends GetView { rawNavigation is Map ? rawNavigation : null; print("导航实时数据 ${rawNavigation}"); // 导航 - return navigationCard(context, modes: list, navigation: navigation); + return navigationCard(context, + destination: destination, modes: list, navigation: navigation); } // if (message.contains('播放列表') || message.contains('音乐')) { @@ -1173,8 +1175,37 @@ class MessageBubble extends GetView { return Icons.help_outline; } + String formatDistance(String distanceStr) { + final distance = double.tryParse(distanceStr); + if (distance == null) return distanceStr; // 如果无法解析,则返回原始字符串 + + if (distance >= 1000) { + final km = distance / 1000; + return '${km.toStringAsFixed(1)} 公里'; + } else { + return '${distance.toStringAsFixed(0)} 米'; + } + } + + String formatDuration(String secondsStr) { + int totalSeconds = int.tryParse(secondsStr) ?? 0; + Duration duration = Duration(seconds: totalSeconds); + + int hours = duration.inHours; + int minutes = duration.inMinutes.remainder(60); + int seconds = duration.inSeconds.remainder(60); + + List parts = []; + if (hours > 0) parts.add('$hours小时'); + if (minutes > 0) parts.add('$minutes分钟'); + if (seconds > 0 || parts.isEmpty) parts.add('$seconds秒'); + + return parts.join(''); + } + Widget navigationCard( BuildContext context, { + required String destination, required List> modes, Map? navigation, double height = 300, @@ -1224,16 +1255,22 @@ class MessageBubble extends GetView { children: List.generate(modes.length, (index) { final isSelected = index == currentIndex; return GestureDetector( - onTap: () { - setInnerState(() => currentIndex = index); - }, + onTap: modes[index]['enable'] as bool + ? () { + setInnerState(() => currentIndex = index); + } + : null, child: SizedBox( width: 50, child: Text( - modes[index]["ntype"] as String, + (modes[index]["ntype"] as String).tr, textAlign: TextAlign.center, style: TextStyle( - color: isSelected ? Colors.blue : Colors.black87, + color: modes[index]['enable'] + ? isSelected + ? Colors.blue + : Colors.black87 + : Colors.grey, fontSize: 12, fontWeight: FontWeight.w500, ), @@ -1250,64 +1287,39 @@ class MessageBubble extends GetView { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('距离:${modes[currentIndex]["distance"]}', - style: - const TextStyle(fontSize: 12, color: Colors.blue)), - IconButton( - icon: const Icon(Icons.turn_left, - color: Colors.blue, size: 20), - onPressed: () { - controller.openNavigation(); - }, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('$destination', + style: const TextStyle( + fontSize: 12, color: Colors.black)), + Text( + '${formatDistance(modes[currentIndex]["distance"])}-约${formatDuration(modes[currentIndex]["duration"])}', + style: const TextStyle( + fontSize: 15, color: Colors.blue)), + if (navigation != null) + Text( + "导航中... ${navigation["distanceText"]}进入${navigation["nextRoad"]}", + style: TextStyle( + fontSize: 12, + color: + const Color.fromARGB(255, 164, 164, 164))) + ], ), + CircleAvatar( + backgroundColor: Colors.blue, + radius: 18, + child: IconButton( + icon: const Icon(Icons.turn_left, + color: Colors.white, size: 20), + onPressed: () { + controller.openNavigation(); + }, + ), + ) ], ), ), - - // 导航实时数据显示 - if (navigation != null) - Padding( - padding: const EdgeInsets.all(8), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - // 圆形方向图标(如果有) - if (navigation["directionIcon"] != "") - Container( - width: 32, - height: 32, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: Colors.blue, - ), - child: ClipOval( - child: Image.memory( - base64Decode(navigation["directionIcon"]), - fit: BoxFit.cover, - ), - ), - ), - const SizedBox(width: 8), - // 文字信息 - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (navigation["currentRoad"] != null) - Text('当前道路:${navigation["currentRoad"]}', - style: const TextStyle(fontSize: 12)), - if (navigation["nextRoad"] != null) - Text('下一道路:${navigation["nextRoad"]}', - style: const TextStyle(fontSize: 12)), - if (navigation["distanceText"] != null) - Text('剩余距离:${navigation["distanceText"]}', - style: const TextStyle(fontSize: 12)), - ], - ), - ), - ], - ), - ), ], ); }, diff --git a/local_plugins/amap_service/android/src/main/kotlin/com/yunqiinnovation/amap_service/NavigationActivity.kt b/local_plugins/amap_service/android/src/main/kotlin/com/yunqiinnovation/amap_service/NavigationActivity.kt index 5ba631c52..0c2f8e5f0 100644 --- a/local_plugins/amap_service/android/src/main/kotlin/com/yunqiinnovation/amap_service/NavigationActivity.kt +++ b/local_plugins/amap_service/android/src/main/kotlin/com/yunqiinnovation/amap_service/NavigationActivity.kt @@ -212,12 +212,13 @@ class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewLi } override fun onNaviCancel() { + finish() // TODO("Not yet implemented") } override fun onNaviBackClick(): Boolean { // TODO("Not yet implemented") - return true + return false } override fun onNaviMapMode(p0: Int) {