Merge #247 into sdk602patch0521 from refs/changes/247/head 259/target/1 260/target/1 261/target/1 262/target/1
author袁清梦 <3449750381@qq.com>
Tue, 11 Jun 2024 10:08:30 +0000 (10:08 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Tue, 11 Jun 2024 10:08:30 +0000 (10:08 +0000)
训练记录显示详细数据

* refs/changes/247/head: (5 commits squashed)

  - 训练记录显示详细数据

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

  - 修复训练记录显示问题

  - Merge branch &#39;sdk602patch0521&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521

Signed-off-by: Caisking <3449750381@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/247
13 files changed:
code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingView.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h
code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h
code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp

index 0ab8532..6ecf25b 100644 (file)
@@ -83,10 +83,10 @@ extern "C"
         {
             return;
         }
-        PRINT("request %d\r\n", request->msgId);
         // 进入拍照界面
         if (request->msgId == TOPIC_EVENT_ENTER_CMAERA)
         {
+            PRINT(" 遥控拍照 \r\n");
             uapi_set_screen_on_api(); // 亮屏
             NativeAbility::GetInstance().EnterSlice(VIEW_TAKEPHOTOS);
             TakephotosView::GetInstance()->SetPopupViewStatus(PopupPhoto::TakePopup, true);
index ebe56f0..58ac873 100644 (file)
@@ -240,6 +240,8 @@ namespace OHOS
         void AnalysisData(cywee_activity_result_t *cyweeInfo);
         /*获取训练数据*/
         SportData *GetSportdata();
+        /*设置训练数据[为训练记录准备]*/
+        void SetSportdata(SportData *data);
         /*获取运动卡路里*/
         int GetCal();
         /*设置时间戳*/
@@ -288,6 +290,9 @@ namespace OHOS
         bool SaveDataToJson(SportData *data);
         std::vector<SportData> LoadDataFormJson();
 
+        /*打印函数*/
+        void printf_data(SportData *data);
+
     private:
         TraingModel(const TraingModel &) = delete;
         TraingModel &operator=(const TraingModel &) = delete;
index 0d92edb..aae8b1b 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 14:19:47
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 15:34:57
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
+ */
 /***
  * @Date: 2024-04-15 14:19:47
  * @LastEditors: Caisking 3449750381@qq.com
@@ -67,7 +73,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
         }
         UNUSED(view);
         return true;
@@ -78,7 +84,7 @@ namespace OHOS
         // 根据控件id查找是哪个控件触发了点击回调
         if (strcmp(view.GetViewId(), BUTTONBACK) == 0)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
         }
         return true;
     }
index a0410de..f77a5a4 100644 (file)
 #include "traing/Training_UiConfig.h"
 #include <cmath>  // 包含数学函数库,用于四舍五入
 #include <string> // 包含字符串处理库,用于使用 std::to_string
+
+/*测试打印函数*/
+#define PRINT_LINE_INFO() printf("File: %s, Line: %d\r\n", __FILE__, __LINE__)
+#define PRINT_FUNCTION_LINE() printf("Function: %s, Line: %d\r\n", __FUNCTION__, __LINE__)
+
 namespace OHOS
 {
 
@@ -38,6 +43,7 @@ namespace OHOS
     /* InitView:初始化界面*/
     void TraingEnddataView ::InitView()
     {
+        // printf("TraingEnddataView::InitView()\r\n");
         if (container_ == nullptr)
         {
             container_ = new UIViewGroup();
@@ -132,6 +138,8 @@ namespace OHOS
         InitButtonExt(buttonexit, 42, 1111, 380, 100, BUTTONBACK, STR_CLOSE, 30);
         buttonexit->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingEnddataPresenter::GetInstance()));
         scrollView_->Add(buttonexit);
+
+        // printf("TraingEnddataView::InitView() is end\r\n");
     }
 
     /* DeInit:删除组件 */
@@ -279,15 +287,24 @@ namespace OHOS
     void TraingEnddataView::InitData()
     {
         SportData *enddata = TraingModel::GetInstance()->GetSportdata();
+
         if (enddata == nullptr)
         {
+            printf("Enddata is nullptr. Exiting InitData()...\r\n");
             return;
         }
-
+        printf("Initializing TraingEnddataView data...\r\n");
         // 训练图标Icon
         std::string imageStr = TraingModel::GetInstance()->GetSportType(enddata->sportType);
-        imageIcon->SetSrc(imageStr.c_str());
-
+        if (!imageStr.empty())
+        {
+            printf("imageIcon %s\r\n", imageStr.c_str());
+            imageIcon->SetSrc(imageStr.c_str());
+        }
+        else
+        {
+            printf("Failed to get image string. Skipping imageIcon update.\r\n");
+        }
         // 运动项目
         labelsport->SetTextId(enddata->sportId);
 
@@ -295,17 +312,24 @@ namespace OHOS
         std::string startTimeStr = enddata->start_time;
         std::string endTimeStr = enddata->end_time;
         std::string durationStr = startTimeStr + "-" + endTimeStr;
+
         labelduration->SetText(durationStr.c_str());
 
         // 运动目标
-        if (enddata && enddata->tag)
+        if (enddata->tag)
         {
             std::string tagStr = std::to_string(enddata->goaldegree) + "%";
             labeltag->SetText(tagStr.c_str());
         }
+        else
+        {
+            printf("Enddata tag is null. Skipping labeltag update.\r\n");
+        }
+
         // 运动时长
-        PRINT("duration:%d\r\n", enddata->duration);
+        printf("Duration of the sport: %d\r\n", enddata->duration);
         std::string timeStr = TraingModel::GetInstance()->GetTrainingTime();
+
         labeltime->SetText(timeStr.c_str());
 
         // 运动距离
@@ -313,7 +337,6 @@ namespace OHOS
         labelmile->SetText(mileStr.c_str());
 
         // 平均心率
-        // int heart = CalculateAverageHeartRate(155); // 设置一个测试值
         std::string heartStr = std::to_string(enddata->avgheart);
         labelheart->SetText(heartStr.c_str());
 
@@ -324,6 +347,8 @@ namespace OHOS
         // 训练强度
         UIResourceTextId intensityid = TraingModel::GetInstance()->GetIntensity();
         labelstrong->SetTextId(intensityid);
+
+        printf("TraingEnddataView data initialization complete.\r\n");
     }
 
     void TraingEnddataView::OnStart()
index 8f9d70b..fd9b46c 100644 (file)
 #include <cmsis_os2.h>
 #include <service/graphic_service.h>
 #include "thread_adapter.h"
-#include <iostream>
 #include <sstream>
 #include <iomanip>
-#include <string>
+#include <fstream>
 #include "cmsis_os.h"
 #include "traing/training_card/include/TraingCardPresenter.h"
 
@@ -355,11 +354,50 @@ namespace OHOS
             }
         }
     }
