优化心率血氧time的更新显示逻辑
authorCaisking <3449750381@qq.com>
Tue, 7 May 2024 11:10:11 +0000 (19:10 +0800)
committerCaisking <3449750381@qq.com>
Tue, 7 May 2024 11:10:11 +0000 (19:10 +0800)
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenView.h
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp
code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h
code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartPresenter.h
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp

index e23bf5b..3324fe3 100644 (file)
@@ -28,6 +28,8 @@ namespace OHOS
         MAX_BLOODVIEW,
     } BLOODVIEWID;
 
+  
+
     class BloodOxygenView;
     class BloodOxygenPresenter : public Presenter<BloodOxygenView>,
                                  public UIView::OnClickListener,
@@ -51,7 +53,7 @@ namespace OHOS
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         uint64_t GetCurrentTime();
-        std::string GetTDOA(uint64_t new_time, uint64_t old_time);
+        int GetTDOA(uint64_t new_time, uint64_t old_time);
 
     private:
         bool CheckPointersValue(void);
index d654824..35db087 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-04-18 10:23:54
@@ -31,6 +31,7 @@
 #include "bloodoxygen/include/BloodBandoffView.h"
 #include "bloodoxygen/include/BloodCheckView.h"
 #include "bloodoxygen/include/BloodResultView.h"
+#include "components/ui_label_button_ext.h"
 
 #include "power_display_service.h"
 namespace OHOS
@@ -50,7 +51,7 @@ namespace OHOS
         void OnTearDownView() override;
         void OnStart() override;
         static BloodOxygenView *GetInstance(void);
-        
+
         bool ChangeBloodView(int16_t thisview); // 主视图
         bool ChangeBandoffView(int16_t thisview);
         bool ChangeCheckView(int16_t thisview);
@@ -60,13 +61,14 @@ namespace OHOS
         void ChangeView(int16_t hideView, int16_t showView);
         UIScrollView *GetBloodScrollView(int ViewId);
         void UpBloodText();
+
     private:
         // 增加图片
         bool InitImageDisplay(void);
         // 初始化标签
         bool InitLabel(void);
         // 添加label按键
-        UILabelButton *CreateAndSetUIButton(const char *title);
+        UILabelButtonExt *CreateAndSetUIButton(const char *title);
         // 初始化界面
         bool InitBloodView(void);
         bool SetOnDragListener(void);
@@ -77,11 +79,11 @@ namespace OHOS
         UIScrollView *BloodScrollView[4]{nullptr};
 
         UIViewGroup *group;
-        UIImageView *imageViewMain; // 背景图片
-        UILabel *percent;           // 心率值
-        UILabel *timeLabel;         // 检测时间
-        UILabel *titleLabel;        // 页面title
-        UILabelButton *testButton;  // 检测按键
+        UIImageView *imageViewMain;   // 背景图片
+        UILabelExt *percent;          // 心率值
+        UILabelExt *timeLabel;        // 检测时间
+        UILabelExt *titleLabel;       // 页面title
+        UILabelButtonExt *testButton; // 检测按键
 
         const power_display_svr_api_t *display_api = power_display_svr_get_api();
         uint32_t display_time;
index c290b75..5b5d4e0 100644 (file)
@@ -62,32 +62,15 @@ namespace OHOS
     }
 
     // 获取时间差,现在传进来的是两个时间戳
-    std::string BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+    int BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
     {
         if (new_time == old_time || old_time > new_time)
         {
-            return "刚刚";
+            return 0;
         }
 
         int time_diff = new_time - old_time;
-        if (time_diff > 60)
-        {
-            int hours = time_diff / 60;
-            int minutes = time_diff % 60;
-            std::stringstream ss;
-            ss << hours << "小时";
-            if (minutes > 0)
-            {
-                ss << minutes << "分钟";
-            }
-            return ss.str() + "前";
-        }
-        else
-        {
-            std::stringstream ss;
-            ss << time_diff << "分钟前";
-            return ss.str();
-        }
+        return time_diff;
     }
 
     /* -------------------------------------------------------------------------- */
