修复主界面notify的刷新 3298/1 3298/head 3299/target/1 3300/target/1
authorCaisking <Casiking@zhihuishixun.com>
Fri, 20 Mar 2026 06:44:43 +0000 (14:44 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 20 Mar 2026 06:44:43 +0000 (14:44 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp

index b2bad82..9680dd3 100644 (file)
      /* --------------------------------- 主界面卡片功能 -------------------------------- */
      void MainPresenterSample::Notify(void)
      {
+        if (view_ == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Notify: view_ is nullptr");
+            return;
+        }
          CardId currentCardId = view_->GetHorCurrentCard();
  
          // 从心率卡片变为其他卡片时关闭心率检测
      {
          if (SleepCardView::GetInstance() != nullptr)
          {
-             auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
-             if (sleepCardView->GetCurrentPage() != 0)
+            auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
+            if (sleepCardView != nullptr && sleepCardView->GetCurrentPage() != 0)
              {
                  sleepCardView->SetCurrentPage(0);
              }
          if(WeatherControlView::GetInstance())
          {
              auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView();
-             if (weatherSwipView->GetCurrentPage() != 0)
+            if (weatherSwipView != nullptr && weatherSwipView->GetCurrentPage() != 0)
              {
                  weatherSwipView->SetCurrentPage(0);
              }
          if(goalControlView::GetInstance())
          {
              auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView();
-             if (goalSwipView->GetCurrentPage() != 0)
+            if (goalSwipView != nullptr && goalSwipView->GetCurrentPage() != 0)
              {
                  goalSwipView->SetCurrentPage(0);
              }
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view_ is nullptr");
             return;
+        }
+        UIView *watchFace = view_->GetViewById(WATCH_FACE);
+        if (watchFace == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateWatchFace: watchFace is nullptr");
+            return;
         }
          DialSetting &setting = GetDialSetting();
          if (setting.dialFlag)
          {
              DialModelTime::GetInstance()->UpdateTime();
-             dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
+            auto dialViewGroup = dynamic_cast<DialViewGroup *>(watchFace);
+            if (dialViewGroup == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateWatchFace: DialViewGroup cast failed");
+                return;
+            }
+            dialViewGroup->UpdateViewsByPeriodicUpdateData();
          }
          else
          {
-             dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
+            auto mainClockView = dynamic_cast<MainClockView *>(watchFace);
+            if (mainClockView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateWatchFace: MainClockView cast failed");
+                return;
+            }
+            mainClockView->UpdateTime();
          }
      }