+    /*打印函数*/
+
+    void TraingModel::printf_data(SportData *data)
+    {
+        /*打印测试一下数据*/
+        printf("\r\n****************************************\r\n");
+        printf("Sport type: %d\n", data->sportType);
+        printf("Sport ID: %d\n", data->sportId);
+        printf("Start date: %s\n", data->start_date.c_str());
+        printf("Start time: %s\n", data->start_time.c_str());
+        printf("End time: %s\n", data->end_time.c_str());
+        printf("Goal degree: %d\n", data->goaldegree);
+        printf("Duration: %d\n", data->duration);
+        printf("Distance: %d\n", data->distance);
+        printf("Average heart rate: %d\n", data->avgheart);
+        printf("Steps: %d\n", data->steps);
+        printf("Intensity: %d\n", data->intensity);
+        printf("\r\n****************************************\r\n");
+    }
     /*获取数据*/
     SportData *TraingModel::GetSportdata()
     {
+        // printf_data(sportdata);
         return sportdata;
     }
+    /* 设置训练数据[为训练记录准备] */
+    void TraingModel::SetSportdata(SportData *data)
+    {
+        if (data != nullptr && sportdata != nullptr)
+        {
+            sportdata->sportTagType = data->sportTagType;
+            sportdata->sportId = data->sportId;
+            sportdata->start_date = data->start_date;
+            sportdata->start_time = data->start_time;
+            sportdata->end_time = data->end_time;
+            sportdata->goaldegree = data->goaldegree;
+            sportdata->duration = data->duration;
+            sportdata->distance = data->distance;
+            sportdata->avgheart = data->avgheart;
+            sportdata->steps = data->steps;
+            sportdata->intensity = data->intensity;
+        }
+        printf_data(data);
+    }
     /*获取训练卡路里*/
     int TraingModel::GetCal()
     {
@@ -742,7 +780,6 @@ namespace OHOS
     {
         Openingway = way;
     }
-
     /*设置运动是否开始*/
     void TraingModel::SetSportOpenState(bool state)
     {
@@ -1114,48 +1151,46 @@ namespace OHOS
         return true;
     }
 
-    /* 保存训练数据到 json 文件 */
     bool TraingModel::SaveDataToJson(SportData *data)
     {
-        cJSON *root = cJSON_CreateObject();
-        cJSON *dataArray = cJSON_CreateArray();
-
-        // 1.获取record.json文件,不存在则创建
-        FILE *fp = fopen(TRAINING_RECORD_FILE, "r+");
+        // 获取 JSON 文件,不存在则创建
+        FILE *fp = fopen(TRAINING_RECORD_FILE, "r");
         if (fp == NULL)
         {
-            fp = fopen(TRAINING_RECORD_FILE, "w");
+            fp = fopen(TRAINING_RECORD_FILE, "w+");
             if (fp == NULL)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fopen file is error");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create or open file for writing");
                 return false;
             }
         }
 
