From 6d73bf6e816570291865674bef8bce8972e4de3f Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期三, 01 十二月 2021 16:32:57 +0800
Subject: [PATCH] 2021-12-01-01

---
 HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs |  332 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 227 insertions(+), 105 deletions(-)

diff --git a/HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs b/HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs
index df3bb2f..9a7fe8d 100644
--- a/HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs
+++ b/HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
 using HDL_ON.Entity;
 using HDL_ON.UI.CSS;
+using HDL_ON.UI.Music;
 using Shared;
 
 namespace HDL_ON.UI
@@ -8,7 +9,7 @@
     public partial class FunctionControlZone : FrameLayout
     {
         #region 鍖哄煙鎺т欢
-        FrameLayout bodyDiv;
+        static FrameLayout bodyDiv;
         /// <summary>
         /// 鍔熻兘/鍦烘櫙icon
         /// </summary>
@@ -29,10 +30,15 @@
 
         #region 鍖哄煙鍙橀噺
         Function function;
+        /// <summary>
+        /// 鏄惁鍦ㄨ皟鍏�
+        /// </summary>
+        bool onDimmerBar;
         #endregion
         public FunctionControlZone(Function func)
         {
             bodyDiv = this;
+            bodyDiv.Tag = func.sid;
             function = func;
         }
 
@@ -47,6 +53,7 @@
         /// </summary>
         public void LoadFunctionDiv()
         {
+            //todo 澧炲姞璁惧锛屽鍔犲姛鑳藉垪琛ㄥ崱鐗�
             if (function == null)
             {
                 this.RemoveFromParent();
@@ -54,90 +61,105 @@
             }
             LoadDiv();
 
+            btnIcon.UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png";
 
-            if (function.functionCategory != FunctionType.Curtain)//绐楀笜娌℃湁寮�鍏虫寜閽�
+            if (SPK.CurtainSpkList().Contains(function.spk))
+            {//绐楀笜娌℃湁寮�鍏虫寜閽�
+                CurtainFragment();
+            }
+            else if (SPK.MusicSpkList().Contains(function.spk))
+            {//闊充箰娌℃湁寮�鍏虫寜閽�
+                MusicFragment();
+            }
+            else if (SPK.EvironmentSensorList().Contains(function.spk) || SPK.ArmSensorSpkList().Contains(function.spk)) //浼犳劅鍣ㄦ病鏈夊紑鍏虫寜閽�)
             {
-                #region 鍔犺浇寮�鍏虫寜閽�
-                /// <summary>
-                /// 寮�鍏虫寜閽�
-                /// </summary>
-                Button btnSwitch;
-                if (function.functionType == "RGB" || function.functionType == "Dimmer")
+                var powerLowTipAttr = function.attributes.Find((obj) => obj.key == FunctionAttributeKey.BatteryState);
+                if (powerLowTipAttr != null)
                 {
-                    btnSwitch = new Button()
+                    if (powerLowTipAttr.state.ToLower() == "low")
                     {
-                        X = Application.GetRealWidth(303),
-                        Y = Application.GetRealHeight(78),
-                        Width = Application.GetMinRealAverage(32),
-                        Height = Application.GetMinRealAverage(32),
-                        UnSelectedImagePath = "Public/PowerClose.png",
-                        SelectedImagePath = "Public/PowerOpen.png",
-                        Tag = function.functionType + "_Switch_" + function.sid
-                    };
-                    bodyDiv.AddChidren(btnSwitch);
-                }
-                else
-                {
-                    btnSwitch = new Button()
-                    {
-                        X = Application.GetRealWidth(303),
-                        Y = Application.GetRealHeight(58),
-                        Width = Application.GetMinRealAverage(32),
-                        Height = Application.GetMinRealAverage(32),
-                        UnSelectedImagePath = "Public/PowerClose.png",
-                        SelectedImagePath = "Public/PowerOpen.png",
-                        Tag = function.functionType + "_Switch_" + function.sid
-                    };
-                    bodyDiv.AddChidren(btnSwitch);
-                }
-                //鍔犺浇寮�鍏虫寜閽簨浠�
-                LoadEvent_LightSwitch(btnSwitch);
-
-                switch (function.functionCategory)
-                {
-                    case FunctionType.AC:
-                        btnIcon.UnSelectedImagePath = "FunctionIcon/AC/AcThinIcon.png";
-                        AcDiv();
-                        break;
-                    case FunctionType.Light:
-                        btnIcon.UnSelectedImagePath = "FunctionIcon/Light/LightThinIcon.png";
-                        btnSwitch.IsSelected = (function as Light).on_off == 1;
-                        LoadLightControl();
-                        break;
-                    case FunctionType.FloorHeating:
-                        btnIcon.UnSelectedImagePath = "FunctionIcon/FloorHeating/FloorHeatingThinIcon.png";
-                        FloorHeatingDiv();
-                        break;
-                    case FunctionType.Scene:
-                        btnIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
-                        if ((function as Scene).sceneType == SceneType.MovieScene)
+                        Button btnTipPowerLow = new Button()
                         {
-                            var movieIcon = new Button()
-                            {
-                                X = Application.GetRealWidth(52),
-                                Y = Application.GetRealHeight(14),
-                                Width = Application.GetRealWidth(16),
-                                Height = Application.GetRealWidth(16),
-                                UnSelectedImagePath = "FunctionIcon/Scene/MovieMark.png",
-                            };
-                            bodyDiv.AddChidren(movieIcon);
-
-                            btnName.X = movieIcon.Right;
-                        }
-                        break;
+                            X = Application.GetRealWidth(307),
+                            Y = Application.GetRealHeight(25),
+                            Width = Application.GetRealWidth(24),
+                            Height = Application.GetRealWidth(24),
+                            UnSelectedImagePath = "FunctionIcon/ArmSensor/PowerLowIcon.png",
+                            SelectedImagePath = "FunctionIcon/ArmSensor/PowerLowIcon.png",
+                        };
+                        this.AddChidren(btnTipPowerLow);
+                    }
                 }
-
-                #endregion
             }
             else
             {
-                btnIcon.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainThinIcon.png";
-                CurtainFragment();
+                if (function.spk == SPK.ClothesHanger)//鏅捐。鏋�
+                {
+                    ClothesHangerFragment();
+                }
+                else
+                {
+                    #region 鍔犺浇寮�鍏虫寜閽�
 
+                    /// <summary>
+                    /// 寮�鍏虫寜閽�
+                    /// </summary>
+                    Button btnSwitch;
+                    if (function.spk == SPK.LightRGB || function.spk == SPK.LightDimming)
+                    {
+                        btnSwitch = new Button()
+                        {
+                            X = Application.GetRealWidth(303),
+                            Y = Application.GetRealHeight(78),
+                            Width = Application.GetMinRealAverage(32),
+                            Height = Application.GetMinRealAverage(32),
+                            UnSelectedImagePath = "Public/PowerClose.png",
+                            SelectedImagePath = "Public/PowerOpen.png",
+                            IsSelected = function.trait_on_off.curValue.ToString() == "on",
+                            Tag = function.sid + "_Switch",
+                        };
+                        bodyDiv.AddChidren(btnSwitch);
+                        //鍔犺浇寮�鍏虫寜閽簨浠�
+                        LoadEvent_SwitchFunction(btnSwitch, function.attributes.Find((obj) => obj.key == FunctionAttributeKey.FadeTime));
+                    }
+                    else
+                    {
+                        btnSwitch = new Button()
+                        {
+                            X = Application.GetRealWidth(303),
+                            Y = Application.GetRealHeight(58),
+                            Width = Application.GetMinRealAverage(32),
+                            Height = Application.GetMinRealAverage(32),
+                            UnSelectedImagePath = "Public/PowerClose.png",
+                            SelectedImagePath = "Public/PowerOpen.png",
+                            IsSelected = function.trait_on_off.curValue.ToString() == "on",
+                            Tag = function.sid + "_Switch",
+                        };
+                        bodyDiv.AddChidren(btnSwitch);
+                        //鍔犺浇寮�鍏虫寜閽簨浠�
+                        LoadEvent_SwitchFunction(btnSwitch);
+                    }
+
+                    if (SPK.AcSpkList().Contains(function.spk) ||
+                        SPK.FhSpkList().Contains(function.spk))
+                    {
+                        LoadLastStatesButton();
+                    }
+                    else if (SPK.LightSpkList().Contains(function.spk))
+                    {
+                        btnSwitch.IsSelected = function.trait_on_off.curValue.ToString() == "on";
+                        LoadLightControl();
+                    }
+                    else if (SPK.ElectricalSpkList().Contains(function.spk))
+                    {
+                        btnSwitch.IsSelected = function.trait_on_off.curValue.ToString() == "on";
+                    }
+                    #endregion
+                }
             }
 
             LoadEvent_DivSkipEvent();
