训练记录修改析构适配
authorCaisking <3449750381@qq.com>
Sat, 10 Aug 2024 03:52:26 +0000 (11:52 +0800)
committerCaisking <3449750381@qq.com>
Sat, 10 Aug 2024 03:52:26 +0000 (11:52 +0800)
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp

index b91e8da..3b8a85d 100644 (file)
@@ -29,7 +29,10 @@ namespace OHOS
 
     TraingRecordView::~TraingRecordView()
     {
-        DeInit();
+        // DeInit();
+        UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
+        UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+
         g_pTraingRecordView = nullptr;
     }
 
@@ -63,6 +66,7 @@ namespace OHOS
     /* DeInit:删除组件 */
     void TraingRecordView::DeInit()
     {
+
         lackView->RemoveAll();
         recordView->RemoveAll();
 
@@ -127,7 +131,10 @@ namespace OHOS
         lackView->Add(imagerecord);
         lackView->Add(buttongo);
 
-        RootView::GetInstance()->Add(lackView);
+        // RootView::GetInstance()->lackView
+        container_->Add(lackView);
+        printf("lackView Add\r\n");
+
         lackView->SetDraggable(true);
         lackView->SetTouchable(true);
 
@@ -150,7 +157,7 @@ namespace OHOS
             return;
         }
         recordView->SetPosition(0, 0);
-        recordView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION);
+        recordView->Resize(466, 466);
         recordView->SetScrollBlankSize(20);
         recordView->SetReboundSize(50);
         recordView->SetDirection(1);
@@ -192,27 +199,19 @@ namespace OHOS
     void TraingRecordView::SetPopupViewStatus(PopupRecord view, bool status)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPopupViewStatus %d", view);
-        UIView *popupView = nullptr;
+
         if (view == PopupRecord::LackPopup)
         {
             TraingRecordModel::GetInstance().SetPopupView(false); // 设置状态为无训练记录
-            popupView = lackView;
+            lackView->SetVisible(true);                           // 隐藏界面
+            recordView->SetVisible(false);                        // 隐藏界面
         }
         else if (view == PopupRecord::RecordPopup)
         {
             TraingRecordModel::GetInstance().SetPopupView(true); // 设置状态为有训练记录
-            popupView = recordView;
-        }
-        if (popupView == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PopupView is NULL");
-            return;
-        }
-        if (container_ != nullptr)
-        {
-            container_->SetVisible(!status);
+            lackView->SetVisible(false);                         // 隐藏界面
+            recordView->SetVisible(true);                        // 隐藏界面
         }
-        popupView->SetVisible(status);
     }
     // 获取目前的view
     void TraingRecordView::OnStart()
@@ -226,13 +225,8 @@ namespace OHOS
             return;
         }
         container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        // 创建 draglistener 实例并设置为拖动监听器
-        UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(TraingRecordPresenter::GetInstance());
-        if (draglistener == nullptr)
-        {
-            return;
-        }
-        container_->SetOnDragListener(draglistener);
+
+        container_->SetOnDragListener(presenter_);
         container_->SetTouchable(true);
         container_->SetDraggable(true);
         container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
@@ -241,8 +235,9 @@ namespace OHOS
         ShowLackView();
         ShowRecordView();
         PreLoad();
-        RootView::GetInstance()->Add(container_);
+
         SetContainerView(container_);
+
         // 增加按键监听
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingRecordPresenter::GetInstance();
         RootView::GetInstance()->SetOnKeyActListener(keyactListener);
@@ -258,7 +253,8 @@ namespace OHOS
         {
             recordView->Add(TraingRecordList);
             recordView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
-            RootView::GetInstance()->Add(recordView);
+            container_->Add(recordView);
+            printf("recordView Add\r\n");
             TraingRecordList->SetAdapter(p_TraingRecordAdapter);
         }
         Draw();