修改训练记录Slice析构
authorCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 12:00:04 +0000 (20:00 +0800)
committerCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 12:00:04 +0000 (20:00 +0800)
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordAdapter.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp

index d5246dd..af44d5b 100644 (file)
@@ -1662,6 +1662,8 @@ namespace OHOS
     {
         FILE *fp;
         char *jsonStr = NULL;
+        // 创建sport文件夹
+        CreateDirectoryIfNotExists(TRAINING_DATA_DIRECTORY);    
 
         // 读取现有的 JSON 数据
         fp = fopen(TRAINING_RECORD_FILE, "r");
index 5bb2f0f..77ef5db 100644 (file)
@@ -19,6 +19,11 @@ namespace OHOS
     TraingRecordAdapter::~TraingRecordAdapter()
     {
         listData.clear();
+        if(itemClickListener)
+        {
+            delete itemClickListener;
+            itemClickListener = nullptr;
+        }
     }
 
     uint16_t TraingRecordAdapter::GetCount(void)
index f916e82..4f2fb3b 100644 (file)
@@ -24,6 +24,7 @@ namespace OHOS
         SetStyle(STYLE_BACKGROUND_OPA, 255);
         SetTouchable(true);
         SetUpChild();
+        
         Add(&sbackground);
         Add(&sicon);
         Add(&sLabeldata);
@@ -37,6 +38,7 @@ namespace OHOS
         Remove(&sLabeldata);
         Remove(&sLabeltime);
         Remove(&slogo);
+        Remove(&sicon);
     }
 
     TraingRecordItemView &TraingRecordItemView::GetInstance()
index a459d5e..0e4354c 100644 (file)
 #include "traingrecord/include/TraingRecordAdapter.h"
 #include "traingrecord/include/TraingRecordModel.h"
 
-#include "common/image_cache_manager.h"
 #include "UiConfig.h"
-#include "ui_resource_image.h"
-#include <ui_scroll_view.h>
+#include "common/image_cache_manager.h"
 #include "components/ui_button.h"
+#include "ui_resource_image.h"
 #include "uicomponents/UIComponents.h"
