~BPCalibSecondDoneView();
static BPCalibSecondDoneView *GetInstance();
UIViewGroup *InitView();
+ void UpdateExpiryText();
private:
UIViewGroup *group_{nullptr};
~BPEntryView();
static BPEntryView *GetInstance();
UIViewGroup *InitView();
+ void RefreshView();
void InitCalibratedView();
void InitCalibrationExpiredView();
void InitNotCalibratedView();
void InitPageIndicator();
private:
+ void ResetContent();
void InitCalibExpiringSoonBar();
void InitNoCalibratedBar();
/** 校准完成后写入当前时间戳与校准值 */
bool SaveCalibrationResult();
int32_t GetCalibrationTimestamp() const;
+ /** 校准到期日 YYYY/MM/DD,无效时返回 "--" */
+ std::string GetCalibrationExpiryDateText() const;
/** 校准有效期(秒),默认 30 天,与 fd230 needMeasure 一致 */
void SetCalibrationTimeoutSec(uint32_t seconds);
#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 {
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());
group_->Add(timeLabel_);
group_->Add(noteLabel_);
group_->Add(confirmButton_);
+ UpdateExpiryText();
return group_;
}
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();
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();
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();
historyView_->RefreshView();
historyView_->StartArrowAnimation();
}
+ if (showView == BP_ENTRY_VIEW && entryView_ != nullptr) {
+ entryView_->RefreshView();
+ }
RefreshCurrentView();
container_->Invalidate();
}
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) {