From 66ec854a69bfc8cd24ad011255813335fd5f2996 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 19 Mar 2025 11:14:33 +0800 Subject: [PATCH] =?utf8?q?AI=E5=A4=A7=E6=A8=A1=E5=9E=8B=E4=BC=98=E5=8C=96?= =?utf8?q?=EF=BC=9A=201.=E8=A7=A3=E5=86=B3Ai=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?utf8?q?=E9=97=AE=E9=A2=98=E6=8B=BC=E6=8E=A5=E9=97=AE=E9=A2=98=202.?= =?utf8?q?=E8=A7=A3=E5=86=B3AI=E5=A4=A7=E6=A8=A1=E5=9E=8B=E5=9C=A8?= =?utf8?q?=E5=9B=9E=E9=95=BF=E5=86=85=E5=AE=B9=E6=89=8B=E8=A1=A8=E6=98=BE?= =?utf8?q?=E7=A4=BA=E5=88=B0=E6=9E=81=E9=99=90=E6=97=B6=E6=A6=82=E7=8E=87?= =?utf8?q?=E5=87=BA=E7=8E=B0=E7=AD=94=E6=A1=88=E6=B6=88=E5=A4=B1=E9=97=AE?= =?utf8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 10 +++- .../nativeui/aivoice/src/AiVoiceModel.cpp | 58 +++++++++++++++++-- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 11 +++- .../src/AivoiceChatContentListItemView.cpp | 9 ++- 4 files changed, 79 insertions(+), 9 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index 6a393a3b3..f45155f05 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-13 16:02:18 + * @LastEditTime: 2025-03-19 09:44:14 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h */ #ifndef AI_VOICE_MODEL_H @@ -112,6 +112,12 @@ namespace OHOS bool CreateDirectory(const char* path); + void SetIsClickable(bool value); + bool GetIsClickable(void); + + void SetIsLimitDisplayed(bool value); + bool GetIsLimitDisplayed(void); + private: AiVoiceModel(); ~AiVoiceModel(); @@ -137,6 +143,8 @@ namespace OHOS uint8_t AIResponseType; std::string errnote; //错误信息 int16_t curView{0}; + bool isClickable{false}; + bool isLimitDisplayed{false};//AI答案是否显示到极限了 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index 110c808e8..41216d698 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-14 09:43:46 + * @LastEditTime: 2025-03-19 11:09:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -32,7 +32,7 @@ namespace OHOS { // 声明定时器变量 static osTimerId_t g_timer = nullptr; - static constexpr uint16_t THIRTY_TIME = 30; + static constexpr uint16_t THIRTY_TIME = 30 / 3; static int Time = THIRTY_TIME; static int AiModelConnectTimeout = 5; @@ -387,6 +387,23 @@ namespace OHOS bool AiVoiceModel::UpdateAiAnswerStr() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateAiAnswerStr"); + #if 0 + AiVoiceView *view_ = AiVoiceView::GetInstance(); + if(view_!= nullptr ) + { + if(view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && !view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()) + { + return false; + } + else + { + if(!GetIsClickable()) + { + SetIsClickable(true); + } + } + } + #endif int index = GetChatContentListCount() - 1; if (index < 0 || index >= MaxChatContentListCount) @@ -438,6 +455,25 @@ namespace OHOS return true; } + void AiVoiceModel::SetIsClickable(bool value) + { + isClickable = value; + } + + bool AiVoiceModel::GetIsClickable(void) + { + return isClickable; + } + + void AiVoiceModel::SetIsLimitDisplayed(bool value) + { + isLimitDisplayed = value; + } + bool AiVoiceModel::GetIsLimitDisplayed(void) + { + return isLimitDisplayed; + } + /*获取用户问题的字符串*/ std::string AiVoiceModel::GetUserQuestionStr(void) { @@ -501,9 +537,19 @@ namespace OHOS return; } } - aiAnswerStr += str; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str()); - SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); + AiVoiceView *view_ = AiVoiceView::GetInstance(); + if(view_!= nullptr ) + { + if(view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()) + { + if(!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) //如果ai答案没有显示到极限了,就更新ai答案字符串 + { + aiAnswerStr += str; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str()); + SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); + } + } + } } /*清空上次用户问题和Ai回答字符串*/ @@ -652,6 +698,8 @@ namespace OHOS } ChatContentListCount = 0; entryTextViewState = false; + isClickable = false; + isLimitDisplayed = false; ClearQuestionAndAiAnswerStr(); StopListenAndRecordingUserQuestion(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index d22a5c106..233dbeb8b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-13 11:52:43 + * @LastEditTime: 2025-03-19 10:24:14 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -264,6 +264,8 @@ namespace OHOS case AIVOICE_RETURN_RESULT_TEXT_VIEWID: AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串 + AiVoiceModel::GetInstance().SetIsClickable(false); + AiVoiceModel::GetInstance().SetIsLimitDisplayed(false); if (showView == AIVOICE_LISTENING_VIEWID) { model->StartListenAndRecordingUserQuestion(); @@ -316,6 +318,13 @@ namespace OHOS auto it = viewIdMap.find(viewId); if (it != viewIdMap.end()) { + #if 0 + if(!model->GetIsClickable()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "当前还不可点击"); + return true; + } + #endif if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp index 0e83e34c2..a5b9590c7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp @@ -2,11 +2,12 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-29 17:27:25 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-28 15:54:29 + * @LastEditTime: 2025-03-19 10:12:45 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp */ #include "aivoice/include/AivoiceChatContentListItemView.h" +#include "aivoice/include/AiVoiceModel.h" #include "wearable_log.h" namespace OHOS @@ -87,7 +88,11 @@ namespace OHOS } else { - chatContentLabel.SetLineBreakMode(isAiAnswerFlag ? UILabel::LINE_BREAK_ELLIPSIS : UILabel::LINE_BREAK_WRAP);//超过高度在末尾用省略号替换 + if(!AiVoiceModel::GetInstance().GetIsLimitDisplayed()) + { + AiVoiceModel::GetInstance().SetIsLimitDisplayed(true); + chatContentLabel.SetLineBreakMode(isAiAnswerFlag ? UILabel::LINE_BREAK_ELLIPSIS : UILabel::LINE_BREAK_WRAP);//超过高度在末尾用省略号替换 + } } } -- 2.17.1