Merge #448 into sdk602patch0521 from refs/changes/448/head 449/target/1
author罗正 <1732036298@qq.com>
Wed, 3 Jul 2024 11:57:57 +0000 (11:57 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Wed, 3 Jul 2024 11:57:57 +0000 (11:57 +0000)
Code review from 罗正

* refs/changes/448/head: (8 commits squashed)

  - Ai语音修改

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

  - Ai语音修改

  - 修改倒计时铃声,修改下拉定时器停止逻辑,在下拉视图析构前停止定时器

  - AI语音Model修改

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

Signed-off-by: 罗正 <1732036298@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/448
21 files changed:
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListItemView.h [new file with mode: 0644]
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/include/ChatContentItem.h [new file with mode: 0644]
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/AivoiceChatContentListAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp
code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h
code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp
code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp

index 26b8b4f..b88f3f8 100644 (file)
@@ -389,6 +389,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceListeningView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceThinkingView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp
     
     #声音与震动
index c77fc93..a360111 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-06-26 17:39:41
+ * @LastEditTime: 2024-07-03 19:20:55
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
  */
 #ifndef AI_VOICE_MODEL_H
 #include "string"
 #include "iostream"
 #include "string"
+#include "ChatContentItem.h"
 namespace OHOS
 {
+
     class AiVoiceModel
     {
     public:
-        static AiVoiceModel &GetInstance(void);
+        static AiVoiceModel &GetInstance(void); // 获取单例实例
         bool ChangeToReturnResultTextView(void);
+        // 初始化和状态管理
         bool CreateIfNotExists();
+        void StatusResume(void);
 
+        // 获取设备状态
         bool GetBluetoothIsOpen(void);
         bool GetMobileDataIsOpen(void);
         bool GetAiVoiceConnectStatus(void);
 
+        // 聊天内容管理
+        bool InitchatContentItems(void);
+        bool AddUserQuestionToChatItems();
+        bool AddAiAnswerToChatItems();
+        bool AddChatContentToItemArray(const ChatContentItem &item);
+        uint8_t GetChatContentListCount(void);
+
+        // 更新和清空问题及回答
+        bool UpdateUserQuestionStr(void);
+        bool UpdateAiAnswerStr(void);
+        void ClearQuestionAndAiAnswerStr(void);
+
+        // 获取和设置问题及回答
         std::string GetUserQuestionStr(void);
         void SetUserQuestionStr(std::string str);
+        std::string GetAiAnswerStr(void);
+        void SetAiAnswerStrStr(std::string str);
 
-        std::string GetAiAnswerStrStr(void);
-        void SetaiAnswerStrStr(std::string str);
+        // 文件检查和AI状态管理
+        void CheckFileAndSendAIIsReady();
+        bool GetEntryTimeoutFlag(void);
+        void SetEntryTimeoutFlag(bool flag);
 
+        // AI录音路径管理
         std::string GetAIAudioPath(void);
 
+        // 启动和停止录音
         void StartListenAndRecordingUserQuestion(void);
         void StopListenAndRecordingUserQuestion(void);
 
+        // 定时器管理
         void AIVoice_StartTimer(uint32_t interval = 1000);
         void AIVoice_StopTimer(void);
 
@@ -44,11 +69,17 @@ namespace OHOS
         ~AiVoiceModel();
         AiVoiceModel(const AiVoiceModel &) = delete;
         AiVoiceModel &operator=(const AiVoiceModel &) = delete;
-        std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.pcm"; // ai录音的文件名
 
-        std::string userQuestionStr; // 存储用户提出的问题
-        std::string aiAnswerStr;     // 存储ai回答的问题
+        // 私有成员变量
+        std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.pcm"; // AI录音的文件路径
+        std::string userQuestionStr;                                          // 用户提出的问题
+        std::string aiAnswerStr;                                              // AI回答的问题
+        bool entryTimeoutFlag{false};                                         // 进入超时界面标志
+        uint8_t ChatContentListCount{0};                                      // 列表数量
+        static const uint16_t MaxChatContentListCount = 2;                    // 对话列表最大数量
+        ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false};  // 对话项数组
     };
+
 }
 
 #endif
\ No newline at end of file
index bddff30..e84c7e8 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 14:44:22
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-25 17:39:55
+ * @LastEditTime: 2024-07-02 18:58:24
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
  */
 #ifndef AI_VOICE_PRESENTER_H
@@ -18,7 +18,8 @@ namespace OHOS
     class AiVoicePresenter : public Presenter<AiVoiceView>,
                              public UIView::OnClickListener,
                              public UIView::OnDragListener,