-namespace OHOS
-{
-    static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
-    static TraingRecordView *g_pTraingRecordView{nullptr};
-    static constexpr uint8_t NUM_2 = 2;
-    // static TraingMOREView *g_pTraingMOREView{nullptr};
-    static constexpr int16_t MORE_LIST_POSITION_X = 43;
-    static constexpr int16_t MORE_LIST_POSITION_Y = 120;
-    static constexpr int16_t MORE_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。
-    static constexpr int16 MAX_SCR_DIS = 1000;
-    static constexpr int16 LIST_POS = 20;
-    static constexpr int16 SNUM_2 = 2;
-
-    TraingRecordView::TraingRecordView()
-    {
-        g_pTraingRecordView = this;
-    }
-
-    TraingRecordView::~TraingRecordView()
-    {
-      // DeInit()
-      lackView->RemoveAll();
-      recordView->RemoveAll();
-
-      UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
-      UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
-
-      g_pTraingRecordView = nullptr;
-    }
-
-    TraingRecordView *TraingRecordView::GetInstance()
-    {
-        return g_pTraingRecordView;
-    }
-
-    /* InitView:初始化界面*/
-    void TraingRecordView ::InitView()
-    {
-        if (container_ == nullptr)
-        {
-            container_ = new UIScrollView();
-            container_->SetPosition(0, 0, 466, 466);
-            container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
-        }
-        // 展示界面
-        if (TraingRecordModel::GetInstance().GetJsonStatus())
-        {
-            printf("存在训练数据!\r\n");
-            SetPopupViewStatus(PopupRecord::RecordPopup, true);
-        }
-        else
-        {
-            printf("不存在训练数据!\r\n");
-            SetPopupViewStatus(PopupRecord::LackPopup, true);
-        }
-    }
-
-    /* DeInit:删除组件 */
-    void TraingRecordView::DeInit()
-    {
-
-        lackView->RemoveAll();
-        recordView->RemoveAll();
-
-        delete labeltitle_;
-        labeltitle_ = nullptr;
-
-        delete labelrecord_;
-        labelrecord_ = nullptr;
-
-        delete buttongo;
-        buttongo = nullptr;
-
-        delete imagerecord;
-        imagerecord = nullptr;
-
-        delete lackView;
-        lackView = nullptr;
+#include <ui_scroll_view.h>
+namespace OHOS {
+static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
+static TraingRecordView *g_pTraingRecordView{nullptr};
+static constexpr uint8_t NUM_2 = 2;
+// static TraingMOREView *g_pTraingMOREView{nullptr};
+static constexpr int16_t MORE_LIST_POSITION_X = 43;
+static constexpr int16_t MORE_LIST_POSITION_Y = 120;
+static constexpr int16_t MORE_SCROLLBLANKSIZE =
+    35; // 设置此滚动视图的空白大小。
+static constexpr int16 MAX_SCR_DIS = 1000;
+static constexpr int16 LIST_POS = 20;
+static constexpr int16 SNUM_2 = 2;
+
+TraingRecordView::TraingRecordView() { g_pTraingRecordView = this; }
+
+TraingRecordView::~TraingRecordView() {
+  DeInit();
+  //   lackView->RemoveAll();
+  //   recordView->RemoveAll();
+
+  //   UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
+  //   UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+
+  g_pTraingRecordView = nullptr;
+}
 
-        delete TraingRecordList;
-        TraingRecordList = nullptr;
+TraingRecordView *TraingRecordView::GetInstance() {
+  return g_pTraingRecordView;
+}
 
-        delete labelercord_;
-        labelercord_ = nullptr;
+/* InitView:初始化界面*/
+void TraingRecordView ::InitView() {
+  if (container_ == nullptr) {
+    container_ = new UIScrollView();
+    container_->SetPosition(0, 0, 466, 466);
+    container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
+  }
+  // 展示界面
+  if (TraingRecordModel::GetInstance().GetJsonStatus()) {
+    printf("存在训练数据!\r\n");
+    SetPopupViewStatus(PopupRecord::RecordPopup, true);
+  } else {
+    printf("不存在训练数据!\r\n");
+    SetPopupViewStatus(PopupRecord::LackPopup, true);
+  }
+}
 
-        delete recordView;
-        recordView = nullptr;
-    }
-    void TraingRecordView::PreLoad(void)
-    {
-        if (!viewiInitStatus)
-        {
-            InitView();
-            viewiInitStatus = true;
-        }
-    }
-    /*显示无记录界面*/
-    void TraingRecordView::ShowLackView()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView start");
-        lackView = new UIScrollView();
-        if (lackView == nullptr)
-        {
-            return;
-        }
-        lackView->SetPosition(0, 0);
-        lackView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION);
-        lackView->SetScrollBlankSize(20);
-        lackView->SetReboundSize(50);
-        lackView->SetDirection(1);
-        /*初始化label*/
-        InitLabelExt(labeltitle_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD, DEFAULT_VECTOR_FONT_FILENAME, 30);
-        InitLabelExt(labelrecord_, 53, 260, 360, 40, "labelrecord", STR_TRAINGNO, DEFAULT_VECTOR_FONT_FILENAME, 30);
-        /*初始化image*/
-        InitImageView(imagerecord, 174, 120, 118, 120, "image", RECOED_IMAGE);
-        /*初始化按键*/
-        InitButtonExt(buttongo, 93, 330, 280, 90, BUTTONGO, STR_TRAINGGO, 30);
-        buttongo->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); // 设置按键颜色
-        buttongo->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingRecordPresenter::GetInstance()));
-
-        lackView->Add(labeltitle_);
-        lackView->Add(labelrecord_);
-        lackView->Add(imagerecord);
-        lackView->Add(buttongo);
-
-        // RootView::GetInstance()->lackView
-        container_->Add(lackView);
-        printf("lackView Add\r\n");
-
-        lackView->SetDraggable(true);
-        lackView->SetTouchable(true);
-
-        UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(TraingRecordPresenter::GetInstance());
-        if (draglistener == nullptr)
-        {
-            return;
-        }
-        lackView->SetOnDragListener(draglistener);
-        lackView->SetVisible(false); // 界面隐藏
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView end");
-    }
-    /*记录列表界面*/
-    void TraingRecordView::ShowRecordView()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView start");
-        recordView = new UIScrollView();
-        if (recordView == nullptr)
-        {
-            return;
-        }
-        recordView->SetPosition(0, 0);
-        recordView->Resize(466, 466);
-        recordView->SetScrollBlankSize(50);
-        // recordView->SetReboundSize(50);
-        recordView->SetDirection(1);
-
-        /*初始化label*/
-        InitLabelExt(labelercord_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD, DEFAULT_VECTOR_FONT_FILENAME, 30);
-        recordView->Add(labelercord_);
-
-        // UIList 的适配器
-        p_TraingRecordAdapter = new TraingRecordAdapter();
-        p_TraingRecordAdapter->SetItemClickListener(presenter_);
-        if (TraingRecordList == nullptr)
-        {
-            TraingRecordList = new UIList();
-        }
-        TraingRecordList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466, 466);
-        TraingRecordList->SetScrollStateListener(this);
-        TraingRecordList->SetThrowDrag(true);
-        TraingRecordList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
-        // 设置手指抬起屏幕后的最大滚动距离
-        TraingRecordList->SetMaxScrollDistance(1000);
-        // 设置手指抬起屏幕后的补偿距离
-        TraingRecordList->SetSwipeACCLevel(800);
-        // 设置拖动加速
-        TraingRecordList->SetDragACCLevel(5);
-        TraingRecordList->SetYScrollBarVisible(true);
-        recordView->SetVisible(false); // 隐藏界面
-        TraingRecordList->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingRecordPresenter::GetInstance()));
-
-        UIView::OnDragListener *recorddraglistener = static_cast<UIView::OnDragListener *>(TraingRecordPresenter::GetInstance());
-        if (recorddraglistener == nullptr)
-        {
-            return;
-        }
-        recordView->SetOnDragListener(recorddraglistener);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView end");
-    }
-    /*控制显示界面*/
-    void TraingRecordView::SetPopupViewStatus(PopupRecord view, bool status)
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPopupViewStatus %d", view);
-
-        if (view == PopupRecord::LackPopup)
-        {
-            TraingRecordModel::GetInstance().SetPopupView(false); // 设置状态为无训练记录
-            lackView->SetVisible(true);                           // 隐藏界面
-            recordView->SetVisible(false);                        // 隐藏界面
-        }
-        else if (view == PopupRecord::RecordPopup)
-        {
-            TraingRecordModel::GetInstance().SetPopupView(true); // 设置状态为有训练记录
-            lackView->SetVisible(false);                         // 隐藏界面
-            recordView->SetVisible(true);                        // 隐藏界面
-        }
-    }
-    // 获取目前的view
-    void TraingRecordView::OnStart()
-    {
-        View<TraingRecordPresenter>::OnStart();
-
-        container_ = new UIScrollView();
-        if (container_ == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
-            return;
-        }
-        container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-
-        container_->SetOnDragListener(presenter_);
-        container_->SetTouchable(true);
-        container_->SetDraggable(true);
-        container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
-        container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
-
-        ShowLackView();
-        ShowRecordView();
-        PreLoad();
-
-        SetContainerView(container_);
-
-        // 增加按键监听
-        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingRecordPresenter::GetInstance();
-        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
-    }
-    void TraingRecordView::AddToTraingRecordList(const TraingRecordItem &item)
-    {
-        p_TraingRecordAdapter->AddItem(item);
+/* DeInit:删除组件 */
+void TraingRecordView::DeInit() {
+  if (container_) {
+    container_->RemoveAll();
+  }
+  if (lackView) {
+    lackView->RemoveAll();
+  }
+
+  if (recordView) {
+    recordView->RemoveAll();
+  }
+
+  if (labeltitle_) {
+    delete labeltitle_;
+    labeltitle_ = nullptr;
+  }
+
+  if (labelrecord_) {
+    delete labelrecord_;
+    labelrecord_ = nullptr;
+  }
+
+  if (buttongo) {
+    delete buttongo;
+    buttongo = nullptr;
+  }
+
+  if (imagerecord) {
+    delete imagerecord;
+    imagerecord = nullptr;
+  }
+
+  if (lackView) {
+    delete lackView;
+    lackView = nullptr;
+  }
+
+  if (TraingRecordList) {
+    delete TraingRecordList;
+    TraingRecordList = nullptr;
+  }
+
+  if (p_TraingRecordAdapter) {
+    delete p_TraingRecordAdapter;
+    p_TraingRecordAdapter = nullptr;
+  }
+
+  if (labelercord_) {
+    delete labelercord_;
+    labelercord_ = nullptr;
+  }
+
+  if (recordView) {
+    delete recordView;
+    recordView = nullptr;
+  }
+}
+void TraingRecordView::PreLoad(void) {
+  if (!viewiInitStatus) {
+    InitView();
+    viewiInitStatus = true;
+  }
+}
+/*显示无记录界面*/
+void TraingRecordView::ShowLackView() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView start");
+  if (lackView == nullptr) {
+    lackView = new UIScrollView();
+    if (lackView == nullptr) {
+      return;
     }
-    void TraingRecordView::OnSetUpView()
-    {
-        View<TraingRecordPresenter>::OnSetUpView();
-        if (TraingRecordModel::GetInstance().GetJsonStatus())
-        {
-            recordView->Add(TraingRecordList);
-            recordView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
-            container_->Add(recordView);
-            printf("recordView Add\r\n");
-            TraingRecordList->SetAdapter(p_TraingRecordAdapter);
-        }
-        Draw();
+    lackView->SetPosition(0, 0);
+    lackView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION);
+    lackView->SetScrollBlankSize(20);
+    lackView->SetReboundSize(50);
+    lackView->SetDirection(1);
+  }
+
+  /*初始化label*/
+  InitLabelExt(labeltitle_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  InitLabelExt(labelrecord_, 53, 260, 360, 40, "labelrecord", STR_TRAINGNO,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  /*初始化image*/
+  InitImageView(imagerecord, 174, 120, 118, 120, "image", RECOED_IMAGE);
+  /*初始化按键*/
+  InitButtonExt(buttongo, 93, 330, 280, 90, BUTTONGO, STR_TRAINGGO, 30);
+  buttongo->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); // 设置按键颜色
+  buttongo->SetOnClickListener(static_cast<UIView::OnClickListener *>(
+      TraingRecordPresenter::GetInstance()));
+
+  lackView->Add(labeltitle_);
+  lackView->Add(labelrecord_);
+  lackView->Add(imagerecord);
+  lackView->Add(buttongo);
+
+  // RootView::GetInstance()->lackView
+  container_->Add(lackView);
+  printf("lackView Add\r\n");
+
+  lackView->SetDraggable(true);
+  lackView->SetTouchable(true);
+
+  UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(
+      TraingRecordPresenter::GetInstance());
+  if (draglistener == nullptr) {
+    return;
+  }
+  lackView->SetOnDragListener(draglistener);
+  lackView->SetVisible(false); // 界面隐藏
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView end");
+}
+/*记录列表界面*/
+void TraingRecordView::ShowRecordView() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView start");
+  if (recordView == nullptr) {
+    recordView = new UIScrollView();
+    if (recordView == nullptr) {
+      return;
     }
+    recordView->SetPosition(0, 0);
+    recordView->Resize(466, 466);
+    recordView->SetScrollBlankSize(50);
+    recordView->SetDirection(1);
+  }
+
+  /*初始化label*/
+  InitLabelExt(labelercord_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  recordView->Add(labelercord_);
+
+  // UIList 的适配器
+  if(p_TraingRecordAdapter == nullptr)
+  {
+    p_TraingRecordAdapter = new TraingRecordAdapter();
+  }
+  p_TraingRecordAdapter->SetItemClickListener(presenter_);
+  if (TraingRecordList == nullptr) {
+    TraingRecordList = new UIList();
+  }
+  TraingRecordList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466,
+                                466);
+  TraingRecordList->SetScrollStateListener(this);
+  TraingRecordList->SetThrowDrag(true);
+  TraingRecordList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+  // 设置手指抬起屏幕后的最大滚动距离
+  TraingRecordList->SetMaxScrollDistance(1000);
+  // 设置手指抬起屏幕后的补偿距离
+  TraingRecordList->SetSwipeACCLevel(800);
+  // 设置拖动加速
+  TraingRecordList->SetDragACCLevel(5);
+  TraingRecordList->SetYScrollBarVisible(true);
+  recordView->SetVisible(false); // 隐藏界面
+  TraingRecordList->SetOnClickListener(static_cast<UIView::OnClickListener *>(
+      TraingRecordPresenter::GetInstance()));
+
+  UIView::OnDragListener *recorddraglistener =
+      static_cast<UIView::OnDragListener *>(
+          TraingRecordPresenter::GetInstance());
+  if (recorddraglistener == nullptr) {
+    return;
+  }
+  recordView->SetOnDragListener(recorddraglistener);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView end");
+}
+/*控制显示界面*/
+void TraingRecordView::SetPopupViewStatus(PopupRecord view, bool status) {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPopupViewStatus %d", view);
+
+  if (view == PopupRecord::LackPopup) {
+    TraingRecordModel::GetInstance().SetPopupView(
+        false);                    // 设置状态为无训练记录
+    lackView->SetVisible(true);    // 隐藏界面
+    recordView->SetVisible(false); // 隐藏界面
+  } else if (view == PopupRecord::RecordPopup) {
+    TraingRecordModel::GetInstance().SetPopupView(true); // 设置状态为有训练记录
+    lackView->SetVisible(false);                         // 隐藏界面
+    recordView->SetVisible(true);                        // 隐藏界面
+  }
+}
+// 获取目前的view
+void TraingRecordView::OnStart() {
+  View<TraingRecordPresenter>::OnStart();
+
+  container_ = new UIScrollView();
+  if (container_ == nullptr) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
+    return;
+  }
+  container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+                          Screen::GetInstance().GetHeight());
+
+  container_->SetOnDragListener(presenter_);
+  container_->SetTouchable(true);
+  container_->SetDraggable(true);
+  container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+  container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+  ShowLackView();
+  ShowRecordView();
+  PreLoad();
+
+  SetContainerView(container_);
+
+  // 增加按键监听
+  RootView::OnKeyActListener *keyactListener =
+      (RootView::OnKeyActListener *)OHOS::TraingRecordPresenter::GetInstance();
+  RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+}
+void TraingRecordView::AddToTraingRecordList(const TraingRecordItem &item) {
+  p_TraingRecordAdapter->AddItem(item);
+}
+void TraingRecordView::OnSetUpView() {
+  View<TraingRecordPresenter>::OnSetUpView();
+  if (TraingRecordModel::GetInstance().GetJsonStatus()) {
+    recordView->Add(TraingRecordList);
+    recordView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+    container_->Add(recordView);
+    printf("recordView Add\r\n");
+    TraingRecordList->SetAdapter(p_TraingRecordAdapter);
+  }
+  Draw();
+}
 
-    void TraingRecordView::OnTearDownView()
-    {
-        View<TraingRecordPresenter>::OnTearDownView();
-        return;
-    }
+void TraingRecordView::OnTearDownView() {
+  View<TraingRecordPresenter>::OnTearDownView();
+  return;
+}
 
-    void TraingRecordView::OnStop()
-    {
-        View<TraingRecordPresenter>::OnStop();
-        if (container_ != nullptr)
-        {
-            container_->RemoveAll();
-            delete container_;
-            container_ = nullptr;
-        }
-        RootView::GetInstance()->RemoveAll();
-        return;
-    }
+void TraingRecordView::OnStop() {
+  View<TraingRecordPresenter>::OnStop();
+  if (container_ != nullptr) {
+    container_->RemoveAll();
+    delete container_;
+    container_ = nullptr;
+  }
+  RootView::GetInstance()->RemoveAll();
+  return;
 }
+} // namespace OHOS