#659 手表,睡醒后滑动到睡眠界面,期望能刷新睡眠时长,目前睡眠刷新不知道是什么时候刷新
authorCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 07:04:28 +0000 (15:04 +0800)
committerCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 07:04:28 +0000 (15:04 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp

index 37af6ea..b628dd6 100644 (file)
@@ -121,6 +121,7 @@ namespace OHOS
         bool DeleteSleepData();                      // 清空睡眠文件
 
         void UpdateSleepView();
+        std::string GetUpdateSleepTime();
 
         /*定时器相关*/
         void Sleep_StartTimer(uint32_t interval);
@@ -150,6 +151,8 @@ namespace OHOS
         std::string goalsleepStr{"--"};
         std::string goalwakeStr{"--"};
 
+        std ::string sleep_time_str{"--"};
+
         int sleep_total_time = 0;
         int goal_total_time = 0;
 
index 2d4214f..ceec62f 100644 (file)
@@ -46,7 +46,8 @@ namespace OHOS
 
         UILabel *time_hour{nullptr};   // 睡眠时间[小时]
         UILabel *time_minute{nullptr}; // 睡眠时间[分钟]
-        UILabelExt *goaltime{nullptr}; // 目标时间
+
+        UILabelExt *sleep_update_time{nullptr}; // 目标时间
 
         UIImageView *roomimage{nullptr};
         UIImageView *upiconimage{nullptr};
index a96f721..2bca0fc 100644 (file)
@@ -59,6 +59,15 @@ namespace OHOS
     static uint32_t sleep_update_timestamp = 0;
     static uint32_t nap_update_timestamp = 0;
 
+    /*获取最新睡眠时间戳*/
+    uint32_t get_sleep_update_timestamp(void)
+    {
+        if(nap_update_timestamp<=sleep_update_timestamp)
+            return sleep_update_timestamp;
+        else
+            return nap_update_timestamp;
+    }
+
     bool save_nap_data(NAP_T *data)
     {
         struct stat info;
@@ -426,10 +435,12 @@ namespace OHOS
         data->wake_up_timestamp =wake_up_timestamp;
         data->total_time = total_time;
 
+        sleep_update_timestamp = wake_up_timestamp;
+
         fclose(fp);
         
         return true;
-}
+    }
 
     void set_sleep_data(SLEEP_T *data)
     {
@@ -625,6 +636,15 @@ namespace OHOS
 
         return true;
     }
+    std::string SleepModel::GetUpdateSleepTime()
+    {
+        sleep_time_str.clear();
+        // 获取睡眠最新时间
+        uint32_t sleep_time = get_sleep_update_timestamp();
+        // 获取时间戳
+        update_time_info(sleep_time, sleep_time_str);
+        return sleep_time_str;
+    }
     void SleepModel::update_sleep(SLEEP_T *data)
     {
         if (data == nullptr)
index de2224a..1bf6c20 100644 (file)
@@ -72,12 +72,17 @@ namespace OHOS
             circleProgress_->SetValue(progress_value * 100); // 更新进度条值,范围为 0 到 100
             circleProgress_->SetCapType(CAP_ROUND);
         }
-        // 更新目标时间
-        if (goaltime != nullptr)
-        {
-            UpdateLabel(goaltime, sleep_goal, STR_SLEEPMGOAL);
+        // 更新时间  
+        if (sleep_update_time != nullptr)  
+        {  
+            std::string update_time = sleepModel.GetUpdateSleepTime();  
+            if (!update_time.empty()) // 检查返回值是否有效  
+            {  
+                std::string update_time_str = update_time + " 更新"; // 拼接字符串  
+                sleep_update_time->SetText(update_time_str.c_str());  
+                // UpdateLabel(sleep_update_time, sleep_goal, STR_SLEEPMGOAL); // TODO: 多国语言支持  
+            }  
         }
-
         // 刷新视图
         RootView::GetInstance()->Invalidate();
     }
@@ -100,10 +105,10 @@ namespace OHOS
             delete time_minute;
             time_minute = nullptr;
         }
-        if (goaltime != nullptr)
+        if (sleep_update_time != nullptr)
         {
-            delete goaltime;
-            goaltime = nullptr;
+            delete sleep_update_time;
+            sleep_update_time = nullptr;
         }
         if (roomimage != nullptr)
         {
@@ -142,8 +147,8 @@ namespace OHOS
         InitImageView(upiconimage, 213, 360, 40, 40, "image", upimagePath);
         InitImageView(progress_image, 28, 80, 100, 100, "image", prossimagePath);
         /*初始化目标时间*/
-        InitLabelExt(goaltime, 83, 330, 300, 35, "lablegoal", STR_SLEEPMGOAL, DEFAULT_VECTOR_FONT_FILENAME, 30);
-        goaltime->SetTextColor(Color::Gray());
+        InitLabelExt(sleep_update_time, 83, 330, 300, 35, "lablegoal", STR_SLEEPMGOAL, DEFAULT_VECTOR_FONT_FILENAME, 30);
+        sleep_update_time->SetTextColor(Color::Gray());
         /*初始化睡眠时间*/
         time_hour = new UILabel();
         time_hour->SetPosition(84, 237);
@@ -194,7 +199,7 @@ namespace OHOS
         Add(minute);
         Add(time_hour);
         Add(time_minute);
-        Add(goaltime);
+        Add(sleep_update_time);
         Add(upiconimage);
         Add(roomimage);