From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs |  157 +++++++++++++++++++++++++++------------------------
 1 files changed, 83 insertions(+), 74 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs
index a4001f1..4c219f0 100755
--- a/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs
+++ b/ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs
@@ -31,10 +31,6 @@
         /// </summary>
         private SeekBarControl seekBarColor = null;
         /// <summary>
-        /// MaxLevel
-        /// </summary>
-        private const int MaxLevel = 254;
-        /// <summary>
         /// 浜害杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓�
         /// </summary>
         private bool isLightProgressing = false;
@@ -42,10 +38,6 @@
         /// 鑹叉俯杩涘害鍊兼槸鍚﹀湪鏀瑰彉涓�
         /// </summary>
         private bool isColorProgressing = false;
-        /// <summary>
-        /// 鑳藉惁鍙戦�佽繘搴﹀��
-        /// </summary>
-        private bool canSetProgressValue = true;
         /// <summary>
         /// 1:鍙戦�佺殑鏄皬澶滅伅  2:鍙戦�佺殑鏄渹楦e櫒
         /// </summary>
@@ -102,7 +94,7 @@
             seekBarLight.ProgressTextSize = 14;
             seekBarLight.ProgressTextColor = UserCenterColor.Current.TextGrayColor2;
             seekBarLight.Gravity = Gravity.Frame;
-            seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
+            seekBarLight.Progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level);
             frameWhiteBack.AddChidren(seekBarLight);
 
             //鑹叉俯
@@ -125,25 +117,27 @@
             frameWhiteBack.AddChidren(btnColorBack);
             //杩涘害鏉�(+60鐨勫亸绉婚噺,鑹叉俯鐨勮寖鍥存槸 3000~6000)
             this.seekBarColor = new SeekBarControl(611 + 120);
-            seekBarColor.Y = btnLightLine.Bottom + Application.GetRealHeight(58);
+            seekBarColor.Y = btnLightLine.Bottom + Application.GetRealHeight(88);
             seekBarColor.X = Application.GetRealWidth(266 - 60);
-            seekBarColor.Height = Application.GetRealHeight(144);
             seekBarColor.SeekBarViewHeight = Application.GetRealHeight(20);
             seekBarColor.SeekBarPadding = Application.GetRealWidth(60);
-            seekBarColor.IsProgressTextShow = true;
             seekBarColor.ProgressBarColor = UserCenterColor.Current.Transparent;
+            seekBarColor.ProgressBarUnEnableColor = UserCenterColor.Current.Transparent;
             seekBarColor.SeekBarBackgroundColor = UserCenterColor.Current.Transparent;
             seekBarColor.ProgressTextSize = 14;
             seekBarColor.ProgressTextColor = UserCenterColor.Current.TextGrayColor2;
             seekBarColor.Gravity = Gravity.Frame;
-            seekBarColor.ProgressBarUnitSring = "K";
             seekBarColor.MinValue = 30;
             seekBarColor.MaxValue = 60;
+            seekBarColor.ProgressChangeDelayTime = 0;
             frameWhiteBack.AddChidren(seekBarColor);
+            //鏄剧ず鑷畾涔夋枃鏈�
+            seekBarColor.ShowCustomTextView(Application.GetRealWidth(200), 15, UserCenterColor.Current.TextGrayColor3);
             //璁剧疆鍒濆鍊�
             int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature;
             if (colorValue == 0) { colorValue = 3000; }
             seekBarColor.Progress = colorValue / 100;
+            seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K");
 
             //铚傞福鍣ㄥ紑鍏筹細
             var btnBuzzerView = new NormalViewControl(300, 60, true);
@@ -161,6 +155,7 @@
             this.btnBuzzerSwitch = new IconBigViewControl(81, 81);
             btnBuzzerSwitch.UnSelectedImagePath = "Item/Switch.png";
             btnBuzzerSwitch.SelectedImagePath = "Item/SwitchSelected.png";
+            btnBuzzerSwitch.IsSelected = ((ColorTemperatureLight)this.device).IsBuzzerRing;
             frameWhiteBack.AddChidren(btnBuzzerSwitch);
             btnBuzzerSwitch.InitControl();
             btnBuzzerSwitch.UseClickStatu = false;
@@ -199,7 +194,6 @@
                 this.SetLightSwitchCommand(!btnMiniSwitch.IsSelected);
             };
             btnMiniSwitch.IsSelected = ((LightBase)this.device).OnOffStatus == 1;
-            this.canSetProgressValue = btnMiniSwitch.IsSelected;
 
             //浜害寮�濮嬫粦鍔ㄧ殑浜嬩欢
             seekBarLight.OnStartTrackingTouchEvent += (sender, e) =>