-                             public RootView::OnKeyActListener
+                             public RootView::OnKeyActListener,
+                             public UIView::OnTouchListener
     {
     public:
         AiVoicePresenter();
@@ -31,9 +32,11 @@ namespace OHOS
         void OnStop() override;
 
         bool JumpToReturnResultTextView(void);
+        bool ChangeViewAndLogicOperator(int16_t hideView, int16_t showView);
 
     private:
         bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnRelease(UIView &view, const ReleaseEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListAdapter.h
new file mode 100644 (file)
index 0000000..cc1bd10
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-28 14:26:55
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-03 18:34:22
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/include/AivoiceChatContentListAdapter.h
+ */
+#ifndef AIVOICE_CHAT_CONTENT_LIST_ADAPTER_H
+#define AIVOICE_CHAT_CONTENT_LIST_ADAPTER_H
+
+#include "components/abstract_adapter.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_list.h"
+#include "language/LanguageInit.h"
+#include "UiConfig.h"
+#include <list>
+#include "aivoice/include/AivoiceChatContentListItemView.h"
+#include "iostream"
+
+namespace OHOS
+{
+
+    class AivoiceChatContentListAdapter : public AbstractAdapter
+    {
+    public:
+        AivoiceChatContentListAdapter();
+        ~AivoiceChatContentListAdapter();
+
+        void SetData(std::list<ChatContentItem> &data);
+        void ClearData(void);
+        std::list<ChatContentItem> &GetChatContentItem();
+        virtual uint16_t GetCount(void) override;
+        virtual UIView *GetView(UIView *inView, int16_t index) override;
+        void AddListItem(const ChatContentItem &item);
+        void SetItemClickListener(UIView::OnClickListener *itemclicklistener);
+        void calculateChatContentItemViewHeight(std::string text, bool flag);
+
+    private:
+        std::list<ChatContentItem> listData;
+        UIView::OnClickListener *itemClickListener{nullptr};
+        int16_t itemViewHeight{0};
+        bool aiAnswerFalg{false};
+    };
+
+}
+
+#endif
diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListItemView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListItemView.h
new file mode 100644 (file)
index 0000000..0297f9a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-06-29 17:26:19
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-02 09:48:43
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListItemView.h
+ */
+
+#ifndef AIVOICE_CHAT_CONTENT_LIST_ITEM_VIEW_H
+#define AIVOICE_CHAT_CONTENT_LIST_ITEM_VIEW_H
+
+#include "components/ui_view_group.h"
+#include "components/ui_label_ext.h"
+#include "View.h"
+#include "iostream"
+#include "ChatContentItem.h"
+namespace OHOS
+{
+    class AivoiceChatContentListItemView : public UIViewGroup
+    {
+    public:
+        AivoiceChatContentListItemView(int16_t viewHeight, bool isAiAnswerFalg);
+        ~AivoiceChatContentListItemView();
+        void SetItemInfo(const ChatContentItem itemInfo);
+        void SetUpChild();
+
+    private:
+        UILabelExt chatContentLabel;
+        int16_t m_viewHeight{250};
+        bool m_isAiAnswerFalg{false};
+    };
+}
+
+#endif
index 74fc328..63c11c0 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-06-25 17:40:57
+ * @LastEditTime: 2024-07-01 14:22:24
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h
  */
 
@@ -13,7 +13,8 @@
 #include "components/ui_label_ext.h"
 #include "components/ui_button.h"
 #include "components/ui_image_view.h"
-
+#include "aivoice/include/AivoiceChatContentListAdapter.h"
+#include "aivoice/include/AivoiceChatContentListItemView.h"
 namespace OHOS
 {
     static constexpr const char *AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID = "AivoiceReturnResultTextReturnButton";             // 返回对话内容界面的返回按钮
@@ -54,6 +55,9 @@ namespace OHOS
         ~AivoiceReturnResultTextView();
         static AivoiceReturnResultTextView *GetInstance(void);
         UIScrollView *CreateAivoiceReturnResultTextView(void);
+        void AddChatContentToList(const ChatContentItem &item);
+        AivoiceChatContentListAdapter* GetAivoiceChatContentListAdapter(void);
+        UIList* GetChatContentList(void);
 
     private:
         void ClearAll(void);
@@ -61,26 +65,19 @@ namespace OHOS
         UIButton *AivoiceReturnResultTextButtonInit(ButtonConfig &buttonconfig);
         UIImageView *AivoiceReturnResultTextImageInit(ImageConfig &imageconfig);
         bool CreateAivoiceReturnResultTextLabel(void);
-        bool CreateAivoiceReturnResultTextUserQuestionLabel(void);
-        bool CreateAivoiceReturnResultTextAIAnswerLabel(void);
-        bool CreateAivoiceReturnResultTextLImage(void);
+        bool CreateAivoiceReturnResultTextList(void);
         bool CreateAivoiceReturnResultTextButton(void);
         bool CreateAivoiceReturnResultTextScrollView(void);
         UIScrollView *scrollView{nullptr};
         UILabelExt *title{nullptr};
 
-        UILabelExt *question{nullptr}; // 提出的问题
-        UIScrollView *questionScrollView{nullptr};
-        UIImageView *recGreenImage{nullptr};
-
-        UILabelExt *answer{nullptr}; // AI回答的答案
-        UIScrollView *answerScrollView{nullptr};
-        UIImageView *recBlackImage{nullptr};
-
         UIButton *returnButton{nullptr};
 
         UIButton *continueChatButton{nullptr};
         UILabelExt *continueChat{nullptr};
+
+        AivoiceChatContentListAdapter *chatContentListAdapter{nullptr};
+        UIList *chatContentList{nullptr};
     };
 }
 #endif
index d225ed7..8d6b50c 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-06-24 16:18:51
+ * @LastEditTime: 2024-07-01 17:20:11
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h
  */
 
@@ -24,7 +24,7 @@ namespace OHOS
     static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_H = 160;
     static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 29; // 图片帧数
     static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_DELAY = 200;          // 图片更新间隔
-    static constexpr char *AIVoiceThinkingImagePaths = "/user/res/AIVoice/AIVoiceThinking/Ai_Thinking_";
+    static constexpr const char *AIVoiceThinkingImagePaths = "/user/res/AIVoice/AIVoiceThinking/Ai_Thinking_";
     class AivoiceThinkingView
     {
     public:
diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/ChatContentItem.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/ChatContentItem.h
new file mode 100644 (file)
index 0000000..9222a2d
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-07-02 09:46:24
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-02 09:48:05
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/ChatContentItem.h
+ */
+#ifndef CHAT_CONTENT_ITEM_H
+#define CHAT_CONTENT_ITEM_H
+
+#include <iostream>
+#include "string"
+namespace OHOS
+{
+    typedef struct
+    {
+        int index;
+        std::string text;
+        bool isAiAnswer;
+    } ChatContentItem;
+}
+#endif
\ No newline at end of file
index 2f14a16..efb0a05 100644 (file)
@@ -2,12 +2,13 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-26 17:39:53
+ * @LastEditTime: 2024-07-03 19:16:04
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
 #include "aivoice/include/AiVoicePresenter.h"
 #include "aivoice/include/AiVoiceView.h"
+#include "aivoice/include/AivoiceReturnResultTextView.h"
 #include "wearable_log.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <ohos_types.h>
 #include <service/graphic_service.h>
 #include <iostream>
+#include "uiservice/include/ui_service.h"
+#include <custom_utils.h>
+#include <bleEvent.h>
 namespace OHOS
 {
+    // 声明定时器变量
+    static osTimerId_t g_timer = NULL;
+    static constexpr uint16_t THIRTY_TIME = 30; // 30秒超时
+    static int Time = THIRTY_TIME;
+
     AiVoiceModel::AiVoiceModel() {}
 
     AiVoiceModel::~AiVoiceModel() {}
@@ -42,6 +51,7 @@ namespace OHOS
         return true;
     }
 
+    /*如果文件不存在就创建*/
     bool AiVoiceModel::CreateIfNotExists()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::CreateIfNotExists");
@@ -86,33 +96,189 @@ namespace OHOS
         return true;
     }
 
+    /*列表数量*/
+    uint8_t AiVoiceModel::GetChatContentListCount(void)
+    {
+        return ChatContentListCount;
+    }
+
+    /*添加聊天内容项到数组*/
+    bool AiVoiceModel::AddChatContentToItemArray(const ChatContentItem &item)
+    {
+        // 检查 ChatContentListCount 是否超出范围
+        if (ChatContentListCount >= MaxChatContentListCount)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChatContentListCount out of bounds!!");
+            return false;
+        }
+
+        chatTtems[ChatContentListCount].index = item.index;
+        chatTtems[ChatContentListCount].text = item.text;
+        chatTtems[ChatContentListCount].isAiAnswer = item.isAiAnswer;
+        ChatContentListCount++;
+
+        return true;
+    }
+
+    /*添加用户问题项*/
+    bool AiVoiceModel::AddUserQuestionToChatItems()
+    {
+        ChatContentItem UserQuestionStrItem;
+        UserQuestionStrItem.index = GetChatContentListCount();
+        UserQuestionStrItem.text = GetUserQuestionStr();
+        UserQuestionStrItem.isAiAnswer = false;
+        return AddChatContentToItemArray(UserQuestionStrItem);
+    }
+
+    /*添加AI回答项*/
+    bool AiVoiceModel::AddAiAnswerToChatItems()
+    {
+        ChatContentItem AiAnswerStrItem;
+        AiAnswerStrItem.index = GetChatContentListCount();
+        AiAnswerStrItem.text = GetAiAnswerStr();
+        AiAnswerStrItem.isAiAnswer = true;
+        return AddChatContentToItemArray(AiAnswerStrItem);
+    }
+
+    /*初始化历史对话数据*/
+    bool AiVoiceModel::InitchatContentItems(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::InitchatContentItems");
+
+        // 获取单例对象
+        AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance();
+        if (p_AivoiceReturnResultTextView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!");
+            return false;
+        }
+
+        // 添加用户问题项到数组
+        if (!AddUserQuestionToChatItems())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!");
+            return false;
+        }
+
+        // 添加AI回答项到数组
+        if (!AddAiAnswerToChatItems())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddAiAnswerToChatItems fail!!");
+            return false;
+        }
+
+        // 将聊天内容添加到显示列表中
+        for (uint8_t i = 0; i < ChatContentListCount; i++)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chatTtems[%d]", i);
+            p_AivoiceReturnResultTextView->AddChatContentToList(chatTtems[i]);
+        }
+
+        // 更新显示列表
+        auto chatContentListAdapter = p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter();
+        auto chatContentList = p_AivoiceReturnResultTextView->GetChatContentList();
+        if (chatContentListAdapter != nullptr && chatContentList != nullptr)
+        {
+            chatContentList->SetAdapter(chatContentListAdapter);
+            chatContentList->RefreshList();
+        }
+        else
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    /*更新用户问题字符串*/
+    bool AiVoiceModel::UpdateUserQuestionStr(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateUserQuestionStr");
+
+        return true;
+    }
+
+    /*更新Ai答案字符串*/
+    bool AiVoiceModel::UpdateAiAnswerStr()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateAiAnswerStr");
+
+        // 获取 ChatContentListCount
+        int index = GetChatContentListCount() - 1;
+        if (index < 0 || index >= MaxChatContentListCount)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid index: %d", index);
+            return false;
+        }
+
+        // 更新 chatTtems 中的 AI 回答内容
+        chatTtems[index].index = index;
+        chatTtems[index].text = GetAiAnswerStr();
+        chatTtems[index].isAiAnswer = true;
+
+        // 更新显示列表
+        AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance();
+        if (p_AivoiceReturnResultTextView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!");
+            return false;
+        }
+
+        AivoiceChatContentListAdapter *adapter = p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter();
+        if (adapter != nullptr && !adapter->GetChatContentItem().empty())
+        {
+            // 如果最后一条是 AI 回答,则移除
+            if (adapter->GetChatContentItem().back().isAiAnswer)
+            {
+                adapter->GetChatContentItem().pop_back();
+            }
+            // 将更新后的 AI 回答内容添加到列表
+            adapter->GetChatContentItem().push_back(chatTtems[index]);
+            p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList();
+        }
+
+        return true;
+    }
+
+    /*获取用户问题的字符串*/
     std::string AiVoiceModel::GetUserQuestionStr(void)
     {
         // userQuestionStr = "写一篇100字文章";
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "userQuestionStr:\n", userQuestionStr.c_str());
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetUserQuestionStr:%s\n", userQuestionStr.c_str());
         return userQuestionStr;
     }
 