+        // 读取并解析现有的 JSON 数据
         fseek(fp, 0, SEEK_END);
         long fileSize = ftell(fp);
         fseek(fp, 0, SEEK_SET);
 
         char *jsonStr = (char *)malloc(fileSize + 1);
+        if (jsonStr == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for JSON data");
+            fclose(fp);
+            return false;
+        }
+
         fread(jsonStr, 1, fileSize, fp);
-        jsonStr[fileSize] = '\0';
+        fclose(fp);
 
-        // 2.读取已有数据
-        cJSON *existingData = cJSON_Parse(jsonStr);
-        cJSON *existingArray = cJSON_GetObjectItem(existingData, "data");
-        if (existingArray != NULL && cJSON_GetArraySize(existingArray) > 0)
+        cJSON *root = cJSON_Parse(jsonStr);
+        if (root == NULL)
         {
-            int existingCount = cJSON_GetArraySize(existingArray);
-            for (int i = 0; i < existingCount; i++)
-            {
-                cJSON *item = cJSON_GetArrayItem(existingArray, i);
-                cJSON_AddItemToArray(dataArray, cJSON_Duplicate(item, 1));
-            }
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to parse JSON data");
+            free(jsonStr);
+            return false;
         }
-        cJSON_Delete(existingData);
-        free(jsonStr);
 
-        // 3.添加新数据
+        // 创建或更新数据节点
+        cJSON *dataArray = cJSON_GetObjectItem(root, "data");
         cJSON *sportData = cJSON_CreateObject();
         cJSON_AddNumberToObject(sportData, "sportTypeId", int(data->sportType));     // 训练项目类 Id
         cJSON_AddNumberToObject(sportData, "sportId", data->sportId);                // 训练项目 Id
@@ -1170,25 +1205,40 @@ namespace OHOS
         cJSON_AddNumberToObject(sportData, "intensity", data->intensity);            // 训练强度
         cJSON_AddItemToArray(dataArray, sportData);
 
-        // 4.限制存储数量,只保存最新的10条数据
-        int dataCount = cJSON_GetArraySize(dataArray);
-        if (dataCount > MAX_DATA_COUNT)
+        // 限制存储数量并删除多余数据
+        while (cJSON_GetArraySize(dataArray) > MAX_DATA_COUNT)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "The training data has reached its maximum ");
             cJSON_DeleteItemFromArray(dataArray, 0);
         }
 
-        cJSON_AddItemToObject(root, "data", dataArray);
-
+        // 将更新后的 JSON 数据写入文件
         char *jsonStrNew = cJSON_Print(root);
-        cJSON_Delete(root);
+        if (jsonStrNew == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to serialize JSON data");
+            cJSON_Delete(root);
+            free(jsonStr);
+            return false;
+        }
 
-        fseek(fp, 0, SEEK_SET);
-        fprintf(fp, "%s\n", jsonStrNew);
+        fp = fopen(TRAINING_RECORD_FILE, "w");
+        if (fp == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open file for writing");
+            cJSON_Delete(root);
+            free(jsonStr);
+            return false;
+        }
 
+        fwrite(jsonStrNew, strlen(jsonStrNew), 1, fp);
         fclose(fp);
 
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveDataToJson  is succeed");
+        // 释放资源
+        cJSON_Delete(root);
+        free(jsonStr);
+        cJSON_free(jsonStrNew);
+
+        WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SaveDataToJson succeeded");
         return true;
     }
     /* 加载训练数据函数 */
