增加充值操作
authorxue <2144439972@qq.com>
Sat, 27 Sep 2025 07:40:23 +0000 (15:40 +0800)
committerxue <2144439972@qq.com>
Sat, 27 Sep 2025 07:40:23 +0000 (15:40 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp

index 235b07f..0576b38 100644 (file)
@@ -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);
         
index 948b268..c7c29a7 100644 (file)
@@ -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,      // 音量调节
index 7f81c0b..4a48013 100644 (file)
         // 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)
    {
        // 参数验证
index db9333d..8c95b14 100644 (file)
@@ -447,6 +447,12 @@ namespace OHOS
         }
     }
 
+    void ThunderBirdReminderView::UpdateTaskReminderText(const char* text)
+    {
+        TextLabel->SetText(text);
+        TextLabel->Invalidate();
+    }
+
 }
 
 
index bd0bdac..0b02629 100644 (file)
@@ -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<char*>(request->data), request->len);
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandChatStaminaNotify payload = %s", payload.c_str());
-    // TODO: UI 可在此解析并展示(或直接将payload转交ThunderBirdModel)
+    
+    // 解析各个字段
+    std::vector<std::string> 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());
+            }
+        });
 }
 
 /* -------------------------------------------------------------------------- */