久坐提醒修改
authorluozheng <1732036298@qq.com>
Wed, 3 Jul 2024 12:35:13 +0000 (20:35 +0800)
committerSnickerSun <snickersun@163.com>
Fri, 5 Jul 2024 02:34:06 +0000 (10:34 +0800)
code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/config/src/ConfigModel.cpp

index 81e7763..97de0af 100644 (file)
@@ -23,8 +23,8 @@ namespace OHOS
     UILabelExt *SedentaryReminderLabel{nullptr};
     UIButton *SedentaryReminderButton{nullptr};
 
-    static constexpr const int X_DRAG_OFFSET =  20;
-    static constexpr const int DOUBLES =  2;
+    static constexpr const int X_DRAG_OFFSET = 20;
+    static constexpr const int DOUBLES = 2;
 
     static constexpr const char *SEDENTARY_REMINDER_GROUPVIEWID = "sedentary_reminder_groupviewid";
     static constexpr const char *SEDENTARY_REMINDER_BUTTONVIEWID = "sedentary_reminder_buttonviewid";
@@ -91,14 +91,30 @@ namespace OHOS
         time_t now = time(0);
         tm *ltm = localtime(&now);
         int currentHour = ltm->tm_hour;
+        int currentMinute = ltm->tm_min;
 
-        std::string ReminderTime = ConfigModel::GetInstance()->GetSedentaryReminderTime();
-        // 判断是否在提醒时间段内
-        if (ReminderTime.find(std::to_string(currentHour)) != std::string::npos)
+        // 获取提醒时间段
+        int ReminderTime = ConfigModel::GetInstance()->GetSedentaryReminderTime();
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ReminderTime = %d ",ReminderTime);
+
+        // 解析开始时间
+        int startHour = (ReminderTime >> 24) & 0xFF;   // 前8位是小时
+        int startMinute = (ReminderTime >> 16) & 0xFF; // 后8位是分钟
+
+        // 解析结束时间
+        int endHour = (ReminderTime >> 8) & 0xFF; // 中间8位是小时
+        int endMinute = ReminderTime & 0xFF;      // 后8位是分钟
+
+        // 判断当前时间是否在提醒时间段内
+        if (currentHour > startHour || (currentHour == startHour && currentMinute >= startMinute))
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's time to remind the user to move!");
-            return true;
+            if (currentHour < endHour || (currentHour == endHour && currentMinute < endMinute))
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's time to remind the user to move!");
+                return true;
+            }
         }
+
         return false;
     }
 
index fb1141d..c59bab1 100644 (file)
@@ -253,14 +253,14 @@ namespace OHOS
         void SetDrinkFreq(const int value);
         int GetDrinkFreq();
         /* ------------------------------ 久坐提醒相关set与get ----------------------------- */
-        void SetSedentarySwitch(const bool value);
-        bool GetSedentarySwitch();
+        void SetSedentarySwitch(const int value);
+        int GetSedentarySwitch();
 
         void SetSedentaryInterval(const int value);
         int GetSedentaryInterval();
 
-        void SetSedentaryReminderTime(const std::string& value);
-        std::string GetSedentaryReminderTime();
+        void SetSedentaryReminderTime(const int value);
+        int GetSedentaryReminderTime();
 
         /* ---------------------------------- 运动识别相关set与get ---------------------------------- */
         void SetMotionRecognition(bool state);
index ace4e6b..cbaac68 100644 (file)
@@ -893,15 +893,15 @@ namespace OHOS
     }
 
     // 设置久坐提醒开关
-    void ConfigModel::SetSedentarySwitch(const bool value) 
+    void ConfigModel::SetSedentarySwitch(const int value) 
     {
         set_condigData_Bool(CONFIGMODEL_ITEM_SEDENTARY_SWITCH,value);
     }
 
     // 获取久坐提醒开关
-    bool ConfigModel::GetSedentarySwitch() 
+    int ConfigModel::GetSedentarySwitch() 
     {
-        return get_configData_bool(CONFIGMODEL_ITEM_SEDENTARY_SWITCH);
+        return get_configData_int(CONFIGMODEL_ITEM_SEDENTARY_SWITCH);
     }
 
     // 设置久坐提醒时间间隔
@@ -917,15 +917,15 @@ namespace OHOS
     }
 
     // 设置久坐提醒时间段
-    void ConfigModel::SetSedentaryReminderTime(const std::string& value) 
+    void ConfigModel::SetSedentaryReminderTime(const int value) 
     {
-        set_condigData_String(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME,value.c_str());
+        set_condigData_Int(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME,value);
     }
 
     // 获取久坐提醒时间段
-    std::string ConfigModel::GetSedentaryReminderTime() 
+    int ConfigModel::GetSedentaryReminderTime() 
     {
-        return get_configData_string(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME);
+        return get_configData_int(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME);
     }
 
     /* -------------------------------------------------------------------------- */