+    /*设置用户问题的字符串*/
     void AiVoiceModel::SetUserQuestionStr(std::string str)
     {
         userQuestionStr = str;
     }
 
-    std::string AiVoiceModel::GetAiAnswerStrStr(void)
+    /*获取Ai回答的字符串*/
+    std::string AiVoiceModel::GetAiAnswerStr(void)
     {
         // aiAnswerStr = "春风化雨,时光荏苒。百年之内,生命如白驹过隙,转瞬即逝。唯有心存善念,用爱化解芥蒂,用智慧建构未来,才是人生的真正意义。让我们携手共进,用每一分时光去关爱他人,用每一滴汗水去创造奇迹,用每一个眼神去传递温暖。让这个世界因我们的存在而变得更加美好。生命短暂,但只要我们怀着虔诚的心,坚韧前行,我们就一定能在有限的时光里留下无限的可能。";
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aiAnswerStr:\n", aiAnswerStr.c_str());
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetAiAnswerStr:%s\n", aiAnswerStr.c_str());
         return aiAnswerStr;
     }
 
-    void AiVoiceModel::SetaiAnswerStrStr(std::string str)
+    /*设置Ai回答的字符串*/
+    void AiVoiceModel::SetAiAnswerStrStr(std::string str)
     {
-        aiAnswerStr = str;
+        SendMsgToUIService(UI_AI_RESPONSE_USERDATA, 0, nullptr, 0);
+        aiAnswerStr += str;
+    }
+
+    /*清空上次用户问题和Ai回答字符串*/
+    void AiVoiceModel::ClearQuestionAndAiAnswerStr(void)
+    {
+        userQuestionStr = "";
+        aiAnswerStr = "";
     }
 
     std::string AiVoiceModel::GetAIAudioPath(void)
     {
-        CreateIfNotExists();
+        // CreateIfNotExists();
         return AIAIAudioPath;
     }
 
@@ -129,7 +295,7 @@ namespace OHOS
     // 开始聆听并录取用户问题
     void AiVoiceModel::StartListenAndRecordingUserQuestion(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::RecordingUserQuestion");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::StartListenAndRecordingUserQuestion");
         AiVoiceView *view_ = AiVoiceView::GetInstance();
         if (view_ == nullptr)
         {
@@ -139,50 +305,113 @@ namespace OHOS
         if ((view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) != nullptr) &&
             (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible()))
         {
-            const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16", AiVoiceModel::GetInstance().GetAIAudioPath().c_str()};
+            std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
+            if (uapi_delete_files(audioPath.c_str())) // 先删除文件
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files,%s", audioPath.c_str());
+            }
+            else
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files fail!!");
+            }
+            const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16", audioPath.c_str()};
             AudioCaptureSample(6, (const char **)defaultArgs);
         }
-        // 开启定时器
-        AIVoice_StartTimer();
-
         return;
     }
 
     // 停止聆听用户问题
     void AiVoiceModel::StopListenAndRecordingUserQuestion(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::StopListenAndRecordingUserQuestion");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::StopListenAndRecordingUserQuestion");
         int32_t argc = 1;
         uint8_t *argv = (uint8_t *)"stop";
         AudioCaptureSample(argc, (const char **)&argv);
