From 16a625e5b8fef038750618c73cf7070c87025c61 Mon Sep 17 00:00:00 2001 From: yangyakun Date: Tue, 5 Aug 2025 19:58:46 +0800 Subject: [PATCH] =?UTF-8?q?[8.2.0]=20[ai]=20[=E6=B7=BB=E5=8A=A0title]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/ui/aiview/AIViewModel.kt | 57 ++++++++++++---- .../ui/aiview/adapter/AIMessageViewHolder.kt | 49 +++++++------- .../ui/aiview/bean/MGCommonTitleBean.kt | 4 ++ .../src/main/res/layout/item_ai_msg_qa.xml | 67 +++++++++++++------ core/mogo-core-utils/build.gradle | 2 +- 5 files changed, 122 insertions(+), 57 deletions(-) create mode 100644 OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/bean/MGCommonTitleBean.kt diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/AIViewModel.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/AIViewModel.kt index 742fad0566..a44fcf8155 100644 --- a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/AIViewModel.kt +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/AIViewModel.kt @@ -7,6 +7,7 @@ import com.mogo.eagle.core.data.BaseData import com.mogo.eagle.core.data.ai.V2XRepository import com.mogo.eagle.core.data.map.MogoLocation import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener +import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.mogo.och.unmanned.passenger.ui.aiview.bean.AIMessage import com.mogo.mgintelligent.speech.AsrResult import com.mogo.mgintelligent.speech.AsrState @@ -23,9 +24,12 @@ import com.mogo.och.data.taxi.BaseOrderBean import com.mogo.och.data.taxi.TaxiOrderStatusEnum import com.mogo.och.unmanned.passenger.bean.ai.LatLonBody import com.mogo.och.unmanned.passenger.network.ai.AiServiceManager +import com.mogo.och.unmanned.passenger.ui.aiview.bean.MGCommonTitleBean import com.mogo.och.unmanned.taxi.utils.order.OrderListener import com.mogo.och.unmanned.taxi.utils.order.OrderModel +import com.mogo.service.v2n.bean.MGEventExtInfoBean import com.mogo.service.v2n.bean.MGLlmQueryBean +import com.mogo.service.v2n.utils.JsonUtil import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -119,6 +123,8 @@ class AIViewModel : ViewModel(), AIMessageManager.AIMessageListener, IWakeUpList llmResultJob = viewModelScope.launch(Dispatchers.IO) { V2XRepository.llmResultFlow.collect { result -> Log.d(TAG, "llm result: $result") + val title = result.aiMsg?.title ?: "" + val suggestion = result.aiMsg?.suggestion ?: result.answer ?: "" val msg = msgList.findLast { it.id == result.queryId } @@ -127,18 +133,33 @@ class AIViewModel : ViewModel(), AIMessageManager.AIMessageListener, IWakeUpList return@collect } - AIMessageManager.post( - AIMessage.QA( - id = result.queryId, - title = result.answer, - tts = result.answer, - answer = result.answer, - question = msg.question, - state = AIMessage.QA.QuestionState.FINISH, - pictureUrl = result.imgUrls.getOrNull(0) ?: "", - pictureUrlList = result.imgUrls - ) - ) + if (result.aiMsg?.data != null) { + val data: MGCommonTitleBean? = result.aiMsg?.parseData() + val content = data?.title ?: "" + AIMessage.QA( + id = result.queryId, + title = title, + tts = content, + answer = content, + question = "", + pictureUrl = result.imgUrls.getOrNull(0) ?: "", + pictureUrlList = result.imgUrls, + ) + }else{ + AIMessageManager.post( + AIMessage.QA( + id = result.queryId, + title = result.answer, + tts = result.answer, + answer = suggestion, + question = msg.question, + state = AIMessage.QA.QuestionState.FINISH, + pictureUrl = result.imgUrls.getOrNull(0) ?: "", + pictureUrlList = result.imgUrls + ) + ) + } + } } } @@ -381,5 +402,17 @@ sealed class AsrUIState { data class Recognized(val finalText: String) : AsrUIState() } +inline fun MGEventExtInfoBean.parseData(): T? { + val TAG = "MGEventExtInfoBean" + return try { + JsonUtil.fromJson(this.data, T::class.java) + } catch (e: Exception) { + Log.e(TAG, "Failed parse data: ${e.message}") + null + } +} + + + diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/adapter/AIMessageViewHolder.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/adapter/AIMessageViewHolder.kt index 79c2f714f2..c9b82721e3 100644 --- a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/adapter/AIMessageViewHolder.kt +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/adapter/AIMessageViewHolder.kt @@ -14,6 +14,7 @@ import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.widget.AppCompatImageView +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.graphics.toColorInt import androidx.recyclerview.widget.LinearLayoutManager @@ -111,14 +112,14 @@ abstract class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) { class QAViewHolder(val binding: View) : MessageViewHolder(binding) { private var tvQuestion: TextView = binding.findViewById(R.id.tvQuestion) - private var tvAnswer: TextView = binding.findViewById(R.id.tvAnswer) + private var tvTitle: TextView = binding.findViewById(R.id.tvTitle) + private var tvTitleImage: TextView = binding.findViewById(R.id.tvTitleImage) + private var clContain: ConstraintLayout = binding.findViewById(R.id.clContain) private var tvTimestamp: TextView = binding.findViewById(R.id.tvTimestamp) private var tvStateContent: TextView = binding.findViewById(R.id.tvStateContent) + private var tvPncActionDesc: TextView = binding.findViewById(R.id.tvPncActionDesc) // private var ivPicture: OchRoundImageView = binding.findViewById(R.id.ivPicture) private var llState: LinearLayout = binding.findViewById(R.id.llState) - private var tvStateUnderstand: TextView = binding.findViewById(R.id.tvStateUnderstand) - private var tvStateAnalyze: TextView = binding.findViewById(R.id.tvStateAnalyze) - private var tvStateAnswer: TextView = binding.findViewById(R.id.tvStateAnswer) private var picBanner = binding.findViewById>(R.id.picBanner) @@ -128,9 +129,19 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) { handleState(item.state) tvQuestion.text = item.question Log.d(TAG, "bind: ${item}") - - tvAnswer.setTextAndVisibility(item.answer) -// ivPicture.showOrHideWithUrl(item.pictureUrl) + if(item.title==item.answer){ + tvTitle.text = item.title + tvPncActionDesc.text = item.answer + tvTitle.visibility = View.VISIBLE + tvPncActionDesc.visibility = View.GONE + tvTitleImage.visibility = View.VISIBLE + }else{ + tvTitle.text = item.title + tvPncActionDesc.text = item.answer + tvTitle.visibility = View.VISIBLE + tvPncActionDesc.visibility = View.VISIBLE + tvTitleImage.visibility = View.VISIBLE + } handleTimestamp(item, tvTimestamp) @@ -140,7 +151,6 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) { } else { picBanner.visibility = View.VISIBLE picBanner.setAdapter(BannerImageAdapter(pictureUrlList)) -// .addBannerLifecycleObserver(picBanner.context) //添加生命周期观察者 .setIndicator(CircleIndicator(picBanner.context)) .setIndicatorSelectedColor("#40B4FF".toColorInt()) .setIndicatorNormalColor("#FFFFFF".toColorInt()) @@ -154,43 +164,32 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) { when (state) { AIMessage.QA.QuestionState.UNDERSTAND -> { llState.visibility = View.VISIBLE + clContain.visibility = View.GONE tvStateContent.text = "正在理解问题…" - tvStateUnderstand.visibility = View.GONE - tvStateAnalyze.visibility = View.GONE - tvStateAnswer.visibility = View.GONE } AIMessage.QA.QuestionState.ANALYZE -> { - tvStateUnderstand.visibility = View.VISIBLE llState.visibility = View.VISIBLE + clContain.visibility = View.GONE tvStateContent.text = "正在分析处理…" - tvStateAnalyze.visibility = View.GONE - tvStateAnswer.visibility = View.GONE + } AIMessage.QA.QuestionState.ANSWER -> { - tvStateUnderstand.visibility = View.VISIBLE - tvStateAnalyze.visibility = View.VISIBLE llState.visibility = View.VISIBLE + clContain.visibility = View.GONE tvStateContent.text = "正在总结回答…" - tvStateAnswer.visibility = View.GONE } AIMessage.QA.QuestionState.FINISH -> { - tvStateUnderstand.visibility = View.VISIBLE - tvStateAnalyze.visibility = View.VISIBLE - tvStateAnswer.visibility = View.VISIBLE - llState.visibility = View.GONE + clContain.visibility = View.VISIBLE tvStateContent.text = "" } AIMessage.QA.QuestionState.ERROR -> { - tvStateUnderstand.visibility = View.VISIBLE - tvStateAnalyze.visibility = View.VISIBLE - tvStateAnswer.visibility = View.VISIBLE - + clContain.visibility = View.VISIBLE llState.visibility = View.GONE tvStateContent.text = "" } diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/bean/MGCommonTitleBean.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/bean/MGCommonTitleBean.kt new file mode 100644 index 0000000000..aab20bad23 --- /dev/null +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/aiview/bean/MGCommonTitleBean.kt @@ -0,0 +1,4 @@ +package com.mogo.och.unmanned.passenger.ui.aiview.bean +data class MGCommonTitleBean( + val title: String = "", +) \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/res/layout/item_ai_msg_qa.xml b/OCH/taxi/unmanned-passenger/src/main/res/layout/item_ai_msg_qa.xml index 211cd007fb..7a34262925 100644 --- a/OCH/taxi/unmanned-passenger/src/main/res/layout/item_ai_msg_qa.xml +++ b/OCH/taxi/unmanned-passenger/src/main/res/layout/item_ai_msg_qa.xml @@ -42,21 +42,6 @@ android:orientation="vertical" android:padding="31dp"> - - - - - - + + + + + + + + + -