@@ -1208,8 +1258,9 @@ namespace OHOS
         cJSON *dataArray = cJSON_GetObjectItem(root, "data");
 
         int dataCount = cJSON_GetArraySize(dataArray);
-        std::vector<SportData> sportDataVector;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dataCount is %d", dataCount);
 
+        std::vector<SportData> sportDataVector;
         for (int i = 0; i < dataCount; i++)
         {
             cJSON *item = cJSON_GetArrayItem(dataArray, i);
@@ -1230,6 +1281,7 @@ namespace OHOS
         }
 
         cJSON_Delete(root);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadDataFormJson is ok");
         return sportDataVector;
     }
 }
\ No newline at end of file
index 7f93aa5..00f35bf 100644 (file)
@@ -224,7 +224,6 @@ namespace OHOS
         // 删除容器\r
         if (container_ != nullptr)\r
         {\r
-            container_->RemoveAll(); // 移除容器中的所有组件\r
             delete container_;\r
             container_ = nullptr;\r
         }\r
index 6d28a4c..424164d 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-08 11:27:43
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h
+ */
 /***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-27 11:12:32
@@ -29,6 +35,8 @@ namespace OHOS
     public:
         explicit TraingRecordItemView();
         virtual ~TraingRecordItemView();
+        static TraingRecordItemView &GetInstance(void);
+
         virtual void SetItemInfo(const TraingRecordItem itemInfo);
         virtual void SetUpChild();
         int GetTraingRecordIndex();
index 617789b..cfbc40d 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:42:02
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h
+ */
 /***
  * @Date: 2024-05-20 19:40:41
  * @LastEditors: Caisking 3449750381@qq.com
@@ -30,6 +36,10 @@ namespace OHOS
         uint8_t GetTraingRecordListNum();
         // 设置标志位
         bool GetJsonStatus();
+        // 设置当前界面
+        void SetPopupView(bool state);
+        // 获取当前界面
+        bool GetPopupView();
 
     private:
         TraingRecordModel();
@@ -41,6 +51,7 @@ namespace OHOS
         TraingRecordItem TraingRecords[TraingRecordListMaxNum] = {0, nullptr, nullptr, nullptr};
         // std::map<int, AppViewId> TraingRecordIdToViewId;
         bool jsonStatus{false}; // json文件存在标志位
+        bool popupStatus{false};
     };
 }
 
index b5e592d..3daf075 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:40:10
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h
+ */
 #ifndef _TraingRecord_VIEW_H
 #define _TraingRecord_VIEW_H
 
@@ -53,6 +59,7 @@ namespace OHOS
         void ShowLackView();
         void ShowRecordView();
         void SetPopupViewStatus(PopupRecord view, bool status);
+        int GetPopupRecordView();
         void AddToTraingRecordList(const TraingRecordItem &item);
 
     private:
index 6621a0e..71645e5 100644 (file)
@@ -39,12 +39,18 @@ namespace OHOS
         Remove(&slogo);
     }
 
