AI语音界面已经完成,下一步需要联调接口 621/2
authorluozheng <1732036298@qq.com>
Wed, 31 Jul 2024 09:09:43 +0000 (17:09 +0800)
committerluozheng <1732036298@qq.com>
Wed, 31 Jul 2024 09:09:43 +0000 (17:09 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp

index 141f15b..aedba05 100644 (file)
@@ -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);
index 6c9b822..a027993 100644 (file)
@@ -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<int, std::pair<int, int>> selectAiModelToTextId;
     };
 
 }
index 7bf57cc..fcd5ab3 100644 (file)
@@ -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;
 
index 8a1c056..442903d 100644 (file)
@@ -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);
index 63c11c0..6e67ed5 100644 (file)
@@ -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);
index 8d6b50c..93a223e 100644 (file)
@@ -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;
index e8d7e54..126a1af 100644 (file)
@@ -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<UIView::OnDragListener *>(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<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
-        if (clickListener == nullptr)
+        UIView::OnTouchListener *onReleaseListener = static_cast<UIView::OnTouchListener *>(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
index 8b33585..61437d7 100644 (file)
@@ -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 <bleEvent.h>
 #include <unistd.h>
 #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<int, int> 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;
index f72dfe7..0cfa13e 100644 (file)
@@ -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<std::string, std::pair<int16_t, int16_t>> 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;
index 6b4fd6d..118bd42 100644 (file)
@@ -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
index 2be4658..2c4d4c5 100644 (file)
@@ -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 <UiConfig.h>
@@ -135,6 +136,13 @@ namespace OHOS
         scrollView->SetPosition(0, 0, 466, 466);
         scrollView->SetTouchable(true);
         scrollView->SetDraggable(true);
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(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
index 4d30e9b..85bf584 100644 (file)
@@ -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