+        return;
+    }
+
+    /*检查录音文件是否存在并发送语音准备操作*/
+    void AiVoiceModel::CheckFileAndSendAIIsReady(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::CheckFileAndSendAIIsReady");
+        const std::string &filePath = AIAIAudioPath;
+        FILE *file = fopen(filePath.c_str(), "r");
+        if (file != nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File already exists: %s", filePath.c_str());
+
+            fseek(file, 0, SEEK_END);
+            long size = ftell(file);
+            fseek(file, 0, SEEK_SET);
+            if (size != 0)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "size = %ld", size);
+                send_AI_is_ready(0);
+                ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
+            }
+            fclose(file);
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File does not exist: %s", filePath.c_str());
+            // Handle the case where the file doesn't exist, if needed
+        }
+    }
+
+    bool AiVoiceModel::GetEntryTimeoutFlag(void)
+    {
+        return entryTimeoutFlag;
+    }
+
+    void AiVoiceModel::SetEntryTimeoutFlag(bool flag)
+    {
+        entryTimeoutFlag = flag;
+    }
+
+    void AiVoiceModel::StatusResume(void)
+    {
+        Time = THIRTY_TIME;
+
+        for (int i = 0; i < ChatContentListCount; i++)
+        {
+            chatTtems[i].index = 0;
+            chatTtems[i].text = "";
+            chatTtems[i].isAiAnswer = false;
+        }
+        ChatContentListCount = 0;
+
+        entryTimeoutFlag = false;
+        AIVoice_StopTimer();
+        ClearQuestionAndAiAnswerStr();
+        StopListenAndRecordingUserQuestion();
     }
 
     /* -------------------------------------------------------------------------- */
-    // 声明定时器变量
-    static osTimerId_t g_timer = NULL;
-    static int Time = 15;
-    static constexpr int ONE_MINUTE = 60; // 一分钟
-    static bool START_FLAG = false;
     /*定时器到期时的处理*/
     static void AIVoice_TimerCallbackProc(int data)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time);
-        Time--;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time);
+        Time -= 1;
         AiVoiceView *view_ = AiVoiceView::GetInstance();
         if (view_ == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::GetInstance fail!!");
             return;
         }
-        if (Time <= 0)
+
+        AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
+        if (p_AiVoicePresenter == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::GetInstance fail!!");
+            return;
+        }
+
+        if (Time < 0) // 如果思考时间超时30s,进入连接超时界面
         {
-            if ((view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) != nullptr) &&
-                (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible()))
+            if ((view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr) &&
+                (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible()))
             {
-                if (AiVoiceModel::GetInstance().GetAiVoiceConnectStatus() == true)
-                    view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
-                else
-                    view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID);
+                p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID);
             }
             AiVoiceModel::GetInstance().AIVoice_StopTimer();
         }
@@ -255,6 +484,7 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
             }
             g_timer = NULL;
+            Time = THIRTY_TIME;
         }
     }
 }
index 7be738e..534419a 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-06-26 17:40:11
+ * @LastEditTime: 2024-07-03 17:39:36
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -18,7 +18,8 @@
 #include <unordered_map> // For std::unordered_map
 #include <string>        // For std::string
 #include <unordered_map> // For std::unordered_map
-
+#include "bleEvent.h"
+#include <unistd.h>
 namespace OHOS
 {
 
@@ -47,7 +48,6 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart");
         Presenter<AiVoiceView>::OnStart();
         ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
-        ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
     }
 
     // 页面已经展示后的调用逻辑
@@ -74,60 +74,237 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop");
         Presenter<AiVoiceView>::OnStop();
         ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
-        AiVoiceModel::GetInstance().AIVoice_StopTimer();
+        model->StatusResume();
     }
 
+    /*调转到返回结果界面*/
     bool AiVoicePresenter::JumpToReturnResultTextView(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView");
-        if (view_ == nullptr)
-        {
-            return false;
-        }
+        WEARABLE_LOGE(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); // 思考中界面->返回结果
+            // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID); // 思考中界面->返回结果
+            ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID);
         }
         else
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView fail");
+           // return false;
+        }
+        if (!model->UpdateAiAnswerStr())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateUserQuestionAndAiAnswerStr fail");
+            return false;
+        }
+        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");
+
+        if (hideView > MAX_AIVOICE_VIEWID)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Overstep ones bounds");
             return false;
         }
 
+        view_->ChangeView(hideView, showView); // 默认先进行视图切换
+
+        switch (hideView)
+        {
+        case AIVOICE_STARTCHAT_VIEWID:
+            if (showView == AIVOICE_LISTENING_VIEWID)
+            {
+                model->StartListenAndRecordingUserQuestion();
+            }
+            break;
+
+        case AIVOICE_LISTENING_VIEWID:
+            model->StopListenAndRecordingUserQuestion();
+            if (showView == AIVOICE_THINKING_VIEWID) // 聆听中->思考中界面
+            {
+                // osal_msleep(500);
+                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) // 连接超时界面->聆听中界面
+            {
+                model->StartListenAndRecordingUserQuestion();
+            }
+            break;
+
+        default:
+            // Handle other cases if needed
+            break;
+        }
+
         return true;
     }
+#endif
 
     bool AiVoicePresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        UNUSED(view);
+        UNUSED(event);
+        return true;
+    }
+
+    bool AiVoicePresenter::OnRelease(UIView &view, const ReleaseEvent &event)
     {
         UNUSED(event);
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnClick");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease");
         std::string viewId = view.GetViewId();
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease %s", viewId.c_str());
 
         if (viewId == START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮
         {
+#if 0
             if (model->GetMobileDataIsOpen() == false) // 判断移动数据是否开启
             {
                 view_->ChangeView(AIVOICE_STARTCHAT_VIEWID, AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID); // 开始对话->移动数据未开启界面
             }
             else
             {
-                view_->ChangeView(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID); // 开始对话->聆听中界面
-                model->StartListenAndRecordingUserQuestion();
+                ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID,AIVOICE_LISTENING_VIEWID);
             }
+#else
+            bool state = model->GetBluetoothIsOpen();
+            (state == false)
+                ? ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID)
+                : ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
+#endif
             return true;
         }
 
         if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮
         {
-            if (model->GetAiVoiceConnectStatus() == false) // 判断与AI模型的连接状态
-            {
-                view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID); // 聆听中->连接超时界面
-            }
-            else
-            {
-                view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 聆听中->思考中界面
-                model->StopListenAndRecordingUserQuestion();
-            }
+            bool state = model->GetAiVoiceConnectStatus();
+            (state == false)
+                ? ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID)
+                : ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
             return true;
         }
 
@@ -142,7 +319,7 @@ namespace OHOS
         auto it = viewIdMap.find(viewId);
         if (it != viewIdMap.end())
         {
-            view_->ChangeView(it->second.first, it->second.second);
+            ChangeViewAndLogicOperator(it->second.first, it->second.second);
             return true;
         }
         else
@@ -182,11 +359,13 @@ namespace OHOS
             }
             else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID))
             {
-                view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 聆听中->开始对话界面
+                // view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 聆听中->开始对话界面
+                ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID);
             }
             else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID))
             {
-                view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 思考中->开始对话界面
+                // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 思考中->开始对话界面
+                ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID);
             }
             AiVoicePresenter::X_DRAG_FLAG = false;
         }