index 9d13e05..c6bced8 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-05-07 18:22:47
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp
+ */
 /*
  * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
  * Description: bloodOxygen view
@@ -10,6 +16,7 @@
 #include "bloodoxygen/include/BloodOxygenPresenter.h"
 #include "displaybrightness/include/DisplayBrightnessModel.h"
 #include "power_display_service.h"
+#include "uicomponents/UIComponents.h"
 namespace OHOS
 {
     // 按钮设置
@@ -75,22 +82,35 @@ namespace OHOS
     void BloodOxygenView::UpBloodText()
     {
         // 更新血氧数据
-        uint16_t spo2_ = BloodOxygenModel::GetInstance()->GetSPO2data();
-        if (spo2_ != 0) // 判断是否为默认数据
+        uint16_t spo2 = BloodOxygenModel::GetInstance()->GetSPO2data();
+        if (spo2 != 0) // 判断是否为默认数据
         {
             // 更新数据
-            std::string bloodoxygenStr = std::to_string(spo2_);
+            std::string bloodoxygenStr = std::to_string(spo2);
             percent->SetText(bloodoxygenStr.c_str());
-            //  更新时间
+            
+            // 获取时间差
             uint32_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();
             uint32_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();
-            std::string TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-            timeLabel->SetText(TimeStr.c_str());
+            int time_diff = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time);
+
+            if (time_diff == 0)
+            {
+                timeLabel->SetTextId(STR_CHECKNEW);
+            }
+            else if (time_diff <= 60)
+            {
+                UpdateLabel(timeLabel, time_diff);
+            }
+            else
+            {
+                timeLabel->SetTextId(STR_CHECKLONG);
+            }
         }
         else
         {
             percent->SetText("--");
-            timeLabel->SetText("暂无检测结果");
+            timeLabel->SetTextId(STR_CHECKNO);
         }
     }
 
@@ -101,7 +121,7 @@ namespace OHOS
         std::string bloodoxygenStr;
         std::string TimeStr;
 
-        percent = new UILabel();
+        percent = new UILabelExt();
         if (percent == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new percent fail");
@@ -111,28 +131,12 @@ namespace OHOS
         percent->Resize(200, 200);                  // widget's width and height
         percent->SetViewId("label2");               // Set style
         percent->SetStyle(STYLE_TEXT_FONT, PERCENT_FONT_SIZE);
-        uint16_t spo2_ = BloodOxygenModel::GetInstance()->GetSPO2data();
-        if (spo2_ != 0)
-        {
-            bloodoxygenStr = std::to_string(spo2_);
-            // 更新时间
-            uint64_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();
-            uint64_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time:%lld check_time:%lld", time, check_time);
-            TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-        }
-        else
-        {
-            percent->SetText("--");
-            TimeStr = "暂无测量数据";
-        }
         percent->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
         percent->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         percent->SetRollSpeed(0);
         percent->SetFont(DEFAULT_VECTOR_FONT_FILENAME, PERCENT_FONT_SIZE);
-        percent->SetText(bloodoxygenStr.c_str());
         /* -------------------------------------------------------------------------- */
-        timeLabel = new UILabel();
+        timeLabel = new UILabelExt();
         if (timeLabel == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new timeLabel fail");
@@ -142,15 +146,14 @@ namespace OHOS
         timeLabel->Resize(280, 100);                      // widget's width and height
         timeLabel->SetViewId("label1");                   // Set style
         timeLabel->SetStyle(STYLE_TEXT_FONT, TIMELABEL_FONT_SIZE);
-        /* -------------------------------------------------------------------------- */
-        timeLabel->SetText(TimeStr.c_str());
-        /* -------------------------------------------------------------------------- */
         timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
         timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         timeLabel->SetRollSpeed(0);
         timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMELABEL_FONT_SIZE);
-        /* -------------------------------------------------------------------------- */
-        titleLabel = new UILabel();
+
+        UpBloodText();
+
+        titleLabel = new UILabelExt();
         if (titleLabel == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new titleLabel fail");
@@ -160,7 +163,7 @@ namespace OHOS
         titleLabel->Resize(200, 90);               // widget's width and height
         titleLabel->SetViewId("label3");           // Set style
         titleLabel->SetStyle(STYLE_TEXT_FONT, TITLE_FONT_SIZE);
-        titleLabel->SetText("血氧饱和度");
+        titleLabel->SetTextId(STR_BLOOD);
         titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
         titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         titleLabel->SetRollSpeed(0);
@@ -169,10 +172,10 @@ namespace OHOS
         return true;
     }
     // 创建标签按键
-    UILabelButton *BloodOxygenView::CreateAndSetUIButton(const char *title)
+    UILabelButtonExt *BloodOxygenView::CreateAndSetUIButton(const char *title)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::CreateAndSetUIButton");
-        UILabelButton *btn = new UILabelButton();
+        UILabelButtonExt *btn = new UILabelButtonExt();
         if (btn == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new UILabelButton fail");
@@ -180,7 +183,7 @@ namespace OHOS
         }
         btn->SetPosition(TESTBUTTON_X, TESTBUTTON_Y, BUTTON_WIDHT2, BUTTON_HEIGHT2);
         btn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffcd492c);
