修复每日目标model,不再多次读取config 1159/1
authorhcj <1224667075@qq.com>
Fri, 11 Oct 2024 09:34:59 +0000 (17:34 +0800)
committerhcj <1224667075@qq.com>
Fri, 11 Oct 2024 09:34:59 +0000 (17:34 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h
code/sdk/application/wearable/fd230app/nativeui/goal/include/goalmodel.h
code/sdk/application/wearable/fd230app/nativeui/goal/src/goalmodel.cpp

index 3c575f5..6610d3f 100644 (file)
@@ -463,7 +463,7 @@ void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height,
   InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize);
 }
 void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator,
-                             ImageAnimatorInfo *&imageAnimatorInfo,
+                             ImageAnimatorInfo *imageAnimatorInfo,
                              const ImageInfo **imageInfo, int numFrames,
                              int left, int top, int width, int height,
                              const char *viewId, int time) {
@@ -476,7 +476,7 @@ void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator,
   // imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
   imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
 
-  imageAnimatorInfo = new ImageAnimatorInfo[numFrames];
+  // imageAnimatorInfo = new ImageAnimatorInfo[numFrames];
   for (int i = 0; i < numFrames; i++) {
     imageAnimatorInfo[i].imageInfo = imageInfo[i];
     imageAnimatorInfo[i].pos.x = left;
index 073efd4..6c232ac 100644 (file)
@@ -231,7 +231,7 @@ namespace OHOS
      * @param config             动画相关的配置(包括路径和帧信息)。
      * @param generalConfig      视图的基本配置(位置、大小、视图 ID 等)。
      */
-    void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const ImageInfo **imageInfo, int numFrames, int left, int top, int width, int height, const char *viewId, int time);
+    void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *imageAnimatorInfo, const ImageInfo **imageInfo, int numFrames, int left, int top, int width, int height, const char *viewId, int time);
 
     /**
      * @brief 释放 UIImageAnimatorView 的资源。
index 7e02201..6719cc7 100644 (file)
@@ -45,8 +45,31 @@ namespace OHOS
         char* getstandgoal();
         char* getstandnew();
         void updata();
+        void GoalModelInitdata();
+
+        uint8_t get_step_goal_show()
+        {
+            return step_goal_show;
+        }
+
+        uint8_t get_other_goal_show()
+        {
+            return other_goal_show;
+        }
+
 
     private:
+        //目标数据
+
+        uint32_t step=0;
+        uint32_t distance=0;
+        uint32_t fat=0;
+        uint32_t calories=0;
+        uint32_t stand=0;
+
+        uint8_t step_goal_show=0;
+        uint8_t other_goal_show=0;
+
         GoalModel();
         GoalModel(const GoalModel &) = delete;
         GoalModel &operator=(const GoalModel &) = delete;
index aa370e3..c1e1384 100644 (file)
 
 namespace OHOS
 {
-
+ 
    GoalModel::GoalModel()
    {
+      GoalModelInitdata();
       WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GoalModel::GoalModel");
    }
 
+    
+
+   void GoalModel::GoalModelInitdata()
+   {
+      step_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEP);
+      other_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_OTHER);
+
+      step=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT);
+      distance=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE);
+      fat=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION);
+      calories=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
+      stand=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
+   }
+
+
    GoalModel::~GoalModel()
    {
       WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GoalModel::~GoalModel");
    }
    uint8_t GoalModel::getstepvalue()
    {
-      int stepgoal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT);
+      int stepgoal = step;
       int stepdata = OHOS::ActivityModel::GetInstance()->GetStepCounter();
       // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %d %f ",stepdata,stepgoal,((float)stepdata/(float)stepgoal) * 100);
       uint8_t value = ((float)stepdata / (float)stepgoal) * 100;
@@ -41,7 +57,7 @@ namespace OHOS
    char stepgoalstr[20];
    char *GoalModel::getstepGoal()
    {
-      int stepgoal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT);
+      int stepgoal = step;
       memset((void *)stepgoalstr, 0, 20);
       sprintf_s(stepgoalstr, 20, "/%d", stepgoal);
       return stepgoalstr;
@@ -59,7 +75,7 @@ namespace OHOS
    char caloriesgoalstr[20];
    char *GoalModel::getcaloriesGoal()
    {
-      int caloriesdata = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
+      int caloriesdata =calories;
       memset((void *)caloriesgoalstr, 0, 20);
       sprintf_s(caloriesgoalstr, 20, "/%d", caloriesdata);
       return caloriesgoalstr;
@@ -78,7 +94,7 @@ namespace OHOS
    char distancegoalstr[20];
    char *GoalModel::getdistanceGoal()
    {
-      int distancedata = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE);
+      int distancedata = distance;
       memset((void *)distancegoalstr, 0, 20);
       sprintf_s(distancegoalstr, 20, "/%d", distancedata);
       return distancegoalstr;
@@ -97,7 +113,7 @@ namespace OHOS
    char fatburninggoalstr[20];
    char *GoalModel::getfatburninggoal()
    {
-      int fatburningdata = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION);
+      int fatburningdata = fat;
       memset((void *)fatburninggoalstr, 0, 20);
       sprintf_s(fatburninggoalstr, 20, "/%d", fatburningdata);
       return fatburninggoalstr;
@@ -107,7 +123,7 @@ namespace OHOS
    bool GoalModel::is_goal_DISTANCE_done()
    {
        float distancedata_now = (float)get_distance_data() / 1000.0;
-       int distancedata_goal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE);
+       int distancedata_goal = distance;
 
       if(distancedata_now>=distancedata_goal)
       return true;
@@ -120,7 +136,7 @@ namespace OHOS
    {
        int fatburningdata_now = get_fat_time_data()/60;
 
-       int fatburningdata_goal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION);
+       int fatburningdata_goal = fat;
 
       if(fatburningdata_now>=fatburningdata_goal)
        return true;
@@ -133,7 +149,7 @@ namespace OHOS
    {
       int standdata_now = get_now_stand_count();
 
-      int standdata_goal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
+      int standdata_goal = stand;
 
       if(standdata_now>=standdata_goal)
        return true;
@@ -146,7 +162,7 @@ namespace OHOS
    {
       int calories_now =  get_calories_data();
 
-      int calories_goal = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
+      int calories_goal = calories;
 
       if(calories_now>=calories_goal)
        return true;
@@ -169,7 +185,7 @@ namespace OHOS
    char standstr[20];
    char *GoalModel::getstandgoal()
    {
-      int standdata = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
+      int standdata =stand;
       memset((void *)standstr, 0, 20);
       sprintf_s(standstr, 20, "/%d", standdata);
       return standstr;
@@ -193,6 +209,8 @@ namespace OHOS
 
    void GoalModel::updata(void)
    {
+      GoalModel::GetInstance().GoalModelInitdata();
+
       if(OHOS::GoalView::GetInstance())
       {
          OHOS::GoalView::GetInstance()->GoalViewrefresh();