index f1e0843..9257f42 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-06-25 17:43:03
+ * @LastEditTime: 2024-07-03 18:38:55
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -141,7 +141,7 @@ namespace OHOS
         button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c);
         button->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
         button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED);
-        button->SetOnClickListener(presenter_);
+        button->SetOnTouchListener(presenter_);
 
         return button;
     }
@@ -426,21 +426,6 @@ namespace OHOS
             AiVoiceScrollView[thisView] = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView();
             container_->Add(AiVoiceScrollView[thisView]);
         }
-        else
-        {
-            container_->Remove(AiVoiceScrollView[thisView]);
-            delete p_AivoiceReturnResultTextView;
-            p_AivoiceReturnResultTextView = nullptr;
-            
-            p_AivoiceReturnResultTextView = new AivoiceReturnResultTextView();
-            if (p_AivoiceReturnResultTextView == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
-                return false;
-            }
-            AiVoiceScrollView[thisView] = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView();
-            container_->Add(AiVoiceScrollView[thisView]);
-        }
         return true;
     }
 
diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp
new file mode 100644 (file)
index 0000000..86af65c
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-28 14:27:05
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-03 15:27:02
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/AivoiceChatContentListAdapter.cpp
+ */
+#include "aivoice/include/AivoiceChatContentListAdapter.h"
+#include "wearable_log.h"
+#include <UiConfig.h>
+
+namespace OHOS
+{
+
+    AivoiceChatContentListAdapter::AivoiceChatContentListAdapter()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::AivoiceChatContentListAdapter");
+    }
+
+    AivoiceChatContentListAdapter::~AivoiceChatContentListAdapter()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::~AivoiceChatContentListAdapter");
+        listData.clear();
+    }
+
+    uint16_t AivoiceChatContentListAdapter::GetCount(void)
+    {
+        return listData.size();
+    }
+
+    std::list<ChatContentItem> &AivoiceChatContentListAdapter::GetChatContentItem()
+    {
+        return listData;
+    }
+
+    void AivoiceChatContentListAdapter::SetData(std::list<ChatContentItem> &data)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+        std::list<ChatContentItem>::iterator it;
+        for (it = data.begin(); it != data.end(); it++)
+        {
+            listData.push_back(*it);
+        }
+    }
+
+    void AivoiceChatContentListAdapter::ClearData(void)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+    }
+
+    void AivoiceChatContentListAdapter::calculateChatContentItemViewHeight(std::string text, bool flag)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::calculateChatContentItemViewHeight");
+
+        const char *Text = text.c_str();
+        aiAnswerFalg = flag;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Text:%s,aiAnswerFalg:%d", Text, aiAnswerFalg);
+
+        UILabel label;
+        label.SetPosition(53, 100);
+        label.Resize(360, 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, 26);
+
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label.GetHeight:%d,label.GetTextHeight:%d", label.GetHeight(), label.GetTextHeight());
+        itemViewHeight = label.GetTextHeight();
+    }
+
+    UIView *AivoiceChatContentListAdapter::GetView(UIView *inView, int16_t index)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::GetView,index %d", index);
+        // 1.先检查列表数据是否为空,若为空则返回空指针
+        if (listData.empty())
+        {
+            return nullptr;
+        }
+        // 2.接着检查索引是否小于0,若小于0则返回空指针
+        if (index < 0)
+        {
+            return nullptr;
+        }
+        // 3.检查是否超出列表数据大小,若超出则返回空指针
+        size_t uindex = index;
+        if (uindex >= listData.size())
+        {
+            return nullptr;
+        }
+        // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量
+        std::list<ChatContentItem>::iterator it = listData.begin();
+        for (int i = 0; i < index; i++)
+        {
+            it++;
+        }
+        ChatContentItem itemData = *it;
+        AivoiceChatContentListItemView *item = nullptr;
+        /* -------------------------------------------------------------------------- */
+        calculateChatContentItemViewHeight(itemData.text, itemData.isAiAnswer);
+        /* -------------------------------------------------------------------------- */
+        // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的LanguageSwitchListItemView对象,否则将inView转换成LanguageSwitchListItemView类型的指针
+        if (inView == nullptr)
+        {
+            item = new AivoiceChatContentListItemView(itemViewHeight, aiAnswerFalg);
+        }
+        else
+        {
+            item = dynamic_cast<AivoiceChatContentListItemView *>(inView);
+        }
+        item->SetItemInfo(itemData);
+        return item;
+    }
+
+    void AivoiceChatContentListAdapter::SetItemClickListener(UIView::OnClickListener *itemclicklistener)
+    {
+        itemClickListener = itemclicklistener;
+    }
+
+    void AivoiceChatContentListAdapter::AddListItem(const ChatContentItem &item)
+    {
+        listData.push_back(item);
+    }
+
+}
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
new file mode 100644 (file)
index 0000000..c7e499f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-06-29 17:27:25
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-03 18:34:57
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
+ */
+
+#include "aivoice/include/AivoiceChatContentListItemView.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+    static constexpr int16_t QUESTION_ITEM_VIEW_X = 112;
+    static constexpr int16_t ANSWER_ITEM_VIEW_X = 53;
+
+    static constexpr int16_t QUESTION_ITEM_VIEW_Y = 0;
+    static constexpr int16_t ANSWER_ITEM_VIEW_Y = 30;
+
+    static constexpr int16_t QUESTION_ITEM_VIEW_W = 280;
+    static constexpr int16_t ANSWER_ITEM_VIEW_W = 360;
+
+    static constexpr int64_t QUESTION_ITEM_VIEW_COLOR = 0xff4fc34c;
+    static constexpr int64_t ANSWER_ITEM_VIEW_COLOR = 0xff191919;
+
+    static constexpr int64_t ITEM_VIEW_RADIUS = 20;
+
+    static constexpr int16_t CHATCONTENTLABEL_TEXT_FONT = 26;
+    static constexpr int16_t CHATCONTENTLABEL_LINE_HEIGHT = 30;
+    static constexpr int16_t CHATCONTENTLABEL_ROLLSPEED = 40;
+    static constexpr int16_t NUM_2 = 2;
+
+    AivoiceChatContentListItemView::AivoiceChatContentListItemView(int16_t viewHeight, bool isAiAnswerFalg)
+    {
+        m_viewHeight = viewHeight;
+        m_isAiAnswerFalg = isAiAnswerFalg;
+        SetPosition(0, 0);
+        Resize(ANSWER_ITEM_VIEW_W, m_viewHeight + 50);
+        SetStyle(STYLE_BACKGROUND_COLOR, m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_COLOR : QUESTION_ITEM_VIEW_COLOR);
+        SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        SetStyle(STYLE_BORDER_RADIUS, ITEM_VIEW_RADIUS);
+        SetTouchable(true);
+        SetUpChild();
+        Add(&chatContentLabel);
+    }
+
+    AivoiceChatContentListItemView::~AivoiceChatContentListItemView()
+    {
+        Remove(&chatContentLabel);
+    }
+
+    void AivoiceChatContentListItemView::SetItemInfo(const ChatContentItem itemInfo)
+    {
+        chatContentLabel.SetText(itemInfo.text.c_str());
+        Resize(ANSWER_ITEM_VIEW_W, m_viewHeight + 50);
+        chatContentLabel.Resize((GetWidth() - chatContentLabel.GetX() * 2), (GetHeight() - chatContentLabel.GetY() * 2));
+    }
+
+    void AivoiceChatContentListItemView::SetUpChild()
+    {
+        chatContentLabel.SetPosition(0, 0);
+        chatContentLabel.Resize((GetWidth() - chatContentLabel.GetX() * 2), (GetHeight() - chatContentLabel.GetY() * 2));
+        chatContentLabel.SetStyle(STYLE_TEXT_FONT, CHATCONTENTLABEL_TEXT_FONT);
+        chatContentLabel.SetStyle(STYLE_LINE_HEIGHT, CHATCONTENTLABEL_LINE_HEIGHT);
+        chatContentLabel.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+        chatContentLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
+        chatContentLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, CHATCONTENTLABEL_TEXT_FONT);
+        chatContentLabel.SetTextColor(m_isAiAnswerFalg ? Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff) : Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xcc));
+    }
+}
\ No newline at end of file
index 9dbf012..ce220d8 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-06-24 10:38:42
+ * @LastEditTime: 2024-07-03 09:34:11
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceConnectTimeoutView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -209,13 +209,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 *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+        if (touchListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::draglistener can not be nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::touchListener can not be nullptr!");
             return false;
         }