-            LoadCollectionEvent();
+            LoadEvent_FunctionCollection();
         }
 
         /// <summary>
@@ -149,14 +171,14 @@
             {
                 X = Application.GetRealWidth(10),
                 Y = Application.GetRealHeight(15),
-                Width = Application.GetMinRealAverage(32),
-                Height = Application.GetMinRealAverage(32),
+                Width = Application.GetRealWidth(32),
+                Height = Application.GetRealWidth(32),
             };
             bodyDiv.AddChidren(btnIcon);
 
             btnName = new Button()
             {
-                X = btnIcon.Right + Application.GetRealWidth(8),
+                X = Application.GetRealWidth(8 +10 + 32),
                 Y = Application.GetRealHeight(10),
                 Width = Application.GetRealWidth(200),
                 Height = Application.GetRealHeight(24),
@@ -169,8 +191,8 @@
 
             btnFromFloor = new Button()
             {
-                X = btnIcon.Right + Application.GetRealWidth(8),
-                Y = btnName.Bottom,
+                X = Application.GetRealWidth(8 + 10 + 32),
+                Y = Application.GetRealHeight(10 + 24),
                 Width = Application.GetRealWidth(200),
                 Height = Application.GetRealHeight(18),
                 Text = function.GetRoomListName(),
@@ -188,10 +210,12 @@
                 Height = Application.GetMinRealAverage(40),
                 SelectedImagePath = "Collection/CollectionIcon.png",
                 UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
-                IsSelected = function.collection
+                IsSelected = function.collect
             };
-            bodyDiv.AddChidren(btnCollectionIcon);
-
+            if ( !SPK.ArmSensorSpkList().Contains(function.spk) && !SPK.EnvironDeviceSpkList().Contains( function.spk))//!DB_ResidenceData.Instance.CurrentRegion.isOtherShare &&
+            {
+                bodyDiv.AddChidren(btnCollectionIcon);
+            }
         }
 
         /// <summary>