+    TraingRecordItemView &TraingRecordItemView::GetInstance()
+    {
+        static TraingRecordItemView instance;
+        return instance;
+    }
+
     /// @brief 设置item的信息
     /// @param itemInfo
     void TraingRecordItemView::SetItemInfo(const TraingRecordItem itemInfo)
     {
         sItemInfo = itemInfo;
-        printf("iamge--%s data--%s time--%s\r\n", (itemInfo.image).c_str(), (itemInfo.data).c_str(), (itemInfo.time).c_str());
+        //printf("iamge--%s data--%s time--%s\r\n", (itemInfo.image).c_str(), (itemInfo.data).c_str(), (itemInfo.time).c_str());
         sLabeldata.SetText((itemInfo.data).c_str());
         sLabeltime.SetText((itemInfo.time).c_str());
         slogo.SetSrc((itemInfo.image).c_str());
index b496b89..9bfcb29 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:41:20
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp
+ */
 /***
  * @Date: 2024-05-20 19:40:41
  * @LastEditors: Caisking 3449750381@qq.com
 namespace OHOS
 {
 
-    TraingRecordModel::TraingRecordModel() {}
+    TraingRecordModel::TraingRecordModel()
+    {
+        jsonStatus = TraingModel::GetInstance()->CheckDataJson();
+    }
 
     TraingRecordModel::~TraingRecordModel() {}
 
@@ -34,7 +43,10 @@ namespace OHOS
     // 设置标志位
     bool TraingRecordModel::GetJsonStatus()
     {
-        jsonStatus = TraingModel::GetInstance()->CheckDataJson();
+        if (jsonStatus)
+        {
+            // printf("存在文件!\r\n");
+        }
         return jsonStatus;
     }
 
@@ -45,6 +57,7 @@ namespace OHOS
         if (!sportDataVector.empty())
         {
             ArrayNum = sportDataVector.size();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the ArrayNum is %d", ArrayNum);
             for (int i = 0; i < ArrayNum && i < TraingRecordListMaxNum; i++) // 最多只有10条数据
             {
                 SportData sportData = sportDataVector[i];
@@ -54,13 +67,6 @@ namespace OHOS
                 // 4.获取时间
                 std::string Time = sportData.start_time + std::string("-") + sportData.end_time;
                 TraingRecords[i] = {i, imageicon.c_str(), sportData.start_date, Time};
-#if 0
-                // 使用 printf 输出每条训练记录的信息 [测试]
-                printf("Training Record %d:\n", i + 1);
-                printf("Sport Type: %s\n", imageicon.c_str());
-                printf("Start Date: %s\n", sportData.start_date.c_str());
-                printf("Start Time: %s\n", Time.c_str());
-#endif
             }
         }
     }
@@ -73,4 +79,15 @@ namespace OHOS
     {
         return ArrayNum;
     }
+
+    // 设置当前界面
+    void TraingRecordModel::SetPopupView(bool state)
+    {
+        popupStatus = state;
+    }
+    // 获取当前界面 0:没有训练记录 | 1:有训练记录
+    bool TraingRecordModel::GetPopupView()
+    {
+        return popupStatus;
+    }
 }
\ No newline at end of file
index 76c4725..952c073 100644 (file)
@@ -14,6 +14,8 @@
 #include <thread>
 #include "traingrecord/include/TraingRecordPresenter.h"
 #include "traingrecord/include/TraingRecordModel.h"
+#include "traing/include/TraingEnddataView.h"
+
 // #include "TraingRecordView.h"
 
 namespace OHOS
@@ -86,10 +88,32 @@ namespace OHOS
     bool TraingRecordPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
         // 返回按键
-        if (strcmp(view.GetViewId(), BUTTONGO) == 0)
+        std::string viewId = view.GetViewId();
+        if (TraingRecordModel::GetInstance().GetPopupView() == false)
         {
-            NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
+            if (viewId == BUTTONGO)
+            {
+                NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "go to training");
+                return true;
+            }
         }
-        return true;
+        else
+        {
+            int index = TraingRecordItemView::GetInstance().GetTraingRecordIndex();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+            // 读取json数据
+            std::vector<SportData> sportDataVector = TraingModel::GetInstance()->LoadDataFormJson();
+            if (!sportDataVector.empty())
+            {
+                // 选择点击按键的历史数据
+                SportData sportData = sportDataVector[index];
+                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA);
+                TraingModel::GetInstance()->SetSportdata(&sportData);
+                return true;
+            }
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the sportDataVector is error");
+        }
+        return false;
     }
 }
index f28a022..33e382d 100644 (file)
@@ -172,7 +172,6 @@ namespace OHOS
             return;
         }
         lackView->SetOnDragListener(draglistener);
-
         lackView->SetVisible(false); // 界面隐藏
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView end");
     }
@@ -218,6 +217,7 @@ namespace OHOS
         // 增加表冠控制
         TraingRecordList->SetRotateFactor(2);
         TraingRecordList->RequestFocus();
+        TraingRecordList->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingRecordPresenter::GetInstance()));
 
         UIView::OnDragListener *recorddraglistener = static_cast<UIView::OnDragListener *>(TraingRecordPresenter::GetInstance());
         if (recorddraglistener == nullptr)
@@ -235,27 +235,26 @@ namespace OHOS
         UIView *popupView = nullptr;
         if (view == PopupRecord::LackPopup)
         {
+            TraingRecordModel::GetInstance().SetPopupView(false); // 设置状态为无训练记录
             popupView = lackView;
         }
         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);
         }
-
         popupView->SetVisible(status);
     }
-
+    // 获取目前的view
     void TraingRecordView::OnStart()
     {
         container_ = new UIScrollView();