-        ensureButton->SetOnClickListener(clickListener);
+        ensureButton->SetOnTouchListener(touchListener);
 
         return true;
     }
index 010ff29..7cb7e89 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-06-24 16:39:51
+ * @LastEditTime: 2024-07-03 18:38:35
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceListeningView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -243,13 +243,13 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finishSpeakButton new fail!");
             return false;
         }
-        UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
-        if (clickListener == nullptr)
+        UIView::OnTouchListener *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+        if (touchListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::draglistener can not be nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::touchListener can not be nullptr!");
             return false;
         }
-        finishSpeakButton->SetOnClickListener(clickListener);
+        finishSpeakButton->SetOnTouchListener(touchListener);
 
         return true;
     }
index b76f9e6..9aaec87 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-06-24 10:39:26
+ * @LastEditTime: 2024-07-03 09:34:25
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceMobileDataFailedStartView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -209,13 +209,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 *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+        if (touchListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::draglistener can not be nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::touchListener can not be nullptr!");
             return false;
         }
-        ensureButton->SetOnClickListener(clickListener);
+        ensureButton->SetOnTouchListener(touchListener);
 
         return true;
     }
index 1e6c112..fa964f2 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-06-25 17:45:39
+ * @LastEditTime: 2024-07-03 15:17:56
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -18,50 +18,24 @@ namespace OHOS
 {
 
     /* -------------------------------------------------------------------------- */
-    static constexpr const int16_t QUESTION_SCROLLVIEW_X = 112;
-    static constexpr const int16_t QUESTION_SCROLLVIEW_Y = 120;
-    static constexpr const int16_t QUESTION_SCROLLVIEW_W = 280;
-    static constexpr const int16_t QUESTION_SCROLLVIEW_H = 80;
-    static constexpr const int64_t QUESTION_BACKGROUND_COLOR = 0xff4fc34c;
-
-    static constexpr const int16_t QUESTION_LABEL_W = 200;
-    static constexpr const int16_t QUESTION_LABEL_H = 30;
-    static constexpr const int16_t QUESTION_LABEL_FONTSIZE = 26;
-    static constexpr const int16_t QUESTION_LABEL_LINEHEIGHT = 30;
-    /* -------------------------------------------------------------------------- */
-
-    static constexpr const int16_t ANSWER_SCROLLVIEW_X = 53;
-    static constexpr const int16_t ANSWER_SCROLLVIEW_Y = QUESTION_SCROLLVIEW_Y + QUESTION_SCROLLVIEW_H + 30;
-    static constexpr const int16_t ANSWER_SCROLLVIEW_W = 360;
-    static constexpr const int16_t ANSWER_SCROLLVIEW_H = 250;
-    static constexpr const int64_t ANSWER_BACKGROUND_COLOR = 0xff191919;
+    static constexpr const int16_t CHATCONTENT_LIST_X = 53;
+    static constexpr const int16_t CHATCONTENT_LIST_Y = 120;
+    static constexpr const int16_t CHATCONTENT_LIST_W = 360;
+    static constexpr const int16_t CHATCONTENT_LIST_H = 200;
+    static constexpr const int16_t REBOUNDSIZE = 35;
+    static constexpr const int16_t CHATCONTENT_SCROLLBLANKSIZE = 35;
+    static constexpr const int16_t MAX_SCR_DIS = 1000;
+    static constexpr const int16_t SNUM_2 = 2;
 
-    static constexpr const int16_t ANSWER_LABEL_W = 270;
-    static constexpr const int16_t ANSWER_LABEL_H = 194;
-    static constexpr const int16_t ANSWER_LABEL_FONTSIZE = 26;
-    static constexpr const int16_t ANSWER_LABEL_LINEHEIGHT = 30;
-
-    /* -------------------------------------------------------------------------- */
-    static constexpr const int16_t RECGREEN_IMAGE_X = 342;
-    static constexpr const int16_t RECGREEN_IMAGE_Y = QUESTION_SCROLLVIEW_Y;
-    static constexpr const int16_t RECGREEN_IMAGE_W = 70;
-    static constexpr const int16_t RECGREEN_IMAGE_H = 30;
-    static constexpr const char *RECGREEN_IMAGE_PATH = "/user/res/AIVoice/AI_RecGreen.bin";
-
-    static constexpr const int16_t RECBLACK_IMAGE_X = 32;
-    static constexpr const int16_t RECBLACK_IMAGE_Y = ANSWER_SCROLLVIEW_Y;
-    static constexpr const int16_t RECBLACK_IMAGE_W = 70;
-    static constexpr const int16_t RECBLACK_IMAGE_H = 30;
-    static constexpr const char *RECBLACK_IMAGE_PATH = "/user/res/AIVoice/AI_RecBlack.bin";
     /* -------------------------------------------------------------------------- */
     static constexpr const int16_t RETURN_BUTTON_X = 73;
-    static constexpr const int16_t RETURN_BUTTON_Y = ANSWER_SCROLLVIEW_Y + ANSWER_SCROLLVIEW_H + 20;
+    static constexpr const int16_t RETURN_BUTTON_Y = CHATCONTENT_LIST_Y + CHATCONTENT_LIST_H + 20;
     static constexpr const int16_t RETURN_BUTTON_W = 100;
     static constexpr const int16_t RETURN_BUTTON_H = 100;
     static constexpr const char *RETURN_BUTTON_PATH = "/user/res/AIVoice/AI_Union.bin";
 
     static constexpr const int16_t CONTINUECHAT_BUTTON_X = 183;
-    static constexpr const int16_t CONTINUECHAT_BUTTON_Y = ANSWER_SCROLLVIEW_Y + ANSWER_SCROLLVIEW_H + 20;
+    static constexpr const int16_t CONTINUECHAT_BUTTON_Y = CHATCONTENT_LIST_Y + CHATCONTENT_LIST_H + 20;
     static constexpr const int16_t CONTINUECHAT_BUTTON_W = 210;
     static constexpr const int16_t CONTINUECHAT_BUTTON_H = 100;
     /* -------------------------------------------------------------------------- */
@@ -105,40 +79,16 @@ namespace OHOS
                 title = nullptr;
             }
 