@@ -222,16 +216,13 @@
             {
                 if (Common.Config.Instance.Home.IsVirtually == false)
                 {
-                    if (this.canSetProgressValue == true)
-                    {
-                        //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰�
-                        nowLightValue = value;
-                    }
+                    //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰�
+                    nowLightValue = value;
                 }
                 else
                 {
                     //濡傛灉浣忓畢涓鸿櫄鎷熶綇瀹�,鐩存帴鏀圭紦瀛�
-                    ((ColorTemperatureLight)this.device).Level = value * MaxLevel / 100;
+                    ((ColorTemperatureLight)this.device).Level = HdlDeviceCommonLogic.Current.CalculateLightLevel(value);
                     //浜害 XX
                     this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                 }
@@ -257,13 +248,12 @@
             int nowColorValue = oldColorValue;//鍙樻洿鐨勫��
             seekBarColor.OnProgressChangedEvent += (sender, value) =>
             {
+                //璁剧疆鑷畾涔夌殑鏂囨湰
+                seekBarColor.SetCustomText(value * 100 + "K");
                 if (Common.Config.Instance.Home.IsVirtually == false)
                 {
-                    if (this.canSetProgressValue == true)
-                    {
-                        //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰�
-                        nowColorValue = value;
-                    }
+                    //鑳藉鍙戦�佽繘搴﹀�肩殑鏃跺��,鎵嶈褰�
+                    nowColorValue = value;
                 }
                 else
                 {
@@ -271,8 +261,13 @@
                     ((ColorTemperatureLight)this.device).ColorTemperature = value * 100;
                 }
             };
+            if (Config.Instance.Home.IsVirtually == true)
+            {
+                //铏氭嫙浣忓畢
+                return;
+            }
 
-            //寮�涓�涓嚎绋�,鐩戣鏄惁婊戝姩鐨勬粦鍔ㄦ潯,姣忕妫�娴嬩竴娆�
+                //寮�涓�涓嚎绋�,鐩戣鏄惁婊戝姩鐨勬粦鍔ㄦ潯,姣忕妫�娴嬩竴娆�
             HdlThreadLogic.Current.RunThread(() =>
             {
                 while (this.Parent != null)
@@ -282,7 +277,7 @@
                     if (nowLightValue != oldLightValue)
                     {
                         oldLightValue = nowLightValue;
-                        ((ColorTemperatureLight)this.device).SetLevel((int)(oldLightValue * MaxLevel / 100.0));
+                        ((ColorTemperatureLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(oldLightValue));
                     }
                     //鍙戦�佽壊娓╁��
                     if (nowColorValue != oldColorValue)
@@ -292,20 +287,17 @@
                         ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                     }
                 }
-                if (this.canSetProgressValue == true)
+                //鐣岄潰鍏抽棴鏃�
+                if (nowLightValue != oldLightValue)
                 {
-                    //鐣岄潰鍏抽棴鏃�
-                    if (nowLightValue != oldLightValue)
-                    {
-                        //鍙戦�佷寒搴﹀��
-                        ((ColorTemperatureLight)this.device).SetLevel((int)(nowLightValue * MaxLevel / 100.0));
-                    }
-                    if (nowColorValue != oldColorValue)
-                    {
-                        //鍙戦�佽壊娓╁��
-                        int value = 1000000 / (nowColorValue * 100);
-                        ((ColorTemperatureLight)this.device).SetColorTemperature(value);
-                    }
+                    //鍙戦�佷寒搴﹀��
+                    ((ColorTemperatureLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(nowLightValue));
+                }
+                if (nowColorValue != oldColorValue)
+                {
+                    //鍙戦�佽壊娓╁��
+                    int value = 1000000 / (nowColorValue * 100);
+                    ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                 }
             });
         }
@@ -320,17 +312,21 @@
         /// <param name="isOpen"></param>
         private void SetLightSwitchCommand(bool isOpen)
         {
+            //鑾峰彇褰撳墠浜害
+            int level = Convert.ToInt32(this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, this.device, null));
             //濡傛灉浣忓畢鏄櫄鎷熶綇瀹�
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
                 ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
+                if (((LightBase)this.device).OnOffStatus == 1 && level == 0)
+                {
+                    //濡傛灉褰撳墠鏄墦寮�鐘舵��,骞朵笖浜害涓�0鐨勮瘽,鍒欓渶瑕佸彉鎴�100%浜害
+                    this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, this.device, new object[] { 100 });
+                }
                 //鍒锋柊寮�鍏崇姸鎬�
                 this.RefreshSwitchStatu(isOpen);
                 return;
             }
