* @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
#include "View.h"
#include "ui_resource_string.h"
#include "components/ui_time_picker.h"
+#include "ModelListenerSample.h"
namespace OHOS
{
class AiVoiceView;
public UIView::OnDragListener,
public RootView::OnKeyActListener,
public UIPicker::SelectedListener,
- public UIView::OnTouchListener
+ public UIView::OnTouchListener,
+ public ModelListenerSample
{
public:
typedef enum : uint8_t
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);
AiVoiceModel *model;
bool X_DRAG_FLAG{false};
+
+ int preHeight{0};
+ bool isScroll{false};
};
}
* @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"
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
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); // 重新常亮屏
}
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秒超时
* @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"
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
{
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模型就切换模型*/
{
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
* @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"
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();
/* -------------------------------------------------------------------------- */