-            if (questionScrollView != nullptr)
+            if (chatContentListAdapter != nullptr)
             {
-                questionScrollView->Remove(question);
-                if (question != nullptr)
-                {
-                    delete question;
-                    question = nullptr;
-                }
-                delete questionScrollView;
-                questionScrollView = nullptr;
+                delete chatContentListAdapter;
+                chatContentListAdapter = nullptr;
             }
 
-            if (recGreenImage != nullptr)
+            if (chatContentList != nullptr)
             {
-                delete recGreenImage;
-                recGreenImage = nullptr;
-            }
-
-            if (answerScrollView != nullptr)
-            {
-                answerScrollView->Remove(answer);
-                if (answer != nullptr)
-                {
-                    delete answer;
-                    answer = nullptr;
-                }
-                delete answerScrollView;
-                answerScrollView = nullptr;
-            }
-
-            if (recBlackImage != nullptr)
-            {
-                delete recBlackImage;
-                recBlackImage = nullptr;
+                delete chatContentList;
+                chatContentList = nullptr;
             }
 
             if (returnButton != nullptr)
@@ -226,96 +176,12 @@ namespace OHOS
         scrollView->SetThrowDrag(true);
         scrollView->SetMaxScrollDistance(1000);
         scrollView->SetDirection(UIScrollView::VERTICAL);
+        scrollView->SetRotateFactor(2);
+        scrollView->RequestFocus();
 
         return true;
     }
 
-    bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextUserQuestionLabel(void)
-    {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextUserQuestionLabel");
-        if (questionScrollView == nullptr)
-        {
-            questionScrollView = new UIScrollView();
-            if (questionScrollView == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::questionScrollView is nullptr!");
-                return false;
-            }
-            questionScrollView->SetPosition(QUESTION_SCROLLVIEW_X, QUESTION_SCROLLVIEW_Y, QUESTION_SCROLLVIEW_W, QUESTION_SCROLLVIEW_H);
-            questionScrollView->SetStyle(STYLE_BACKGROUND_COLOR, QUESTION_BACKGROUND_COLOR);
-            questionScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-            questionScrollView->SetStyle(STYLE_BORDER_RADIUS, 20);
-        }
-        /* -------------------------------------------------------------------------- */
-        int16_t QUESTION_LABEL_X = (questionScrollView->GetWidth() - QUESTION_LABEL_W) / ONE_HALF_NUM;
-        int16_t QUESTION_LABEL_Y = (questionScrollView->GetHeight() - QUESTION_LABEL_H) / ONE_HALF_NUM;
-        if (question == nullptr)
-        {
-            question = new UILabelExt();
-            if (question == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::question is nullptr!");
-                return false;
-            }
-
-            question->SetPosition(QUESTION_LABEL_X, QUESTION_LABEL_Y, QUESTION_LABEL_W, QUESTION_LABEL_H);
-            question->SetStyle(STYLE_TEXT_FONT, QUESTION_LABEL_FONTSIZE);
-            question->SetStyle(STYLE_LINE_HEIGHT, QUESTION_LABEL_LINEHEIGHT);
-            std::string questionStr = AiVoiceModel::GetInstance().GetUserQuestionStr();
-            question->SetText(questionStr.c_str());
-            question->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xcc));
-            question->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
-            question->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-            question->SetFont(DEFAULT_VECTOR_FONT_FILENAME, QUESTION_LABEL_FONTSIZE);
-
-            questionScrollView->Add(question);
-        }
-        return true;
-    }
-
-    bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextAIAnswerLabel(void)
-    {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextAIAnswerLabel");
-        if (answerScrollView == nullptr)
-        {
-            answerScrollView = new UIScrollView();
-            if (answerScrollView == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::answerScrollView is nullptr!");
-                return false;
-            }
-            answerScrollView->SetPosition(ANSWER_SCROLLVIEW_X, ANSWER_SCROLLVIEW_Y, ANSWER_SCROLLVIEW_W, ANSWER_SCROLLVIEW_H);
-            answerScrollView->SetStyle(STYLE_BACKGROUND_COLOR, ANSWER_BACKGROUND_COLOR);
-            answerScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-            answerScrollView->SetStyle(STYLE_BORDER_RADIUS, 20);
-            /* -------------------------------------------------------------------------- */
-            int16_t ANSWER_LABEL_X = (answerScrollView->GetWidth() - ANSWER_LABEL_W) / ONE_HALF_NUM;
-            int16_t ANSWER_LABEL_Y = (answerScrollView->GetHeight() - ANSWER_LABEL_H) / ONE_HALF_NUM;
-            if (answer == nullptr)
-            {
-                answer = new UILabelExt();
-                if (answer == nullptr)
-                {
-                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::answer is nullptr!");
-                    return false;
-                }
-
-                answer->SetPosition(ANSWER_LABEL_X, ANSWER_LABEL_Y, ANSWER_LABEL_W, ANSWER_LABEL_H);
-                answer->SetStyle(STYLE_TEXT_FONT, ANSWER_LABEL_FONTSIZE);
-                answer->SetStyle(STYLE_LINE_HEIGHT, ANSWER_LABEL_LINEHEIGHT);
-                std::string answerStr = AiVoiceModel::GetInstance().GetAiAnswerStrStr();
-                answer->SetText(answerStr.c_str());
-                answer->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
-                answer->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
-                answer->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
-                answer->SetFont(DEFAULT_VECTOR_FONT_FILENAME, QUESTION_LABEL_FONTSIZE);
-
-                answerScrollView->Add(answer);
-            }
-        }
-        return true;
-    }
-
     bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel");
@@ -336,11 +202,6 @@ namespace OHOS
             return false;
         }
         /* -------------------------------------------------------------------------- */
-        if (!CreateAivoiceReturnResultTextUserQuestionLabel() || !CreateAivoiceReturnResultTextAIAnswerLabel())
-        {
-            return false;
-        }
-        /* -------------------------------------------------------------------------- */
         labelconfig = {
             .left = CONTINUECHAT_X,
             .top = CONTINUECHAT_Y,
@@ -361,37 +222,41 @@ namespace OHOS
         return true;
     }
 