-
-            //褰撴寜涓嬪紑鍏虫寜閽椂,涓嶈兘鍐嶅彂閫佽繘搴﹀��
-            this.canSetProgressValue = false;
 
             //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅
             this.StartCheckResponeResult(new List<ButtonBase> { this.btnMiniSwitch.btnIcon }, (result) =>
@@ -343,12 +339,6 @@
                          bool statu = ((LightBase)this.device).OnOffStatus == 1;
                          //鍒锋柊寮�鍏崇姸鎬�
                          this.RefreshSwitchStatu(statu);
-                         if (statu == true)
-                         {
-                             //褰撴槸鎵撳紑鐘舵�佹椂,缃戝叧璇村畠浼氶粯璁ゆ妸浜害鍙樻垚100%
-                             //浠ラ槻涓囦竴,杩欓噷鍐嶆璇诲彇涓�涓�
-                             ((ColorTemperatureLight)device).ReadLevel();
-                         }
                      }
                  });
              });
@@ -357,7 +347,15 @@
             if (isOpen == true)
             {
                 //鎵撳紑
-                this.device.SwitchControl(1);
+                if (level == 0)
+                {
+                    //濡傛灉褰撳墠鏄墦寮�鐘舵��,骞朵笖浜害涓�0鐨勮瘽,鍒欓渶瑕佸彉鎴�100%浜害
+                    this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 255 });
+                }
+                else
+                {
+                    this.device.SwitchControl(1);
+                }
             }
             else
             {
@@ -379,24 +377,23 @@
             //濡傛灉浣忓畢鏄櫄鎷熶綇瀹�
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
-                //((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
-                ////鍒锋柊寮�鍏崇姸鎬�
-                //this.RefreshSwitchStatu(isOpen);
+                ((ColorTemperatureLight)this.device).IsBuzzerRing = isOpen;
+                //鍒锋柊寮�鍏崇姸鎬�
+                this.RefreshSwitchStatu(isOpen);
                 return;
             }
 
             //妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅
-            this.StartCheckResponeResult(new List<ButtonBase> { this.btnBuzzerSwitch.btnIcon }, (result) =>
+            this.btnBuzzerSwitch.CanClick = false;
+            this.StartCheckResponeResult(new List<ButtonBase>(), (result) =>
             {
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //鎺ユ敹鍒扮綉鍏冲洖澶�
+                    this.btnBuzzerSwitch.CanClick = true;
                     if (result == true)
                     {
                         this.btnBuzzerSwitch.IsSelected = isOpen;
-                        //bool statu = ((LightBase)this.device).OnOffStatus == 1;
-                        ////鍒锋柊寮�鍏崇姸鎬�
-                        //this.RefreshSwitchStatu(statu);
                     }
                 });
             });
@@ -463,36 +460,48 @@
         /// <param name="isOpen">鎵撳紑鐘舵��</param>
         private void RefreshSwitchStatu(bool isOpen)
         {
-            if (this.isColorProgressing == true)
+            //鍒锋柊铚傞福鍣ㄥ紑鍏崇姸鎬�
+            bool isBuzzerRing = ((ColorTemperatureLight)this.device).IsBuzzerRing;
+            if (this.btnBuzzerSwitch.IsSelected != isBuzzerRing)
             {
-                //濡傛灉鏄壊娓╂粦鍔ㄧ殑璇�,涓嶉渶瑕佸埛鏂扮晫闈�
-                return;
+                this.btnBuzzerSwitch.IsSelected = isBuzzerRing;
             }
+
             if (isOpen == true)
             {
                 //浜害鏄繀椤昏鍒锋柊鐨�  浜害 XX
                 this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
-                if (this.isLightProgressing == false)
+                if (this.btnMiniSwitch.IsSelected == false)
                 {
-                    //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫�
-                    seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
+                    this.btnMiniSwitch.IsSelected = true;
                 }
-                if (this.isColorProgressing == false)
-                {
-                    //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫�
-                    seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
-                }
-                this.btnMiniSwitch.IsSelected = true;
             }
             else
             {
-                //鍙樻洿瀛楁牱:鍏抽棴
-                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
-                this.btnMiniSwitch.IsSelected = false;
+                if (this.btnMiniSwitch.IsSelected == true)
+                {
+                    this.btnMiniSwitch.IsSelected = false;
+                    //鍙樻洿瀛楁牱:鍏抽棴
+                    this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
+                }
             }
 
-            //鍥炲鐨勭粨鏋滆,澶勪簬鎵撳紑鐘舵�佹墠鑳藉彂閫�
-            this.canSetProgressValue = isOpen;
+            if (this.isLightProgressing == false)
+            {
+                //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫�
+                int progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level);
+                if (seekBarLight.Progress != progress)
+                {
+                    seekBarLight.Progress = progress;
+                }
+            }
+            if (this.isColorProgressing == false)
+            {
+                //褰撹繘搴﹀�煎湪鎵嬪姩鍙樻洿涓椂,涓嶆帴鏀舵帹閫�
+                seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
+                //璁剧疆鑷畾涔夌殑鏂囨湰
+                seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K");
+            }
         }
 
         #endregion

--
Gitblit v1.8.0