实现AI答案恢复,列表同步滚动 1244/1
authorluozheng <1732036298@qq.com>
Wed, 23 Oct 2024 07:07:47 +0000 (15:07 +0800)
committerluozheng <1732036298@qq.com>
Wed, 23 Oct 2024 07:07:47 +0000 (15:07 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
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/AivoiceReturnResultTextView.cpp

index 8768583..6025767 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-08-31 16:13:42
+ * @LastEditTime: 2024-10-23 11:22:25
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
  */
 #ifndef AI_VOICE_PRESENTER_H
@@ -12,6 +12,7 @@
 #include "View.h"
 #include "ui_resource_string.h"
 #include "components/ui_time_picker.h"
+#include "ModelListenerSample.h"
 namespace OHOS
 {
     class AiVoiceView;
@@ -21,7 +22,8 @@ namespace OHOS
                              public UIView::OnDragListener,
                              public RootView::OnKeyActListener,
                              public UIPicker::SelectedListener,
-                             public UIView::OnTouchListener
+                             public UIView::OnTouchListener,
+                             public ModelListenerSample
     {
     public:
         typedef enum : uint8_t
@@ -42,6 +44,8 @@ namespace OHOS
         void OnResume() override;
         void OnPause() override;
         void OnStop() override;
+        void Notify() override;
+        void calculateChatContentItemViewHeight(std::string text, bool flag);
 
         bool JumpToReturnResultTextView(void);
         bool ChangeToAIVoiceListeningView(bool val);
@@ -61,6 +65,9 @@ namespace OHOS
 
         AiVoiceModel *model;
         bool X_DRAG_FLAG{false};
+
+        int preHeight{0};
+        bool isScroll{false};
     };
 }
 
index e16011c..35c847d 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-10-22 17:30:40
+ * @LastEditTime: 2024-10-23 14:19:17
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -408,6 +408,8 @@ namespace OHOS
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetChatContentListCount() - 1 = %d,line = %d", GetChatContentListCount() - 1, __LINE__);
             // 将更新后的 AI 回答内容添加到列表
             adapter->GetChatContentItem().push_back(chatTtems[GetChatContentListCount() - 1]);
+            if (AiVoicePresenter::GetInstance())
+                AiVoicePresenter::GetInstance()->calculateChatContentItemViewHeight(chatTtems[GetChatContentListCount() - 1].text, true); 
             p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList();
         }
         else
@@ -785,7 +787,7 @@ namespace OHOS
     void AiVoiceModel::reset_ai_screen60s_timer_time()
     {
         SCREEN_60S_TIME = 60;
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d",SCREEN_60S_TIME);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d", SCREEN_60S_TIME);
         if (nullptr == g_screen60s_timer)
         {
             ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 重新常亮屏
@@ -878,7 +880,7 @@ namespace OHOS
     }
 
     static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
-    static uint8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时
+    static uint8_t AI_IS_READY_TIMEOUT = 5;            // 5s钟超时
     static void AI_IS_READY_CallbackProc(int data)
     {
         if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时
index 029b813..998281a 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-10-21 18:35:53
+ * @LastEditTime: 2024-10-23 15:07:12
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -102,8 +102,10 @@ namespace OHOS
     bool AiVoicePresenter::JumpToReturnResultTextView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView");
-        if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())
+        if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr &&
+            view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())
         {
+            preHeight = 0;
             ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID);
         }
         else
@@ -263,8 +265,8 @@ namespace OHOS
     {
         UNUSED(event);
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnClick");
-        
-        model->reset_ai_screen60s_timer_time();//重置60s取消常亮屏timer
+
+        model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer
 
         if (strcmp(view.GetViewId(), AIVOICE_IMGAE_VIEW_ID) == 0) /*点击的是Ai模型就切换模型*/
         {
@@ -478,4 +480,42 @@ namespace OHOS
         model->SetSelectAiModel(picker.GetSelected());
         view_->ChangeAiModelAndUpdateComponentsStatus();
     }
+
+    // 计算聊天内容ItemView的高度
+    void AiVoicePresenter::calculateChatContentItemViewHeight(std::string text, bool flag)
+    {
+        const char *Text = text.c_str();
+        UILabel label;
+        label.SetPosition(53, 100);
+        label.Resize(flag ? 280 : 200, 60);
+        label.SetStyle(STYLE_TEXT_FONT, 26);
+        label.SetStyle(STYLE_LINE_HEIGHT, 30);
+        label.SetText(Text);
+        label.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+        label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        label.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 26);
+
+        if (label.GetTextHeight() > preHeight)
+        {
+            preHeight = label.GetTextHeight();
+            isScroll = true;
+        }
+        return;
+    }
+
+    //监听高度是否变化
+    void AiVoicePresenter::Notify()
+    {
+        if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) &&
+            (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()))
+        {
+            if (isScroll)
+            {
+                // 监听,让List实现滚动
+                AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-150);
+                isScroll = false;
+            }
+        }
+        return;
+    }
 }
\ No newline at end of file
index cfdc9a8..b585e2d 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-08-01 10:12:28
+ * @LastEditTime: 2024-10-23 14:58:03
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -248,13 +248,13 @@ namespace OHOS
         chatContentList->SetTouchable(true);
         chatContentList->SetDraggable(true);
         chatContentList->SetThrowDrag(true);
-        chatContentList->SetReboundSize(REBOUNDSIZE);
+        // chatContentList->SetReboundSize(REBOUNDSIZE);
         chatContentList->SetMaxScrollDistance(MAX_SCR_DIS);
         chatContentList->SetSwipeACCLevel(800); // 800: compensation distance
         chatContentList->SetDragACCLevel(5);    // 5: drag acceleration
         chatContentList->SetRotateFactor(2);
         chatContentList->RequestFocus();
-        chatContentList->SetIntercept(true);
+        // chatContentList->SetIntercept(true);
         chatContentList->SetAdapter(chatContentListAdapter);
         chatContentList->RefreshList();
         /* -------------------------------------------------------------------------- */