-    bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLImage(void)
+    bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLImage");
-        ImageConfig imageconfig = {
-            .x = RECGREEN_IMAGE_X,
-            .y = RECGREEN_IMAGE_Y,
-            .w = RECGREEN_IMAGE_W,
-            .h = RECGREEN_IMAGE_H,
-            .src = RECGREEN_IMAGE_PATH,
-        };
-        recGreenImage = AivoiceReturnResultTextImageInit(imageconfig);
-        if (recGreenImage == nullptr)
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList");
+        chatContentListAdapter = new AivoiceChatContentListAdapter();
+        if (chatContentListAdapter == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::recGreenImage is nullptr!");
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr");
             return false;
         }
-        /* -------------------------------------------------------------------------- */
-        imageconfig = {
-            .x = RECBLACK_IMAGE_X,
-            .y = RECBLACK_IMAGE_Y,
-            .w = RECBLACK_IMAGE_W,
-            .h = RECBLACK_IMAGE_H,
-            .src = RECBLACK_IMAGE_PATH,
-        };
-        recBlackImage = AivoiceReturnResultTextImageInit(imageconfig);
-        if (recBlackImage == nullptr)
+        UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
+        if (clickListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::recBlackImage is nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr");
             return false;
         }
+        chatContentListAdapter->SetItemClickListener(clickListener);
 
+        chatContentList = new UIList(UIList::VERTICAL);
+        if (chatContentList == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::chatContentList is nullptr");
+            return false;
+        }
+        chatContentList->SetPosition(CHATCONTENT_LIST_X, CHATCONTENT_LIST_Y, CHATCONTENT_LIST_W, CHATCONTENT_LIST_H);
+        chatContentList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+        chatContentList->EnableAutoAlign(true);
+        chatContentList->SetTouchable(true);
+        chatContentList->SetDraggable(true);
+        chatContentList->SetThrowDrag(true);
+        chatContentList->SetReboundSize(REBOUNDSIZE);
+        chatContentList->SetMaxScrollDistance(MAX_SCR_DIS);
+        chatContentList->SetIntercept(true);
+        /* -------------------------------------------------------------------------- */
+        AiVoiceModel::GetInstance().InitchatContentItems();
+        /* -------------------------------------------------------------------------- */
         return true;
     }
 
@@ -413,13 +278,13 @@ namespace OHOS
         }
         returnButton->SetImagePosition(39, 39);
         returnButton->SetImageSrc(RETURN_BUTTON_PATH, RETURN_BUTTON_PATH);
-        UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
-        if (clickListener == nullptr)
+        UIView::OnTouchListener *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+        if (touchListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::draglistener can not be nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::touchListener can not be nullptr!");
             return false;
         }
-        returnButton->SetOnClickListener(clickListener);
+        returnButton->SetOnTouchListener(touchListener);
         /* -------------------------------------------------------------------------- */
         buttonconfig = {
             .x = CONTINUECHAT_BUTTON_X,
@@ -434,7 +299,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "continueChatButton new fail!");
             return false;
         }
-        continueChatButton->SetOnClickListener(clickListener);
+        continueChatButton->SetOnTouchListener(touchListener);
 
         return true;
     }
@@ -445,21 +310,35 @@ namespace OHOS
         if (scrollView == nullptr)
         {
             if (!CreateAivoiceReturnResultTextScrollView() || !CreateAivoiceReturnResultTextLabel() ||
-                !CreateAivoiceReturnResultTextLImage() || !CreateAivoiceReturnResultTextButton())
+                !CreateAivoiceReturnResultTextList() || !CreateAivoiceReturnResultTextButton())
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextView fail!!");
                 return nullptr;
             }
             /* ----------------------------------- Add ---------------------------------- */
             scrollView->Add(title);
-            scrollView->Add(questionScrollView);
-            scrollView->Add(recGreenImage);
-            scrollView->Add(answerScrollView);
-            scrollView->Add(recBlackImage);
+            scrollView->Add(chatContentList);
             scrollView->Add(returnButton);
             scrollView->Add(continueChatButton);
             scrollView->Add(continueChat);
         }
         return scrollView;
     }
+
+    /*添加对话内容到List*/
+    void AivoiceReturnResultTextView::AddChatContentToList(const ChatContentItem &item)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::AddChatContentToList");
+        chatContentListAdapter->AddListItem(item);
+    }
+
+    AivoiceChatContentListAdapter *AivoiceReturnResultTextView::GetAivoiceChatContentListAdapter(void)
+    {
+        return chatContentListAdapter;
+    }
+
+    UIList *AivoiceReturnResultTextView::GetChatContentList(void)
+    {
+        return chatContentList;
+    }
 }
\ No newline at end of file
index 10298ad..5aa19e9 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-06-24 16:39:53
+ * @LastEditTime: 2024-07-03 09:34:58
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceThinkingView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -244,13 +244,13 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancelThinkButton new fail!");
             return false;
         }
-        UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
-        if (clickListener == nullptr)
+        UIView::OnTouchListener *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+        if (touchListener == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::draglistener can not be nullptr!");
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::touchListener can not be nullptr!");
             return false;
         }
-        cancelThinkButton->SetOnClickListener(clickListener);
+        cancelThinkButton->SetOnTouchListener(touchListener);
 
         return true;
     }
index 935850e..bb52096 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-04-07 18:15:53\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-09 15:27:19\r
+ * @LastEditTime: 2024-07-03 18:44:50\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h\r
  */\r
 #ifndef COUNTDOWN_MODEL_H\r
@@ -106,7 +106,8 @@ namespace OHOS
         std::shared_ptr<CountDownRingPlayerListener> playerInterruptListener{nullptr};\r
         AudioSession sessionId;\r
         AudioInterrupt interrupt;\r
-        const char *RingMusicPath = "/user/music/alarm.mp3"; // 铃声路径\r
+        // const char *RingMusicPath = "/user/music/alarm.mp3"; // 铃声路径\r
+        const char *RingMusicPath = "/music/ring/alarm.mp3"; // 铃声路径\r
 \r
         std::string countdownDuration{nullptr};\r
         std::string RingTime{"00:00:00"};  // 响铃时间\r
index 92d983f..f58fa75 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-26 18:14:24
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-01 09:30:03
+ * @LastEditTime: 2024-07-03 18:42:05
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp
  */
 
@@ -117,6 +117,10 @@ namespace OHOS
     PullUpDownView::~PullUpDownView()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView");
+        if (MainPresenterSample::GetInstance() != nullptr)
+        {
+            MainPresenterSample::GetInstance()->PullUpDown_StopTimer();
+        }
         ClearAll();
         g_pPullUpDownView = nullptr;
     }
index 6f7d3b8..a0d491f 100644 (file)
@@ -80,7 +80,7 @@ void ble_set_ai_Question_str(char *buf)
 
 void ble_set_ai_Answer_str(char *buf)
 {
-    OHOS::AiVoiceModel::GetInstance().SetaiAnswerStrStr(std::string(buf));
+    OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf));
 }
 
 // {