From c90e52a01a6e11493096b4357f43bb30b9d9451c Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 23 Oct 2024 15:07:47 +0800 Subject: [PATCH] =?utf8?q?=E5=AE=9E=E7=8E=B0AI=E7=AD=94=E6=A1=88=E6=81=A2?= =?utf8?q?=E5=A4=8D=EF=BC=8C=E5=88=97=E8=A1=A8=E5=90=8C=E6=AD=A5=E6=BB=9A?= =?utf8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../aivoice/include/AiVoicePresenter.h | 11 ++++- .../nativeui/aivoice/src/AiVoiceModel.cpp | 8 ++-- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 48 +++++++++++++++++-- .../src/AivoiceReturnResultTextView.cpp | 6 +-- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h index 8768583ce..60257671e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 14:44:22 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:13:42 + * @LastEditTime: 2024-10-23 11:22:25 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h */ #ifndef AI_VOICE_PRESENTER_H @@ -12,6 +12,7 @@ #include "View.h" #include "ui_resource_string.h" #include "components/ui_time_picker.h" +#include "ModelListenerSample.h" namespace OHOS { class AiVoiceView; @@ -21,7 +22,8 @@ namespace OHOS public UIView::OnDragListener, public RootView::OnKeyActListener, public UIPicker::SelectedListener, - public UIView::OnTouchListener + public UIView::OnTouchListener, + public ModelListenerSample { public: typedef enum : uint8_t @@ -42,6 +44,8 @@ namespace OHOS void OnResume() override; void OnPause() override; void OnStop() override; + void Notify() override; + void calculateChatContentItemViewHeight(std::string text, bool flag); bool JumpToReturnResultTextView(void); bool ChangeToAIVoiceListeningView(bool val); @@ -61,6 +65,9 @@ namespace OHOS AiVoiceModel *model; bool X_DRAG_FLAG{false}; + + int preHeight{0}; + bool isScroll{false}; }; } 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 e16011c69..35c847da1 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: 2024-10-22 17:30:40 + * @LastEditTime: 2024-10-23 14:19:17 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -408,6 +408,8 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetChatContentListCount() - 1 = %d,line = %d", GetChatContentListCount() - 1, __LINE__); // 将更新后的 AI 回答内容添加到列表 adapter->GetChatContentItem().push_back(chatTtems[GetChatContentListCount() - 1]); + if (AiVoicePresenter::GetInstance()) + AiVoicePresenter::GetInstance()->calculateChatContentItemViewHeight(chatTtems[GetChatContentListCount() - 1].text, true); p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList(); } else @@ -785,7 +787,7 @@ namespace OHOS void AiVoiceModel::reset_ai_screen60s_timer_time() { SCREEN_60S_TIME = 60; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d",SCREEN_60S_TIME); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d", SCREEN_60S_TIME); if (nullptr == g_screen60s_timer) { ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 重新常亮屏 @@ -878,7 +880,7 @@ namespace OHOS } static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器 - static uint8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时 + static uint8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时 static void AI_IS_READY_CallbackProc(int data) { if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时 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 029b81357..998281a51 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: 2024-10-21 18:35:53 + * @LastEditTime: 2024-10-23 15:07:12 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -102,8 +102,10 @@ namespace OHOS bool AiVoicePresenter::JumpToReturnResultTextView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView"); - if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible()) + if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr && + view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible()) { + preHeight = 0; ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID); } else @@ -263,8 +265,8 @@ namespace OHOS { UNUSED(event); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnClick"); - - model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer + + model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer if (strcmp(view.GetViewId(), AIVOICE_IMGAE_VIEW_ID) == 0) /*点击的是Ai模型就切换模型*/ { @@ -478,4 +480,42 @@ namespace OHOS model->SetSelectAiModel(picker.GetSelected()); view_->ChangeAiModelAndUpdateComponentsStatus(); } + + // 计算聊天内容ItemView的高度 + void AiVoicePresenter::calculateChatContentItemViewHeight(std::string text, bool flag) + { + const char *Text = text.c_str(); + UILabel label; + label.SetPosition(53, 100); + label.Resize(flag ? 280 : 200, 60); + label.SetStyle(STYLE_TEXT_FONT, 26); + label.SetStyle(STYLE_LINE_HEIGHT, 30); + label.SetText(Text); + label.SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 26); + + if (label.GetTextHeight() > preHeight) + { + preHeight = label.GetTextHeight(); + isScroll = true; + } + return; + } + + //监听高度是否变化 + void AiVoicePresenter::Notify() + { + if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) && + (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())) + { + if (isScroll) + { + // 监听,让List实现滚动 + AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-150); + isScroll = false; + } + } + return; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp index cfdc9a80a..b585e2dc5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-01 10:12:28 + * @LastEditTime: 2024-10-23 14:58:03 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -248,13 +248,13 @@ namespace OHOS chatContentList->SetTouchable(true); chatContentList->SetDraggable(true); chatContentList->SetThrowDrag(true); - chatContentList->SetReboundSize(REBOUNDSIZE); + // chatContentList->SetReboundSize(REBOUNDSIZE); chatContentList->SetMaxScrollDistance(MAX_SCR_DIS); chatContentList->SetSwipeACCLevel(800); // 800: compensation distance chatContentList->SetDragACCLevel(5); // 5: drag acceleration chatContentList->SetRotateFactor(2); chatContentList->RequestFocus(); - chatContentList->SetIntercept(true); + // chatContentList->SetIntercept(true); chatContentList->SetAdapter(chatContentListAdapter); chatContentList->RefreshList(); /* -------------------------------------------------------------------------- */ -- 2.17.1