优化勿扰模式,用ConfigModel保存勿扰模式状态
authorluozheng <1732036298@qq.com>
Tue, 16 Apr 2024 03:44:29 +0000 (11:44 +0800)
committerluozheng <1732036298@qq.com>
Tue, 16 Apr 2024 03:44:29 +0000 (11:44 +0800)
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbModel.h
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbModel.cpp
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h
code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp

index 23514d1..ec34b9e 100644 (file)
@@ -63,6 +63,7 @@ namespace OHOS
             CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES,    //运动目标站立次数
             CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION,    //运动目标时长
             CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE,    //运动目标距离
+            CONFIGMODEL_ITEM_DNOTDISTURB,//勿扰模式
             CONFIGMODEL_ITEM_MAX,
         } ;
 
@@ -134,6 +135,9 @@ namespace OHOS
 
         void SetCat1_4Gability(bool state);
         bool GetCat1_4Gability();
+
+        void SetDnotdisturb(bool state);
+        bool GetDnotdisturb(void);
         
         // -------------------------------------------------------------------------- */
     private:
@@ -169,6 +173,7 @@ namespace OHOS
             {ConfigDataType::DATATYPE_INT,      "GoalStandupTimes",         "10"    },// CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES,    //运动目标站立次数 10
             {ConfigDataType::DATATYPE_INT,      "GoalDuration",             "30"    },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION,    //运动目标时长   30(分钟)
             {ConfigDataType::DATATYPE_DOUBLE,   "GoalDistance",             "8.0"   },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE,    //运动目标距离   8.0(km)
+            {ConfigDataType::DATATYPE_BOOL,     "Dnotdisturb",              "false" },// CONFIGMODEL_ITEM_DNOTDISTURB //勿扰模式默认关闭
         };
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
         ConfigModel(const ConfigModel &) = delete;            // 禁止拷贝构造
index e64594f..7c2d619 100644 (file)
@@ -609,6 +609,18 @@ namespace OHOS
         return get_configData_bool(CONFIGMODEL_ITEM_CAT1_SERVICE_ON);
     }
 
+    /*设置勿扰模式是否开启*/
+    void ConfigModel::SetDnotdisturb(bool state)
+    {
+        set_condigData_Bool(CONFIGMODEL_ITEM_DNOTDISTURB,state);
+    }
+
+    /*获取勿扰模式是否开启*/
+    bool ConfigModel::GetDnotdisturb(void)
+    {
+        return get_configData_bool(CONFIGMODEL_ITEM_DNOTDISTURB);
+    }
+
 /* ---------------------------------------------------------------------------- */
     int ConfigModel::get_configData_int(ConfigItem item)
     {
index 7497560..311041d 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 16:38:44
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 16:44:52
+ * @LastEditTime: 2024-04-16 11:40:33
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbModel.h
  */
 #ifndef DNOTDISTURB_MODEL_H
@@ -23,7 +23,7 @@ namespace OHOS
         DnotDisturbModel &operator=(const DnotDisturbModel &) = delete;
         virtual ~DnotDisturbModel();
 
-        bool isDoNotDisturbModeEnabled = false; // 默认勿扰模式未开启
+        //bool isDoNotDisturbModeEnabled = false; // 默认勿扰模式未开启
     };
 }
 
index d0711a6..480ebf5 100644 (file)
@@ -1,5 +1,12 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 16:38:52
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-16 11:37:40
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbModel.cpp
+ */
 #include "dnotdisturb/include/DnotDisturbModel.h"
-
+#include "config/include/ConfigModel.h"
 namespace OHOS
 {
 
@@ -15,11 +22,13 @@ namespace OHOS
 
     void DnotDisturbModel::SetDoNotDisturbModeEnabled(bool enabled)
     {
-        isDoNotDisturbModeEnabled = enabled;
+        //isDoNotDisturbModeEnabled = enabled;
+        ConfigModel::GetInstance()->SetDnotdisturb(enabled);
     }
 
     bool DnotDisturbModel::GetDoNotDisturbModeEnabled() const
     {
-        return isDoNotDisturbModeEnabled;
+        //return isDoNotDisturbModeEnabled;
+        return ConfigModel::GetInstance()->GetDnotdisturb();
     }
 }
\ No newline at end of file
index 5c21d5f..8148416 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 11:58:37
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 16:45:23
+ * @LastEditTime: 2024-04-16 11:09:23
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -76,7 +76,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::GetInstance fail!!");
             return false;
         }
-        if (&view == p_DnotDisturbView->GetButtonOn())
+        if (&view == p_DnotDisturbView->GetButtonOn())//开启勿扰模式
         {
             DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(true);
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
@@ -84,7 +84,7 @@ namespace OHOS
         }
         else if (&view == p_DnotDisturbView->GetButtonOff())
         {
-            DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false);
+            //DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false);
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
             NativeAbility::GetInstance().ChangeSlice(preSlice);
         }
index 95bc5b8..b065eda 100644 (file)
@@ -70,7 +70,7 @@ namespace OHOS
         bool InitView();
         void PreLoad(void) override;
         void UpdateBlueToothStatus(int status);
-
+        void UpdateDnotDisturbStatus(int status);
     private:
         UIImageView *dropSetting{nullptr};                  // 设置
         UIImageView *dropLighting{nullptr};                 // 亮屏
index b2574e1..570a00e 100644 (file)
@@ -26,6 +26,7 @@
 #include "DialModelPower.h"
 #include "gfx_utils/mem_check.h"
 #include "traing/training_card/include/Training_CardView.h"
+#include "dnotdisturb/include/DnotDisturbModel.h"
 #if USE_OFFLINE_DIAL
 #include "DialViewGroup.h"
 #endif
@@ -136,6 +137,14 @@ namespace OHOS
 #endif
         }
 
+        //如果勿扰模式是开启状态,在下拉界面点击勿扰快捷入口会关闭勿扰模式不进入勿扰视图
+        if(g_jumpView[curViewId] == VIEW_DNOTDISTURB &&  DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() == true)
+        {
+            PullUpDownView::GetInstance()->UpdateDnotDisturbStatus(false);
+            DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false);
+            return true;
+        }
+
         if (g_jumpView.count(curViewId) != 0)
         {
             NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
index ce32050..54da487 100644 (file)
@@ -489,4 +489,26 @@ namespace OHOS
         return;
     }
 
+    /*更新勿扰模式状态*/
+    void PullUpDownView::UpdateDnotDisturbStatus(int status)
+    {
+        if (dropIconBackground[DNOTDISTURB_INDEX] != nullptr)
+        {
+            if (status)
+            {
+                ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[DNOTDISTURB_INDEX], DROPDOWN_ICONELLIPSEPURPLE);
+            }
+            else
+            {
+                ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[DNOTDISTURB_INDEX], DROPDOWN_ICONELLIPSEBLACK);                
+            }
+            dropIconBackground[DNOTDISTURB_INDEX]->Invalidate();
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropIconBackground[DNOTDISTURB_INDEX] is nullptr");
+            return;
+        }
+    }
+
 }