From b175aeef8802b83346554185abdc4440ee74d07f Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Sat, 27 Sep 2025 15:40:23 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=85=85=E5=80=BC=E6=93=8D?= =?utf8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../thunderbird/include/ThunderBirdModel.h | 4 ++ .../include/ThunderBirdReminderView.h | 1 + .../thunderbird/src/ThunderBirdModel.cpp | 36 +++++++++++++++++ .../src/ThunderBirdReminderView.cpp | 6 +++ .../nativeui/uiservice/src/ui_service.cpp | 39 ++++++++++++++++++- 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index 235b07faa..0576b3863 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -172,6 +172,10 @@ namespace OHOS const char* eyesColor, const char* hairStyle, int screenImageAsEmoji); + // 聊天体力更改处理函数 + void HandleChatStaminaChange(int chatLeft, const char* chatDesc, int flowLeft, + const char* flowDesc, const char* qrcodeUrl); + // 表情切换函数 bool SwitchExpression(const char* eyeShape, const char* eyeColor); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h index 948b268ca..c7c29a7b2 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h @@ -26,6 +26,7 @@ namespace OHOS // 任务提醒文本更新接口(用于 THUNDERBIRD_REMINDERVIEW_TASK_REMINDER) void UpdateTaskReminderText(const char* title, const char* content); + void UpdateTaskReminderText(const char* text); enum : int16_t { THUNDERBIRD_REMINDERVIEW_VOLUME = 0, // 音量调节 diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index 7f81c0b0c..4a480130a 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -1514,6 +1514,42 @@ // SaveCharacterConfig(characterId, characterName, eyesShape, hairColor, eyesColor, hairStyle, screenImageAsEmoji); } + void ThunderBirdModel::HandleChatStaminaChange(int chatLeft, const char* chatDesc, int flowLeft, + const char* flowDesc, const char* qrcodeUrl) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleChatStaminaChange"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " chatLeft: %d", chatLeft); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " chatDesc: %s", chatDesc ? chatDesc : "null"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " flowLeft: %d", flowLeft); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " flowDesc: %s", flowDesc ? flowDesc : "null"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " qrcodeUrl: %s", qrcodeUrl ? qrcodeUrl : "null"); + + // 这里可以添加聊天体力更改的具体处理逻辑 + int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); + if((chatLeft < 20 && chatLeft > 0))//对话不足 + { + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_DIALOGUE_NOT_ENOUGH); + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText("对话额度不足20轮可扫码续充"); + } + else if(flowLeft < 80 && flowLeft > 0)//流量不足 + { + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_DIALOGUE_USE_UP); + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText("流量不足100M了哦扫码可重置流量"); + } + else if(chatLeft == 0)//对话用尽 + { + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_DIALOGUE_USE_UP); + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText("啊哦,对话轮数已用完,扫码续上吧"); + } + else if(flowLeft == 0)//流量用尽 + { + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_FLOW_USE_UP); + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText("流量用完了哦"); + } + + + } + bool ThunderBirdModel::SwitchExpression(const char* eyeShape, const char* eyeColor) { // 参数验证 diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp index db9333dbd..8c95b1452 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp @@ -447,6 +447,12 @@ namespace OHOS } } + void ThunderBirdReminderView::UpdateTaskReminderText(const char* text) + { + TextLabel->SetText(text); + TextLabel->Invalidate(); + } + } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index bd0bdacd7..0b026292f 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -463,13 +463,50 @@ void HandDownloadEmojiNotify(Request *request) static void HandChatStaminaNotify(Request *request) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify msg_id = %d", request->msgId); + if (request->data == nullptr || request->len <= 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify: invalid data"); return; } + + // 解析接收到的数据:聊天体力信息(以'|'分隔) + // 格式: "chatLeft|chatDesc|flowLeft|flowDesc|qrcodeUrl" std::string payload(static_cast(request->data), request->len); WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify payload = %s", payload.c_str()); - // TODO: UI 可在此解析并展示(或直接将payload转交ThunderBirdModel) + + // 解析各个字段 + std::vector fields; + std::stringstream ss(payload); + std::string field; + while (std::getline(ss, field, '|')) { + fields.push_back(field); + } + + if (fields.size() < 3) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify: invalid payload format, expected at least 3 fields, got %zu", fields.size()); + return; + } + + int chatLeft = std::stoi(fields[0]); + std::string chatDesc = fields[1]; + int flowLeft = std::stoi(fields[2]); + std::string flowDesc = (fields.size() > 3) ? fields[3] : ""; + std::string qrcodeUrl = (fields.size() > 4) ? fields[4] : ""; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify chatLeft = %d", chatLeft); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify chatDesc = %s", chatDesc.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify flowLeft = %d", flowLeft); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify flowDesc = %s", flowDesc.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify qrcodeUrl = %s", qrcodeUrl.c_str()); + + // 通过图形服务调用 ThunderBirdModel 的处理函数 + GraphicService::GetInstance()->PostGraphicEvent( + [chatLeft, chatDesc, flowLeft, flowDesc, qrcodeUrl]() { + if (OHOS::ThunderBirdModel::GetInstance()) { + OHOS::ThunderBirdModel::GetInstance()->HandleChatStaminaChange( + chatLeft, chatDesc.c_str(), flowLeft, flowDesc.c_str(), qrcodeUrl.c_str()); + } + }); } /* -------------------------------------------------------------------------- */ -- 2.17.1