From 9e21b5c0a9295ed2d9de8514635ae308f2c14483 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 31 Jul 2024 17:09:43 +0800 Subject: [PATCH] =?utf8?q?AI=E8=AF=AD=E9=9F=B3=E7=95=8C=E9=9D=A2=E5=B7=B2?= =?utf8?q?=E7=BB=8F=E5=AE=8C=E6=88=90=EF=BC=8C=E4=B8=8B=E4=B8=80=E6=AD=A5?= =?utf8?q?=E9=9C=80=E8=A6=81=E8=81=94=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/AiVoiceBluetoothFailedStartView.h | 5 +- .../nativeui/aivoice/include/AiVoiceModel.h | 6 +- .../nativeui/aivoice/include/AiVoiceView.h | 22 +-- .../AivoiceMobileDataFailedStartView.h | 5 +- .../include/AivoiceReturnResultTextView.h | 7 +- .../aivoice/include/AivoiceThinkingView.h | 4 +- .../src/AiVoiceBluetoothFailedStartView.cpp | 34 +++- .../nativeui/aivoice/src/AiVoiceModel.cpp | 70 +++---- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 187 +++++------------- .../nativeui/aivoice/src/AiVoiceView.cpp | 26 ++- .../src/AivoiceMobileDataFailedStartView.cpp | 26 ++- .../src/AivoiceReturnResultTextView.cpp | 11 +- 12 files changed, 182 insertions(+), 221 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h index 141f15b55..aedba05fa 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-21 17:07:07 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-22 16:59:20 + * @LastEditTime: 2024-07-31 14:16:00 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h */ @@ -16,7 +16,7 @@ namespace OHOS { - static constexpr const char *BLUETOOTHFAILEDSTART_ENSURE_BUTTON_VIEW_ID = "BluetoothFailedStartEnsureButton";//蓝牙未开启界面的确定按钮 + static constexpr const char *ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID = "AppBluetoothAnd4gNetworkEnsureButton";//APP蓝牙与4G网络都连接异常界面的确定按钮 class AiVoiceBluetoothFailedStartView { @@ -53,6 +53,7 @@ namespace OHOS ~AiVoiceBluetoothFailedStartView(); static AiVoiceBluetoothFailedStartView *GetInstance(void); UIScrollView *CreateAiVoiceBluetoothFailedStartView(void); + void UpdateTitleTextId(int textId); private: void ClearAll(void); 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 6c9b822f0..a0279934a 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: 2024-07-30 15:47:01 + * @LastEditTime: 2024-07-31 16:53:36 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h */ #ifndef AI_VOICE_MODEL_H @@ -13,6 +13,7 @@ #include "iostream" #include "string" #include "ChatContentItem.h" +#include "map" #define AIAUDIO_TYPE_PCM 0 #define AIAUDIO_TYPE_SBC 1 #define AIAUDIO_TYPE_MSBC 2 @@ -34,7 +35,7 @@ namespace OHOS bool IsExistOpenAIAPIKeys(); void DeleteLocalOpenAIAPIKeys(); - bool GetBluetoothIsOpen(void); + bool GetAPPBluetoothIsConnect(void); bool GetMobileDataIsOpen(void); bool GetAiVoiceConnectStatus(void); @@ -98,6 +99,7 @@ namespace OHOS static const uint16_t MaxChatContentListCount = 2; // 对话列表最大数量 ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组 bool entryTextViewState{false}; // 进入返回结果界面的标志 + std::map> selectAiModelToTextId; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h index 7bf57cc9f..fcd5ab3fc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-08 09:36:01 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:05:40 + * @LastEditTime: 2024-07-30 20:24:56 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h */ #ifndef AI_VOICE_VIEW_H @@ -45,16 +45,16 @@ namespace OHOS typedef enum { - AIVOICE_STARTCHAT_VIEWID = 0, // 开始对话界面 - AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID, // 蓝牙未开启界面 - AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID, // 移动数据未开启界面 - AIVOICE_CONNECT_TIMEOUT_VIEWID, // 连接超时界面 - AIVOICE_LISTENING_VIEWID, // 聆听中界面 - AIVOICE_THINKING_VIEWID, // 思考中界面 - AIVOICE_RETURN_RESULT_TEXT_VIEWID, // 返回结果文本界面 - AIVOICE_SETAPIKEYS, // API Keys set界面 - AIVOICE_NOTSETAPIKEYS, // API Keys notset界面 - AIVOICE_APIKEYS_DELETE, // API Keys 删除界面 + AIVOICE_STARTCHAT_VIEWID = 0, // 开始对话界面 + AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, // APP蓝牙与4G网络都连接异常界面 + AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, // 模型连接失败弹窗界面 + AIVOICE_CONNECT_TIMEOUT_VIEWID, // 连接超时界面 + AIVOICE_LISTENING_VIEWID, // 聆听中界面 + AIVOICE_THINKING_VIEWID, // 思考中界面 + AIVOICE_RETURN_RESULT_TEXT_VIEWID, // 返回结果文本界面 + AIVOICE_SETAPIKEYS, // API Keys set界面 + AIVOICE_NOTSETAPIKEYS, // API Keys notset界面 + AIVOICE_APIKEYS_DELETE, // API Keys 删除界面 MAX_AIVOICE_VIEWID, } AIVOICEVIEWID; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h index 8a1c056aa..442903d1b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-22 15:22:56 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-22 16:59:59 + * @LastEditTime: 2024-07-31 15:08:31 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h */ @@ -16,7 +16,7 @@ namespace OHOS { - static constexpr const char *MOBILEDATAFAILEDSTART_ENSURE_BUTTON_VIEW_ID = "MobiledatafailedStartEnsureButton"; // 移动数据未开启界面的确定按钮 + static constexpr const char *AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID = "AimodelConnectFailedEnsureButton_"; // 模型连接失败弹窗界面的确定按钮 class AivoiceMobileDataFailedStartView { @@ -53,6 +53,7 @@ namespace OHOS ~AivoiceMobileDataFailedStartView(); static AivoiceMobileDataFailedStartView *GetInstance(void); UIScrollView *CreateAivoiceMobileDataFailedStartView(void); + void UpdateTitleTextId(int textId); private: void ClearAll(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h index 63c11c0f5..6e67ed523 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-22 16:46:26 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-01 14:22:24 + * @LastEditTime: 2024-07-31 11:45:08 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h */ @@ -56,8 +56,9 @@ namespace OHOS static AivoiceReturnResultTextView *GetInstance(void); UIScrollView *CreateAivoiceReturnResultTextView(void); void AddChatContentToList(const ChatContentItem &item); - AivoiceChatContentListAdapter* GetAivoiceChatContentListAdapter(void); - UIList* GetChatContentList(void); + AivoiceChatContentListAdapter *GetAivoiceChatContentListAdapter(void); + UIList *GetChatContentList(void); + void UpdateTitleTextId(int textId); private: void ClearAll(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h index 8d6b50c2b..93a223ee2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-22 16:46:26 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-01 17:20:11 + * @LastEditTime: 2024-07-31 11:33:33 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h */ @@ -16,7 +16,7 @@ #include "components/ui_image_animator.h" namespace OHOS { - static constexpr const char *CANCEL_THINKING_BUTTON_VIEW_ID = "CancelThinkingButton"; // 思考中界面说话完毕按钮 + static constexpr const char *CANCEL_THINKING_BUTTON_VIEW_ID = "CancelThinkingButton"; // 思考中界面取消按钮 static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_X = 153; static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_Y = 120; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp index e8d7e54be..126a1af5b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp @@ -2,10 +2,11 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:08:31 + * @LastEditTime: 2024-07-31 15:01:20 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceBluetoothFailedStartView.cpp */ #include "aivoice/include/AiVoicePresenter.h" +#include "aivoice/include/AiVoiceModel.h" #include "aivoice/include/AiVoiceBluetoothFailedStartView.h" #include "wearable_log.h" #include "ui_resource_string.h" @@ -135,7 +136,13 @@ namespace OHOS scrollView->SetPosition(0, 0, 466, 466); scrollView->SetTouchable(true); scrollView->SetDraggable(true); - + UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::dragListener new fail!"); + return false; + } + scrollView->SetOnDragListener(dragListener); return true; } @@ -149,7 +156,7 @@ namespace OHOS .height = 35, .fontSize = 30, .lineHeigh = 35, - .textId = STR_AI_INTELLIGENT_ASSISTANT, + .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; title = AiVoiceBluetoothFailedStartLabelInit(labelconfig); @@ -161,10 +168,10 @@ namespace OHOS /* -------------------------------------------------------------------------- */ labelconfig.left = 53; labelconfig.width = 360; - int textId[] = {STR_BOOT_FAILED, STR_ENABLE_BLUETOOTH_FIRST}; + int textId[] = {STR_BOOT_FAILED, STR_PCY4GC_OR_AS}; /*启动失败,请检查4G或打开APP连接*/ for (int i = 0; i < sizeof(textId) / sizeof(textId[0]); i++) { - labelconfig.top = 222 + i * labelconfig.height; + labelconfig.top = 222 + i * 35; labelconfig.textId = textId[i]; label[i] = AiVoiceBluetoothFailedStartLabelInit(labelconfig); if (label[i] == nullptr) @@ -202,7 +209,7 @@ namespace OHOS .y = 340, .w = 280, .h = 90, - .ViewId = BLUETOOTHFAILEDSTART_ENSURE_BUTTON_VIEW_ID, + .ViewId = ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID, }; ensureButton = AiVoiceBluetoothFailedStartButtonInit(buttonconfig); if (ensureButton == nullptr) @@ -210,13 +217,13 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ensureButton new fail!"); return false; } - UIView::OnClickListener *clickListener = static_cast(AiVoicePresenter::GetInstance()); - if (clickListener == nullptr) + UIView::OnTouchListener *onReleaseListener = static_cast(AiVoicePresenter::GetInstance()); + if (onReleaseListener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::draglistener can not be nullptr!"); return false; } - ensureButton->SetOnClickListener(clickListener); + ensureButton->SetOnTouchListener(onReleaseListener); return true; } @@ -263,4 +270,13 @@ namespace OHOS return scrollView; } + void AiVoiceBluetoothFailedStartView::UpdateTitleTextId(int textId) + { + if (title) + { + title->SetTextId(textId); + title->ForceResetText(); + } + } + } \ No newline at end of file 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 8b3358543..61437d761 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-07-30 18:33:12 + * @LastEditTime: 2024-07-31 16:57:44 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -23,6 +23,7 @@ #include #include #include "ConfigModel.h" +#include "settings/include/SettingModel.h" namespace OHOS { // 声明定时器变量 @@ -102,16 +103,16 @@ namespace OHOS ConfigModel::GetInstance()->SetOpenAIAPIKeys("-1"); } - // 获取蓝牙是否打开 - bool AiVoiceModel::GetBluetoothIsOpen(void) + // 获取APP蓝牙是否已连接 + bool AiVoiceModel::GetAPPBluetoothIsConnect(void) { - return true; + return SettingModel::GetInstance().GetPhoneConnectStatus(); } - // 获取移动数据是否打开 + // 获取4G网络是否正常 bool AiVoiceModel::GetMobileDataIsOpen(void) { - return true; + return false; } // 获取与AI模型的连接状态 @@ -473,7 +474,13 @@ namespace OHOS fseek(file, 0, SEEK_SET); if (size != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "size = %ld", size); + auto it = selectAiModelToTextId.find(GetSelectAiModel()); + if (it != selectAiModelToTextId.end()) + { + size, it->second.second; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second); + send_AI_is_ready(0); ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串 } @@ -526,33 +533,19 @@ namespace OHOS } if (Time < 0) // 如果思考时间超时30s,进入连接超时界面 { + AiVoiceModel::GetInstance().AIVoice_StopTimer(); + AiVoiceView *view_ = AiVoiceView::GetInstance(); - if (view_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::GetInstance fail!!"); - AiVoiceModel::GetInstance().AIVoice_StopTimer(); - return; - } AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance(); - if (p_AiVoicePresenter == nullptr) + if (view_ != nullptr && p_AiVoicePresenter != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::GetInstance fail!!"); - AiVoiceModel::GetInstance().AIVoice_StopTimer(); - return; - } - bool flag = false; - if ((view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())) - { - p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID); - flag = true; - } - if (!flag) - { - AiVoiceModel::GetInstance().AIVoice_StopTimer(); + if ((view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr) && + (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())) + { + p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID); + } } } - return; } @@ -642,24 +635,23 @@ namespace OHOS int language = ConfigModel::GetInstance()->GetLanguage(); int textId; - std::map selectAiModelToTextId; if (language == 0) { selectAiModelToTextId = { - {0, STR_AIMODES_WENXINYIYAN}, - {1, STR_AIMODES_KIMI}, - {2, STR_AIMODELS_DOUBAO}, - {3, STR_AIMODES_CHATGPT}, + {0, {STR_AIMODES_WENXINYIYAN, 0}}, + {1, {STR_AIMODES_KIMI, 2}}, + {2, {STR_AIMODELS_DOUBAO, 3}}, + {3, {STR_AIMODES_CHATGPT, 1}}, }; textId = STR_AIMODES_WENXINYIYAN; } else { selectAiModelToTextId = { - {0, STR_AIMODES_CHATGPT}, - {1, STR_AIMODES_WENXINYIYAN}, - {2, STR_AIMODES_KIMI}, - {3, STR_AIMODELS_DOUBAO}, + {0, {STR_AIMODES_CHATGPT, 1}}, + {1, {STR_AIMODES_WENXINYIYAN, 0}}, + {2, {STR_AIMODES_KIMI, 2}}, + {3, {STR_AIMODELS_DOUBAO, 3}}, }; textId = STR_AIMODES_CHATGPT; } @@ -668,7 +660,7 @@ namespace OHOS auto it = selectAiModelToTextId.find(GetSelectAiModel()); if (it != selectAiModelToTextId.end()) { - return it->second; + return it->second.first; } return textId; 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 f72dfe7cb..0cfa13ee9 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-07-30 18:35:35 + * @LastEditTime: 2024-07-31 16:14:11 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -91,7 +91,7 @@ namespace OHOS /*调转到返回结果界面*/ bool AiVoicePresenter::JumpToReturnResultTextView(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView"); if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible()) { // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID); // 思考中界面->返回结果 @@ -105,101 +105,9 @@ namespace OHOS return true; } -#if 0 - /*切换视图的逻辑操作*/ bool AiVoicePresenter::ChangeViewAndLogicOperator(int16_t hideView, int16_t showView) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeViewOperator"); - if (hideView > MAX_AIVOICE_VIEWID) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Overstep ones bounds"); - return false; - } - if (hideView == AIVOICE_STARTCHAT_VIEWID && showView == AIVOICE_LISTENING_VIEWID) // 开始对话->聆听中界面 - { - view_->ChangeView(hideView, showView); - // 开始聆听并录取用户问题 - model->StartListenAndRecordingUserQuestion(); - } - else if (hideView == AIVOICE_LISTENING_VIEWID && showView == AIVOICE_THINKING_VIEWID) // 聆听中->思考中界面 - { - // 停止聆听用户问题 - model->StopListenAndRecordingUserQuestion(); - model->CheckFileAndSendAIIsReady(); - view_->ChangeView(hideView, showView); - // 在思考中界面开启定时器 - model->AIVoice_StartTimer(); - } - else if (hideView == AIVOICE_LISTENING_VIEWID && showView == AIVOICE_STARTCHAT_VIEWID) // 聆听中->开始对话界面 - { - view_->ChangeView(hideView, showView); - // 停止聆听用户问题 - model->StopListenAndRecordingUserQuestion(); - } - else if (hideView == AIVOICE_THINKING_VIEWID && showView == AIVOICE_CONNECT_TIMEOUT_VIEWID) // 思考中->连接超时界面 - { - // 停止定时器 - model->AIVoice_StopTimer(); - // 设置进入超时界面的标志 - model->SetEntryTimeoutFlag(true); - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_THINKING_VIEWID && showView == AIVOICE_RETURN_RESULT_TEXT_VIEWID) // 思考中->返回结果文本界面 - { - // 停止定时器 - model->AIVoice_StopTimer(); - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_THINKING_VIEWID && showView == AIVOICE_LISTENING_VIEWID) // 思考中->聆听中界面 - { - // 停止定时器 - model->AIVoice_StopTimer(); - view_->ChangeView(hideView, showView); - // 开始聆听并录取用户问题 - model->StartListenAndRecordingUserQuestion(); - } - else if (hideView == AIVOICE_CONNECT_TIMEOUT_VIEWID && showView == AIVOICE_LISTENING_VIEWID) // 连接超时界面->聆听中界面 - { - bool flag = model->GetEntryTimeoutFlag(); - if (flag) - { - model->StartListenAndRecordingUserQuestion(); // 重新开始录音 - } - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_THINKING_VIEWID && showView == AIVOICE_STARTCHAT_VIEWID) // 思考中界面->开始对话界面 - { - // 停止定时器 - model->AIVoice_StopTimer(); - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_STARTCHAT_VIEWID && showView == AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID) // 开始对话->移动数据未开启界面 - { - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID && showView == AIVOICE_STARTCHAT_VIEWID) // 蓝牙未开启界面->开始对话界面 - { - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID && showView == AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID) // 移动数据未开启界面->开始对话界面 - { - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_RETURN_RESULT_TEXT_VIEWID && showView == AIVOICE_STARTCHAT_VIEWID) // 返回结果文本界面->开始对话界面 - { - view_->ChangeView(hideView, showView); - } - else if (hideView == AIVOICE_RETURN_RESULT_TEXT_VIEWID && showView == AIVOICE_LISTENING_VIEWID) // 返回结果文本界面->聆听中界面 - { - model->StartListenAndRecordingUserQuestion(); // 重新开始录音 - view_->ChangeView(hideView, showView); - } - return true; - } -#else - bool AiVoicePresenter::ChangeViewAndLogicOperator(int16_t hideView, int16_t showView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeViewOperator"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeViewOperator"); if (hideView > MAX_AIVOICE_VIEWID) { @@ -226,37 +134,14 @@ namespace OHOS // model->CheckFileAndSendAIIsReady(); model->AIVoice_StartTimer(); } - else if (showView == AIVOICE_STARTCHAT_VIEWID) // 聆听中->开始对话界面:(右滑不想录音了) - { - // No additional actions needed - } break; case AIVOICE_THINKING_VIEWID: model->AIVoice_StopTimer(); - if (showView == AIVOICE_CONNECT_TIMEOUT_VIEWID) // 思考中界面->连接超时界面 - { - model->SetEntryTimeoutFlag(true); - } - else if (showView == AIVOICE_RETURN_RESULT_TEXT_VIEWID) // 思考中界面->返回结果文本界面 - { - // No additional actions needed - } - else if (showView == AIVOICE_LISTENING_VIEWID) // 思考中界面->聆听中界面 - { - model->StartListenAndRecordingUserQuestion(); - } break; - case AIVOICE_CONNECT_TIMEOUT_VIEWID: - if (showView == AIVOICE_LISTENING_VIEWID && model->GetEntryTimeoutFlag()) // 连接超时界面->聆听中界面 - { - model->SetEntryTimeoutFlag(false); - model->StartListenAndRecordingUserQuestion(); - } - break; case AIVOICE_RETURN_RESULT_TEXT_VIEWID: - if (showView == AIVOICE_LISTENING_VIEWID) // 连接超时界面->聆听中界面 + if (showView == AIVOICE_LISTENING_VIEWID) { model->StartListenAndRecordingUserQuestion(); } @@ -269,7 +154,6 @@ namespace OHOS return true; } -#endif bool AiVoicePresenter::OnClick(UIView &view, const ClickEvent &event) { @@ -324,30 +208,44 @@ namespace OHOS * 3.只有与APP蓝牙连接正常 -> 通过蓝牙连接APP调用大模型 * 4.两者连接都异常 -> 返回错误 */ - bool state = model->GetBluetoothIsOpen(); - (state == false) - ? ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID) - : ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID); + bool netWork4GState = model->GetMobileDataIsOpen(); + bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect(); + + if (netWork4GState && appBluetoothConnectState) // 1.当手表4G网络正常+与app连接正常 + { + // 通过4G调用大模型 + } + else if (netWork4GState && !appBluetoothConnectState) // 2.只有手表4G网络正常 + { + // 通过4G调用大模型 + } + else if (!netWork4GState && appBluetoothConnectState) // 3.只有与APP蓝牙连接正常 + { + // 通过蓝牙连接APP调用大模型 + ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID); + } + else if (!netWork4GState && !appBluetoothConnectState) // 4.两者连接都异常 + { + // 返回错误 + ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID); + // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); + } return true; } - - if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮 + else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮 { - bool state = model->GetAiVoiceConnectStatus(); - (state == false) - ? ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID) - : ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); + ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); return true; } std::unordered_map> viewIdMap = { - {BLUETOOTHFAILEDSTART_ENSURE_BUTTON_VIEW_ID, {AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {MOBILEDATAFAILEDSTART_ENSURE_BUTTON_VIEW_ID, {AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID, {AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听 - {CANCEL_THINKING_BUTTON_VIEW_ID, {AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录 - {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录 + {ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID, {AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 + {AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID, {AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 + {AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID, {AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 + {CANCEL_THINKING_BUTTON_VIEW_ID, {AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 + {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录 + {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录 }; auto it = viewIdMap.find(viewId); if (it != viewIdMap.end()) @@ -388,21 +286,32 @@ namespace OHOS { if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)) { + /*AI对话界面右滑退出当前Slice*/ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } + else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID)) + { + /*APP蓝牙与4G网络都连接异常界面右滑退回到开始对话界面*/ + ChangeViewAndLogicOperator(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, AIVOICE_STARTCHAT_VIEWID); + } + else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID)) + { + /*模型连接失败弹窗界面右滑退回到开始对话界面*/ + ChangeViewAndLogicOperator(AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, AIVOICE_STARTCHAT_VIEWID); + } else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)) { - // view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 聆听中->开始对话界面 + /*聆听中界面右滑退回到AI对话界面*/ ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID); } else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)) { - // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 思考中->开始对话界面 + /*思考中界面右滑退到AI对话界面*/ ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); } else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_CONNECT_TIMEOUT_VIEWID)) { - // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 连接超时->开始对话界面 + /*连接超时界面右滑退到AI对话界面*/ ChangeViewAndLogicOperator(AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID); } AiVoicePresenter::X_DRAG_FLAG = false; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp index 6b4fd6d38..118bd425a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 17:23:59 + * @LastEditTime: 2024-07-31 14:42:25 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -475,7 +475,7 @@ namespace OHOS return true; } - /*切换到蓝牙未开启界面*/ + /*切换到APP蓝牙或4G网络未连接界面界面*/ bool AiVoiceView::ChangeAiVoiceBluetoothFailedStartView(int16_t thisView) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoiceBluetoothFailedStartView"); @@ -493,7 +493,7 @@ namespace OHOS return true; } - /*切换到移动数据未开启界面*/ + /*切换到模型连接失败界面*/ bool AiVoiceView::ChangeAiVoiceMobileDataFailedStartView(int16_t thisView) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoiceMobileDataFailedStartView"); @@ -646,8 +646,8 @@ namespace OHOS static const AiVoiceViewMapper ViewMapper[] = { {AIVOICE_STARTCHAT_VIEWID, &AiVoiceView::ChangeAiVoiceStartChatView}, - {AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID, &AiVoiceView::ChangeAiVoiceBluetoothFailedStartView}, - {AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID, &AiVoiceView::ChangeAiVoiceMobileDataFailedStartView}, + {AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, &AiVoiceView::ChangeAiVoiceBluetoothFailedStartView}, + {AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, &AiVoiceView::ChangeAiVoiceMobileDataFailedStartView}, {AIVOICE_CONNECT_TIMEOUT_VIEWID, &AiVoiceView::ChangeAiVoicConnectTimeoutView}, {AIVOICE_LISTENING_VIEWID, &AiVoiceView::ChangeAiVoicListeningView}, {AIVOICE_THINKING_VIEWID, &AiVoiceView::ChangeAiVoicThinkingView}, @@ -710,7 +710,7 @@ namespace OHOS UIScrollView *AiVoiceView::GetAiVoiceScrollView(int16_t index) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::GetAiVoiceScrollView"); - if (index >= AIVOICE_STARTCHAT_VIEWID && index < MAX_AIVOICE_VIEWID) + if (index >= 0 && index < MAX_AIVOICE_VIEWID) { return AiVoiceScrollView[index]; } @@ -762,6 +762,20 @@ namespace OHOS } SetAiVoiceViewAllComponentsVisibilityStatus(); + + /*更新title的textid*/ + if (p_AiVoiceBluetoothFailedStartView) + { + p_AiVoiceBluetoothFailedStartView->UpdateTitleTextId(textId); + } + if (p_AivoiceReturnResultTextView) + { + p_AivoiceReturnResultTextView->UpdateTitleTextId(textId); + } + if (p_AivoiceMobileDataFailedStartView) + { + p_AivoiceMobileDataFailedStartView->UpdateTitleTextId(textId); + } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp index 2be465838..2c4d4c5a5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp @@ -2,11 +2,12 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:11:42 + * @LastEditTime: 2024-07-31 15:08:38 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceMobileDataFailedStartView.cpp */ #include "aivoice/include/AiVoicePresenter.h" #include "aivoice/include/AivoiceMobileDataFailedStartView.h" +#include "aivoice/include/AiVoiceModel.h" #include "wearable_log.h" #include "ui_resource_string.h" #include @@ -135,6 +136,13 @@ namespace OHOS scrollView->SetPosition(0, 0, 466, 466); scrollView->SetTouchable(true); scrollView->SetDraggable(true); + UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::dragListener new fail!"); + return false; + } + scrollView->SetOnDragListener(dragListener); return true; } @@ -149,7 +157,7 @@ namespace OHOS .height = 35, .fontSize = 30, .lineHeigh = 35, - .textId = STR_AI_INTELLIGENT_ASSISTANT, + .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; title = AivoiceMobileDataFailedStartLabelInit(labelconfig); @@ -161,10 +169,10 @@ namespace OHOS /* -------------------------------------------------------------------------- */ labelconfig.left = 53; labelconfig.width = 360; - int textId[] = {STR_BOOT_FAILED, STR_ENABLE_MOBILE_DATA_FIRST}; + int textId[] = {STR_CONNECTION_FAIL, STR_PTALORTM}; /*连接失败,请稍后再重试或更换模型*/ for (int i = 0; i < sizeof(textId) / sizeof(textId[0]); i++) { - labelconfig.top = 222 + i * labelconfig.height; + labelconfig.top = 222 + i * 35; labelconfig.textId = textId[i]; label[i] = AivoiceMobileDataFailedStartLabelInit(labelconfig); if (label[i] == nullptr) @@ -202,7 +210,7 @@ namespace OHOS .y = 340, .w = 280, .h = 90, - .ViewId = MOBILEDATAFAILEDSTART_ENSURE_BUTTON_VIEW_ID, + .ViewId = AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID, }; ensureButton = AivoiceMobileDataFailedStartButtonInit(buttonconfig); if (ensureButton == nullptr) @@ -263,4 +271,12 @@ namespace OHOS return scrollView; } + void AivoiceMobileDataFailedStartView::UpdateTitleTextId(int textId) + { + if (title) + { + title->SetTextId(textId); + title->ForceResetText(); + } + } } \ 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 4d30e9b70..85bf584a0 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-07-12 16:11:36 + * @LastEditTime: 2024-07-31 11:45:51 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -345,4 +345,13 @@ namespace OHOS { return chatContentList; } + + void AivoiceReturnResultTextView::UpdateTitleTextId(int textId) + { + if (title) + { + title->SetTextId(textId); + title->ForceResetText(); + } + } } \ No newline at end of file -- 2.17.1