@@ -199,16 +223,16 @@
         /// </summary>
         void LoadLightControl()
         {
-            switch (function.functionType)
+            switch (function.spk)
             {
-                case "Dimmer":
-                case "RGB":
+                case SPK.LightDimming:
+                case SPK.LightRGB:
                     #region Dimmer
                     var btnDimmerMinValues = new Button()
                     {
                         X = Application.GetRealWidth(14),
                         Y = Application.GetRealHeight(85),
-                        Width = Application.GetRealWidth(22),
+                        Width = Application.GetRealWidth(30),
                         Height = Application.GetRealHeight(21),
                         Text = "0%",
                         TextAlignment = TextAlignment.CenterLeft,
@@ -219,27 +243,28 @@
 
                     var dimmerControlBar = new DiyImageSeekBar()
                     {
-                        X = btnDimmerMinValues.Right,
+                        X = Application.GetRealWidth(14 + 22),
                         Y = Application.GetRealHeight(68),//91,璁捐鏁版嵁
                         Width = Application.GetRealWidth(180),
                         Height = Application.GetRealHeight(54),
                         SeekBarViewHeight = Application.GetRealHeight(8),
                         ThumbImagePath = "Public/ThumbImage.png",
                         ThumbImageHeight = Application.GetRealHeight(54),
-                        ProgressBarColor = CSS_Color.AuxiliaryColor1,
+                        ProgressBarColor = function.trait_on_off.curValue.ToString() == "on" ? CSS_Color.AuxiliaryColor1 : CSS_Color.PromptingColor2,
                         ProgressTextColor = CSS_Color.FirstLevelTitleColor,
-                        ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
+                        ProgressTextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
                         MaxValue = 100,
-                        Progress = (function as Light).brightness,
-                        Tag = function.functionType + "_DimmerBar_" + function.sid
+                        Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
+                        Tag = function.sid + "_DimmerBar",
+                        SeekBarPadding = Application.GetRealWidth(20),
                     };
                     bodyDiv.AddChidren(dimmerControlBar);
 
                     var btnDimmerMaxValues = new Button()
                     {
-                        X = dimmerControlBar.Right,
+                        X = Application.GetRealWidth(14 + 22+180),
                         Y = Application.GetRealHeight(85),
-                        Width = Application.GetRealWidth(35),
+                        Width = Application.GetRealWidth(45),
                         Height = Application.GetRealHeight(21),
                         Text = "100%",
                         TextAlignment = TextAlignment.CenterLeft,
@@ -268,8 +293,15 @@
                 Height = Application.GetMinRealAverage(32),
                 UnSelectedImagePath = "FunctionIcon/Curtain/CurtainCloseIcon.png",
                 SelectedImagePath = "FunctionIcon/Curtain/CurtainCloseOnIcon.png",
+                IsSelected = function.GetAttrState(FunctionAttributeKey.OnOff) == "off",
+                Tag = function.sid + "_off"
             };
             bodyDiv.AddChidren(btnCurtainClose);
+            if(function.spk == SPK.CurtainRoller)
+            {
+                btnCurtainClose.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainDownIcon.png";
+                btnCurtainClose.SelectedImagePath = "FunctionIcon/Curtain/CurtainDownIconOn.png";
+            }
 
             var btnCurtainStop = new Button()
             {
@@ -279,6 +311,7 @@
                 Height = Application.GetMinRealAverage(32),
                 UnSelectedImagePath = "FunctionIcon/Curtain/CurtainStopIcon.png",
                 SelectedImagePath = "FunctionIcon/Curtain/CurtainStopOnIcon.png",
+                Tag = function.sid + "_stop",
             };
             bodyDiv.AddChidren(btnCurtainStop);
 
@@ -290,30 +323,119 @@
                 Height = Application.GetMinRealAverage(32),
                 UnSelectedImagePath = "FunctionIcon/Curtain/CurtainOpenIcon.png",
                 SelectedImagePath = "FunctionIcon/Curtain/CurtainOpenOnIcon.png",
+                Tag = function.sid + "_on",
+                IsSelected = function.GetAttrState(FunctionAttributeKey.OnOff) == "on",
             };
             bodyDiv.AddChidren(btnCurtainOpen);
+            if (function.spk == SPK.CurtainRoller)
+            {
+                btnCurtainOpen.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainUpIcon.png";
+                btnCurtainOpen.SelectedImagePath = "FunctionIcon/Curtain/CurtainUpIconOn.png";
+            }
+            LoadEvent_ControlCurtain(btnCurtainStop, btnCurtainOpen, btnCurtainClose, function);
+            #endregion
+        }
+        /// <summary>
+        /// 鍔犺浇鏅捐。鏋跺姛鑳芥帶鍒跺崱鐗�
+        /// </summary>
+        void ClothesHangerFragment()
+        {
+            #region ClothesHanger
+            var btnClothesHangerUp = new Button()
+            {
+                X = Application.GetRealWidth(233),
+                Y = Application.GetRealHeight(58),
+                Width = Application.GetMinRealAverage(32),
+                Height = Application.GetMinRealAverage(32),
+                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIcon1.png",
+                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIcon1On.png",
+            };
+            bodyDiv.AddChidren(btnClothesHangerUp);
+
+            var btnClothesHangerDown = new Button()
+            {
+                X = Application.GetRealWidth(303),
+                Y = Application.GetRealHeight(58),
+                Width = Application.GetMinRealAverage(32),
+                Height = Application.GetMinRealAverage(32),
+                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIcon1.png",
+                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIcon1On.png",
+            };
+            bodyDiv.AddChidren(btnClothesHangerDown);
+            LoadEvent_ControlClothesHanger(function,  btnClothesHangerUp, btnClothesHangerDown);
+            #endregion
 
 
+        }
 
+        /// <summary>
+        /// 鍔犺浇闊充箰鍔熻兘鎺у埗鍗$墖
+        /// </summary>
+        void MusicFragment()
+        {
+            #region Music
+            var btnPrev = new Button()
+            {
+                X = Application.GetRealWidth(163),
+                Y = Application.GetRealHeight(58),
+                Width = Application.GetMinRealAverage(32),
+                Height = Application.GetMinRealAverage(32),
+                UnSelectedImagePath = "MusicIcon/prev.png",
+                SelectedImagePath = "MusicIcon/prevSeletced.png",
+            };
+            bodyDiv.AddChidren(btnPrev);
+
+            var btnPlay = new Button()
+            {
+                X = Application.GetRealWidth(233),
+                Y = Application.GetRealHeight(58),
+                Width = Application.GetMinRealAverage(32),
+                Height = Application.GetMinRealAverage(32),
+                UnSelectedImagePath = "MusicIcon/pause.png",
+                SelectedImagePath = "MusicIcon/play.png",
+                //IsSelected = (function as A31MusicModel).A31PlayStatus.status == "play" ,
+                Tag = function.spk + "_State_" + function.sid
+            };
+            bodyDiv.AddChidren(btnPlay);
+
+            var btnNext = new Button()
+            {
+                X = Application.GetRealWidth(303),
+                Y = Application.GetRealHeight(58),
+                Width = Application.GetMinRealAverage(32),
+                Height = Application.GetMinRealAverage(32),
+                UnSelectedImagePath = "MusicIcon/next.png",
+                SelectedImagePath = "MusicIcon/nextSelected.png",
+            };
+            bodyDiv.AddChidren(btnNext);
+            LoadEvent_ControlMusic(btnPlay, btnNext, btnPrev, function as A31MusicModel);
             #endregion
         }
 
         /// <summary>
-        /// 鍔犺浇绌鸿皟鍔熻兘鎺у埗鍗$墖
+        /// 鍔犺浇鍔熻兘鐘舵�佷俊鎭寜閽�
         /// </summary>
-        void AcDiv()
+        void LoadLastStatesButton()
         {
-            #region AC
-            #endregion
-        }
-
-        /// <summary>
-        /// 鍔犺浇鍦扮儹鍔熻兘鎺у埗鍗$墖
-        /// </summary>
-        void FloorHeatingDiv()
-        {
-            #region 鍦扮儹
-            #endregion
+            if(function.spk == SPK.LightSwitch)
+            {
+                return;
+            }
+            var btnLastStates = new Button()
+            {
+                X = Application.GetRealWidth(10 + 32 + 8),
+                Y = Application.GetRealHeight(10 + 24 + 18),
+                Width = Application.GetRealWidth(200),
+                Height = Application.GetRealHeight(18),
+                Text = function.lastState,
+                TextAlignment = TextAlignment.CenterLeft,
+                SelectedTextColor = CSS_Color.PromptingColor1,
+                TextColor = 0x00000000,
+                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
+                Tag = function.spk + "_laststates_" + function.sid,
+                IsSelected = function.trait_on_off.curValue.ToString() == "on"
+            };
+            bodyDiv.AddChidren(btnLastStates);
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.8.0