修复校准完成有效期显示bug
authorxue <2144439972@qq.com>
Thu, 11 Jun 2026 03:11:31 +0000 (11:11 +0800)
committerxue <2144439972@qq.com>
Thu, 11 Jun 2026 03:11:31 +0000 (11:11 +0800)
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPCalibSecondDoneView.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPEntryView.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPModel.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPCalibSecondDoneView.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPEntryView.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainView.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPModel.cpp

index 6858450..e66264a 100644 (file)
@@ -26,12 +26,14 @@ public:
   ~BPEntryView();
   static BPEntryView *GetInstance();
   UIViewGroup *InitView();
+  void RefreshView();
   void InitCalibratedView();
   void InitCalibrationExpiredView();
   void InitNotCalibratedView();
   void InitPageIndicator();
 
 private:
+  void ResetContent();
   void InitCalibExpiringSoonBar();
   void InitNoCalibratedBar();
 
index 554db62..c43be74 100644 (file)
@@ -39,6 +39,8 @@ public:
   /** 校准完成后写入当前时间戳与校准值 */
   bool SaveCalibrationResult();
   int32_t GetCalibrationTimestamp() const;
+  /** 校准到期日 YYYY/MM/DD,无效时返回 "--" */
+  std::string GetCalibrationExpiryDateText() const;
 
   /** 校准有效期(秒),默认 30 天,与 fd230 needMeasure 一致 */
   void SetCalibrationTimeoutSec(uint32_t seconds);
index f55999b..4f1f52f 100644 (file)
@@ -1,7 +1,9 @@
 #include "bloodpressure/include/BPCalibSecondDoneView.h"
 #include "bloodpressure/include/BPEntryView.h"
 #include "bloodpressure/include/BPMainPresenter.h"
+#include "bloodpressure/include/BPModel.h"
 #include "bloodpressure/include/BPViewClickIds.h"
+#include "securec.h"
 #include "uicomponents/UIComponents.h"
 
 namespace OHOS {
@@ -31,6 +33,24 @@ BPCalibSecondDoneView::~BPCalibSecondDoneView() {
 
 BPCalibSecondDoneView *BPCalibSecondDoneView::GetInstance() { return g_instance; }
 
+void BPCalibSecondDoneView::UpdateExpiryText() {
+  if (timeLabel_ == nullptr) {
+    return;
+  }
+  BPModel *model = BPModel::GetInstance();
+  if (model == nullptr) {
+    timeLabel_->SetText("有效期至:----");
+    return;
+  }
+  char textBuf[48] = {0};
+  if (sprintf_s(textBuf, sizeof(textBuf), "有效期至:%s",
+                model->GetCalibrationExpiryDateText().c_str()) < 0) {
+    timeLabel_->SetText("有效期至:----");
+    return;
+  }
+  timeLabel_->SetText(textBuf);
+}
+
 UIViewGroup *BPCalibSecondDoneView::InitView() {
   group_ = new UIViewGroup();
   group_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
@@ -54,6 +74,7 @@ UIViewGroup *BPCalibSecondDoneView::InitView() {
   group_->Add(timeLabel_);
   group_->Add(noteLabel_);
   group_->Add(confirmButton_);
+  UpdateExpiryText();
   return group_;
 }
 
index dc9cc3c..cbb9828 100644 (file)
@@ -46,6 +46,49 @@ BPEntryView::~BPEntryView() {
 
 BPEntryView *BPEntryView::GetInstance() { return g_pBPEntryView; }
 
+void BPEntryView::ResetContent() {
+  if (group_ != nullptr) {
+    group_->RemoveAll();
+  }
+  delete titleLabel_;
+  delete instructionLabel_;
+  delete instructionButton_;
+  delete measureButton_;
+  delete imageView_;
+  delete calibWarnBg_;
+  delete calibWarnIcon_;
+  delete calibWarnLabel_;
+  delete dotEntry_;
+  delete dotHistory_;
+  titleLabel_ = nullptr;
+  instructionLabel_ = nullptr;
+  instructionButton_ = nullptr;
+  measureButton_ = nullptr;
+  imageView_ = nullptr;
+  calibWarnBg_ = nullptr;
+  calibWarnIcon_ = nullptr;
+  calibWarnLabel_ = nullptr;
+  dotEntry_ = nullptr;
+  dotHistory_ = nullptr;
+}
+
+void BPEntryView::RefreshView() {
+  if (group_ == nullptr) {
+    return;
+  }
+  ResetContent();
+  currentState_ = BPModel::GetInstance()->GetCurrentstate();
+  if (currentState_ == BP_CALIB_STATE_VALID) {
+    InitCalibratedView();
+  } else if (currentState_ == BP_CALIB_STATE_EXPIRED) {
+    InitCalibrationExpiredView();
+  } else {
+    InitNotCalibratedView();
+  }
+  InitPageIndicator();
+  group_->Invalidate();
+}
+
 
 UIViewGroup *BPEntryView::InitView() {
   group_ = new UIViewGroup();
index 8e7ada6..069966d 100644 (file)
@@ -94,6 +94,9 @@ void BPMainView::OnStop() {
 bool BPMainView::ChangeBPEntryView(int16_t thisView, int16_t type) {
   UNUSED(type);
   if (group_[thisView] != nullptr) {
+    if (entryView_ != nullptr) {
+      entryView_->RefreshView();
+    }
     return true;
   }
   entryView_ = new BPEntryView();
@@ -302,6 +305,9 @@ bool BPMainView::ChangeBPCalibFirstDoneView(int16_t thisView, int16_t type) {
 bool BPMainView::ChangeBPCalibSecondDoneView(int16_t thisView, int16_t type) {
   UNUSED(type);
   if (group_[thisView] != nullptr) {
+    if (calibSecondDoneView_ != nullptr) {
+      calibSecondDoneView_->UpdateExpiryText();
+    }
     return true;
   }
   calibSecondDoneView_ = new BPCalibSecondDoneView();
@@ -375,6 +381,9 @@ void BPMainView::ChangeView(int16_t hideView, int16_t showView, int16_t type) {
     historyView_->RefreshView();
     historyView_->StartArrowAnimation();
   }
+  if (showView == BP_ENTRY_VIEW && entryView_ != nullptr) {
+    entryView_->RefreshView();
+  }
   RefreshCurrentView();
   container_->Invalidate();
 }
index dc34646..059f8fb 100644 (file)
@@ -172,6 +172,25 @@ bool BPModel::SaveCalibrationResult() {
 
 int32_t BPModel::GetCalibrationTimestamp() const { return calibrationTimestamp_; }
 
+std::string BPModel::GetCalibrationExpiryDateText() const {
+  if (calibrationTimestamp_ <= 0) {
+    return "--";
+  }
+  uint32_t expiryTs =
+      static_cast<uint32_t>(calibrationTimestamp_) + calibrationTimeoutSec_;
+  struct tm timeInfo = {0};
+  time_t ts = static_cast<time_t>(expiryTs);
+  if (localtime_r(&ts, &timeInfo) == nullptr) {
+    return "--";
+  }
+  char buf[32] = {0};
+  if (sprintf_s(buf, sizeof(buf), "%04d/%02d/%02d", timeInfo.tm_year + 1900,
+                timeInfo.tm_mon + 1, timeInfo.tm_mday) < 0) {
+    return "--";
+  }
+  return std::string(buf);
+}
+
 /** 设置校准有效期(秒),默认 30 天,与 fd230 needMeasure 一致 */
 void BPModel::SetCalibrationTimeoutSec(uint32_t seconds) {
   if (seconds > 0) {