-        btn->SetText(title);
+        btn->SetTextId(STR_CHECK);
         // btn->SetTextColor(Color::Red());
         btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
         btn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
index 192cca7..6f8acc6 100644 (file)
@@ -1,7 +1,7 @@
 /*** 
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-05-07 17:00:01
+ * @LastEditTime: 2024-05-07 18:46:22
  * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h
  */
 /*** 
index 8e403a4..970ae3e 100644 (file)
@@ -50,7 +50,7 @@ namespace OHOS
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         uint64_t GetCurrentTime();
-        std::string GetTDOA(uint64_t new_time, uint64_t old_time);
+        int GetTDOA(uint64_t new_time, uint64_t old_time);
 
     private:
         bool CheckPointersValue(void);
index 929a961..3235812 100644 (file)
@@ -53,32 +53,15 @@ namespace OHOS
         return current_time;
     }
 
-    std::string HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+    int HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
     {
         if (new_time == old_time || old_time > new_time)
         {
-            return "刚刚";
+            return 0;
         }
 
         int time_diff = new_time - old_time;
-        if (time_diff > 60)
-        {
-            int hours = time_diff / 60;
-            int minutes = time_diff % 60;
-            std::stringstream ss;
-            ss << hours << "小时";
-            if (minutes > 0)
-            {
-                ss << minutes << "分钟";
-            }
-            return ss.str() + "前";
-        }
-        else
-        {
-            std::stringstream ss;
-            ss << time_diff << "分钟前";
-            return ss.str();
-        }
+        return time_diff;
     }
 
     HeartPresenter::HeartPresenter()
index 0c54815..fac88cc 100644 (file)
@@ -82,28 +82,38 @@ namespace OHOS
     }
     void HeartView::UpHeartText()
     {
-        // 更新血氧数据
-        uint64_t heart_ = HeartModel::GetInstance()->GetHeartdata();
-        std::string heartStr;
-        std::string TimeStr;
-        if (heart_ != 0) // 判断是否为默认数据
+        // 更新心率数据
+        uint8_t heart = HeartModel::GetInstance()->GetHeartdata();
+        if (heart != 0) // 判断是否为默认数据
         {
-            heartStr = std::to_string(heart_);
-            // 更新时间
-            uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime();
-            uint64_t check_time = HeartModel::GetInstance()->GetCheckTime();
-            TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-            // timeLabel->SetText(TimeStr.c_str());
-            timeLabel->SetTextId(STR_CHECKTIME);
-            UpdateLabel(timeLabel, TimeStr);
+            // 更新心率数据
+            std::string heartStr = std::to_string(heart);
+            percent->SetText(heartStr.c_str());
+
+            // 获取时间差
+            uint32_t time = HeartPresenter::GetInstance()->GetCurrentTime();
+            uint32_t check_time = HeartModel::GetInstance()->GetCheckTime();
+            int time_diff = HeartPresenter::GetInstance()->GetTDOA(time, check_time);
+
+            // 更新时间标签
+            if (time_diff == 0)
+            {
+                timeLabel->SetTextId(STR_CHECKNEW);
+            }
+            else if (time_diff <= 60)
+            {
+                UpdateLabel(timeLabel, time_diff);
+            }
+            else
+            {
+                timeLabel->SetTextId(STR_CHECKLONG);
+            }
         }
         else
         {
-            heartStr = "--";
-            // TimeStr = "暂无检测记录";
+            percent->SetText("--");
             timeLabel->SetTextId(STR_CHECKNO);
         }
-        percent->SetText(heartStr.c_str());
     }
 
     // 初始化标签
@@ -157,28 +167,8 @@ namespace OHOS
         titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         titleLabel->SetRollSpeed(0);
         titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE);
-        /* -------------------------------------------------------------------------- */
-        uint64_t heart_ = HeartModel::GetInstance()->GetHeartdata();
-        std::string heartStr;
-        std::string TimeStr;
-        if (heart_ != 0) // 判断是否为默认数据
-        {
-            heartStr = std::to_string(heart_);
-            // 更新时间
-            uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime();
-            uint64_t check_time = HeartModel::GetInstance()->GetCheckTime();
-            TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-            // timeLabel->SetText(TimeStr.c_str());
-            timeLabel->SetTextId(STR_CHECKTIME);
-            UpdateLabel(timeLabel, TimeStr);
-        }
-        else
-        {
-            heartStr = "--";
-            // TimeStr = "暂无检测记录";
-            timeLabel->SetTextId(STR_CHECKNO);
-        }
-        percent->SetText(heartStr.c_str());
+
+        UpHeartText();
         /* -------------------------------------------------------------------------- */
         return true;
     }