wxr
2022-11-23 5b77d9d57a6cddb474a66ca54401ad5ab0892db3
HDL_ON/UI/UI2/FuntionControlView/Acst/AcstParentPage.cs
@@ -16,7 +16,9 @@
    {
        static AcstParentPage basePage;
        VerticalScrolViewLayout bodyView;
        VerticalScrolViewLayout contentView;
        string helloText = "上午好";
        #region 天气控件
        Button btnOutdoorTemp;
@@ -64,10 +66,49 @@
        public AcstParentPage()
        {
            basePage = this;
            var curTime = DateTime.Now;
            if (Language.CurrentLanguage != "Chinese")
            {
                helloText = "Good morning";
            }
            if (curTime.Hour >= 8 && curTime.Hour < 12)
            {
                helloText = "上午好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good morning";
                }
                curColor = CSS.CSS_Color.MainColor;
                imageFolder = "blue";
            }
            else if (curTime.Hour >= 12 && curTime.Hour < 18)
            {
                helloText = "下午好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good afternoon";
                }
                curColor = 0xFFE7914F;
                imageFolder = "orange";
            }
            else
            {
                helloText = "晚上好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good evening";
                }
                curColor = 0xFF9175F3;
                imageFolder = "purple";
            }
            this.function = FunctionList.List.GetAcstParentList()[0];
            this.BackgroundColor = CSS.CSS_Color.BackgroundColor;
            bodyView = new VerticalScrolViewLayout();
            this.AddChidren(bodyView);
            this.AddChidren(new Button() { Height = Application.GetRealHeight(50), BackgroundColor = curColor });
            contentView = new VerticalScrolViewLayout() {
                Height = Application.GetRealHeight(667 - 56),
            };
            this.AddChidren(contentView);
            subViewList = new Dictionary<string, AcstSubControlView>();
        }
        /// <summary>
@@ -93,6 +134,8 @@
        /// </summary>
        public static void UpdateAcstParentInfo(Function temp)
        {
            try
            {
            if (basePage == null)
            {
                return;
@@ -100,21 +143,21 @@
            Application.RunOnMainThread(() =>
            {
                if (basePage.sensorDiyView_Temp != null)
                    basePage.sensorDiyView_Temp.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_temp.ToString()).state);
                        basePage.sensorDiyView_Temp.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_temp.ToString()).state, true);
                if (basePage.sensorDiyView_Humi != null)
                    basePage.sensorDiyView_Humi.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_humidity.ToString()).state);
                        basePage.sensorDiyView_Humi.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.room_humidity.ToString()).state, true);
                if (basePage.sensorDiyView_Pm25 != null)
                    basePage.sensorDiyView_Pm25.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.pm25.ToString()).state);
                        basePage.sensorDiyView_Pm25.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.pm25.ToString()).state, false);
                if (basePage.sensorDiyView_Co2 != null)
                    basePage.sensorDiyView_Co2.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.co2.ToString()).state);
                        basePage.sensorDiyView_Co2.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.co2.ToString()).state, false);
                if (basePage.sensorDiyView_Tvoc != null)
                    basePage.sensorDiyView_Tvoc.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.tvoc.ToString()).state);
                        basePage.sensorDiyView_Tvoc.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.tvoc.ToString()).state, false);
                if (basePage.sensorDiyView_EleDay != null)
                    basePage.sensorDiyView_EleDay.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.day_electricity.ToString()).state);
                        basePage.sensorDiyView_EleDay.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.day_electricity.ToString()).state, false);
                if (basePage.sensorDiyView_EleMonth != null)
                    basePage.sensorDiyView_EleMonth.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.month_electricity.ToString()).state);
                        basePage.sensorDiyView_EleMonth.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.month_electricity.ToString()).state, false);
                if (basePage.sensorDiyView_EleActivePower != null)
                    basePage.sensorDiyView_EleActivePower.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.active_power.ToString()).state);
                        basePage.sensorDiyView_EleActivePower.UpdateValue(temp.GetAttribute(AcstParent_AttrEnum.active_power.ToString()).state, false);
@@ -162,6 +205,10 @@
                }
                basePage.btnModeControl.IsSelected = basePage.btnWorkSceneControl.IsSelected = basePage.btnPowerControl.IsSelected = temp.GetAttrState("on_off") == "on";
            });
            }catch (Exception ex)
            {
                MainPage.Log("科技系统更新数据失败");
            }
        }
@@ -171,11 +218,14 @@
        /// <param name="temp"></param>
        public static void UpdateAcstSubInfo(Function temp)
        {
            try
            {
            if(basePage == null)
            {
                return;
            }
            Application.RunOnMainThread(() => {
                Application.RunOnMainThread(() =>
                {
                var view = basePage.subViewList[temp.sid];
                if(view!= null)
                {
@@ -185,54 +235,21 @@
                }
            });
        }
            catch (Exception ex)
            {
                MainPage.Log("科技系统更新异常11");
            }
        }
        public void LoadPage()
        {
            var curTime = DateTime.Now;
            string helloText = "上午好";
            if (Language.CurrentLanguage != "Chinese")
            {
                helloText = "Good morning";
            }
            if (curTime.Hour >= 8 && curTime.Hour < 12)
            {
                helloText = "上午好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good morning";
                }
                curColor = CSS.CSS_Color.MainColor;
                imageFolder = "blue";
            }
            else if (curTime.Hour >= 12 && curTime.Hour < 18)
            {
                helloText = "下午好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good afternoon";
                }
                curColor = 0xFFE7914F;
                imageFolder = "orange";
            }
            else
            {
                helloText = "晚上好";
                if (Language.CurrentLanguage != "Chinese")
                {
                    helloText = "Good evening";
                }
                curColor = 0xFF9175F3;
                imageFolder = "purple";
            }
            #region 头部信息区域
            FrameLayout topView = new FrameLayout()
            {
                Height = Application.GetRealHeight(180),
                BackgroundImagePath = $"FunctionIcon/Acst/{imageFolder}/TopViewBg.png",
            };
            bodyView.AddChidren(topView);
            contentView.AddChidren(topView);
            var backView = new FrameLayout()
            {
@@ -353,7 +370,7 @@
            #endregion
            bodyView.AddChidren(new Button
            contentView.AddChidren(new Button
            {
                Height = Application.GetRealHeight(8),
            });
@@ -417,7 +434,7 @@
                    Height = Application.GetRealHeight(104),
                    BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
                };
                bodyView.AddChidren(infoView);
                contentView.AddChidren(infoView);
                var infoContentView = new FrameLayout()
                {
@@ -442,23 +459,33 @@
                if (tempObj != null)
                {
                    sensorDiyView_Temp = new SensorDiyView(sensorListView, curColor, tempObj.state == "" ? "--" : tempObj.state, "°", Language.StringByID(StringId.Temp));
                    string tempValues = tempObj.state == "" ? "--" : tempObj.state;
                    if (tempValues.Contains("."))
                    {
                        tempValues = tempValues.Remove(tempValues.IndexOf('.'), tempValues.Length - tempValues.IndexOf('.'));
                    }
                    sensorDiyView_Temp = new SensorDiyView(sensorListView, curColor, tempValues, "°","", Language.StringByID(StringId.Temp));
                }
                if (humiObj != null)
                {
                    sensorDiyView_Humi = new SensorDiyView(sensorListView, curColor, humiObj.state == "" ? "--" : humiObj.state, "%", Language.StringByID(StringId.Humidity));
                    string humiValues = humiObj.state == "" ? "--" : humiObj.state;
                    if (humiValues.Contains("."))
                    {
                        humiValues = humiValues.Remove(humiValues.IndexOf('.'), humiValues.Length - humiValues.IndexOf('.'));
                    }
                    sensorDiyView_Humi = new SensorDiyView(sensorListView, curColor, humiValues , "%", "", Language.StringByID(StringId.Humidity));
                }
                if (pm25Obj != null)
                {
                    sensorDiyView_Pm25 = new SensorDiyView(sensorListView, curColor, pm25Obj.state == "" ? "--" : pm25Obj.state, "", "PM2.5");
                    sensorDiyView_Pm25 = new SensorDiyView(sensorListView, curColor, pm25Obj.state == "" ? "--" : pm25Obj.state, "", "", "PM2.5");
                }
                if (co2Obj != null)
                {
                    sensorDiyView_Co2 = new SensorDiyView(sensorListView, curColor, co2Obj.state == "" ? "--" : co2Obj.state, "", "CO2");
                    sensorDiyView_Co2 = new SensorDiyView(sensorListView, curColor, co2Obj.state == "" ? "--" : co2Obj.state, "", "", "CO2");
                }
                if (tvocObj != null)
                {
                    sensorDiyView_Tvoc = new SensorDiyView(sensorListView, curColor, tvocObj.state == "" ? "--" : tvocObj.state, "", "TVOC");
                    sensorDiyView_Tvoc = new SensorDiyView(sensorListView, curColor, tvocObj.state == "" ? "--" : tvocObj.state, "", "", "TVOC");
                }
                #endregion
@@ -467,7 +494,7 @@
                {
                    Width = Application.GetRealWidth(100 * energyCount),
                    Gravity = Gravity.Center,
                    Visible = false,
                    Visible = sensorCount == 0
                };
                if (energyCount > 0)
                {
@@ -480,8 +507,7 @@
                    {
                        text = "Power";
                    }
                    sensorDiyView_EleActivePower = new SensorDiyView(energyListView, curColor, totalObj.state == "" ? "--" : totalObj.state, "KW", text, 100);
                    sensorDiyView_EleActivePower = new SensorDiyView(energyListView, curColor, totalObj.state == "" ? "--" : totalObj.state, "", "KW", text, 100);
                }
                if (dayObj != null)
                {
@@ -490,7 +516,7 @@
                    {
                        text = "Power of today";
                    }
                    sensorDiyView_EleDay = new SensorDiyView(energyListView, curColor, dayObj.state == "" ? "--" : dayObj.state, "KW", text, 100);
                    sensorDiyView_EleDay = new SensorDiyView(energyListView, curColor, dayObj.state == "" ? "--" : dayObj.state, "", "KWh", text, 100);
                }
                if (monthObj != null)
                {
@@ -499,7 +525,7 @@
                    {
                        text = "Power of month";
                    }
                    sensorDiyView_EleMonth = new SensorDiyView(energyListView, curColor, monthObj.state == "" ? "--" : monthObj.state, "KWh", text, 100);
                    sensorDiyView_EleMonth = new SensorDiyView(energyListView, curColor, monthObj.state == "" ? "--" : monthObj.state, "", "KWh", text, 100);
                }
@@ -537,7 +563,7 @@
            {
                Height = Application.GetRealHeight(54-11),
            };
            bodyView.AddChidren(subTitleView);
            contentView.AddChidren(subTitleView);
            var btnCollection = new Button()
            {
@@ -583,10 +609,14 @@
            {
                Height = Application.GetRealHeight(88),
            };
            bodyView.AddChidren(subFunctionListView);
            contentView.AddChidren(subFunctionListView);
            subFunctionListView.AddChidren(new Button { Width = Application.GetRealWidth(9) });
            new System.Threading.Thread(() =>
            {
                try
                {
            foreach (var sub in FunctionList.List.GetAcstSubList())
            {
                if (subViewList.ContainsKey(sub.sid))
@@ -594,31 +624,38 @@
                    continue;
                }
                        Application.RunOnMainThread(() =>
                        {
                if (subFunctionCount > 0 && subFunctionCount % 2 == 0)
                {
                    subFunctionListView = new HorizontalScrolViewLayout()
                    {
                        Height = Application.GetRealHeight(93),
                    };
                    bodyView.AddChidren(subFunctionListView);
                                contentView.AddChidren(subFunctionListView);
                    subFunctionListView.AddChidren(new Button { Width = Application.GetRealWidth(9) });
                }
                AcstSubControlView subFunctionView = new AcstSubControlView(sub, subFunctionListView,imageFolder);
                subViewList.Add(sub.sid, subFunctionView);
                            new System.Threading.Thread(() =>
                            {
                Control.Ins.SendReadCommand(sub);
                            })
                            { IsBackground = true }.Start();
                subFunctionCount++;
            }
                        });
                        System.Threading.Thread.Sleep(10);
                    }
                }
                catch { }
                finally{
                }
            }).Start();
            #endregion
            bodyView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(72),
            });
            #region 底部控制栏
            var bottomView = new FrameLayout()
@@ -643,10 +680,10 @@
            bottomView.AddChidren(btnModeControl);
            btnModeControl.MouseUpEventHandler = (sender3, e3) =>
            {
                if(function.trait_on_off.state == "off")
                {
                    return;
                }
                //if(function.trait_on_off.state == "off")
                //{
                //    return;
                //}
                Dialog dialog = new Dialog();
                var dialogView = new FrameLayout();
@@ -675,7 +712,7 @@
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(100),
                    TextID = StringId.SelectScene,
                    TextID = StringId.SelectMode,
                    TextSize = 16,
                    TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                    IsBold = true,
@@ -752,41 +789,6 @@
                    heatView.AddChidren(heatIconButton);
                    #endregion
                }
                if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.humidity.ToString()))
                {
                    #region 除湿
                    var dehumiView = new FrameLayout()
                    {
                        X = Application.GetRealWidth(2),
                        Width = Application.GetRealWidth(144),
                        Height = Application.GetRealHeight(44),
                    };
                    dialogContentView.AddChidren(dehumiView);
                    dehumiView.AddChidren(new Button
                    {
                        Width = Application.GetRealWidth(112),
                        Gravity = Gravity.CenterHorizontal,
                        Height = 1,
                        BackgroundColor = CSS.CSS_Color.DividingLineColor,
                    });
                    IconButton dehumiIconButton = new IconButton("FunctionIcon/Acst/grey/ModeDeHumiIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon.png",
                        Language.StringByID(StringId.Humidity), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.dry.ToString());
                    dehumiIconButton.Click(() =>
                    {
                        btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon2.png";
                        dialog.Close();
                        new System.Threading.Thread(() =>
                        {
                            Dictionary<string, string> d = new Dictionary<string, string>();
                            d.Add("mode", AcstParent_Attr_ModeValueEnum.dry.ToString());
                            Control.Ins.SendWriteCommand(function, d);
                        })
                        { IsBackground = true }.Start();
                    });
                    dehumiView.AddChidren(dehumiIconButton);
                    #endregion
                }
                if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.fan.ToString()))
                {
@@ -823,6 +825,40 @@
                    #endregion
                }
                if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.dry.ToString()))
                {
                    #region 除湿
                    var dehumiView = new FrameLayout()
                    {
                        X = Application.GetRealWidth(2),
                        Width = Application.GetRealWidth(144),
                        Height = Application.GetRealHeight(44),
                    };
                    dialogContentView.AddChidren(dehumiView);
                    dehumiView.AddChidren(new Button
                    {
                        Width = Application.GetRealWidth(112),
                        Gravity = Gravity.CenterHorizontal,
                        Height = 1,
                        BackgroundColor = CSS.CSS_Color.DividingLineColor,
                    });
                    IconButton dehumiIconButton = new IconButton("FunctionIcon/Acst/grey/ModeDeHumiIcon.png", $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon.png",
                        Language.StringByID(StringId.Dry), curColor, function.GetAttrState(AcstParent_AttrEnum.mode.ToString()) == AcstParent_Attr_ModeValueEnum.dry.ToString());
                    dehumiIconButton.Click(() =>
                    {
                        btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/ModeDeHumiIcon2.png";
                        dialog.Close();
                        new System.Threading.Thread(() =>
                        {
                            Dictionary<string, string> d = new Dictionary<string, string>();
                            d.Add("mode", AcstParent_Attr_ModeValueEnum.dry.ToString());
                            Control.Ins.SendWriteCommand(function, d);
                        })
                        { IsBackground = true }.Start();
                    });
                    dehumiView.AddChidren(dehumiIconButton);
                    #endregion
                }
                if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.heat_humidity.ToString()))
                {
@@ -861,7 +897,6 @@
                if (function.GetAttribute(AcstParent_AttrEnum.mode.ToString()).value.Contains(AcstParent_Attr_ModeValueEnum.humidity.ToString()))
                {
                    #region 加湿
                    var humiView = new FrameLayout()
                    {
@@ -943,10 +978,10 @@
            btnWorkSceneControl.MouseUpEventHandler = (sender2, e2) =>
            {
                if (function.trait_on_off.state == "off")
                {
                    return;
                }
                //if (function.trait_on_off.state == "off")
                //{
                //    return;
                //}
                Dialog dialog = new Dialog();
                var dialogView = new FrameLayout();
@@ -1009,7 +1044,7 @@
                    Language.StringByID(StringId.AtHome), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.at_home.ToString());
                    atHomeIconButton.Click(() =>
                    {
                        btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAtHome2.png";
                        btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAtHome2.png";
                        dialog.Close();
                        new System.Threading.Thread(() =>
                        {
@@ -1046,7 +1081,7 @@
                        Language.StringByID(StringId.AwayHome), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.leave_home.ToString());
                    awayHomeIconButton.Click(() =>
                    {
                        btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAwayHomeIcon2.png";
                        btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneAwayHomeIcon2.png";
                        dialog.Close();
                        new System.Threading.Thread(() =>
                        {
@@ -1084,7 +1119,7 @@
                        Language.StringByID(StringId.Sleep), curColor, function.GetAttrState(AcstParent_AttrEnum.scene.ToString()) == AcstParent_Attr_SceneValueEnum.sleep.ToString());
                    sleepIconButton.Click(() =>
                    {
                        btnModeControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneSleepIcon2.png";
                        btnWorkSceneControl.SelectedImagePath = $"FunctionIcon/Acst/{imageFolder}/SceneSleepIcon2.png";
                        dialog.Close();
                        new System.Threading.Thread(() =>
                        {
@@ -1108,7 +1143,11 @@
            InitGetWeatherAction();
            new System.Threading.Thread(() =>
            {
            Control.Ins.SendReadCommand(function);
            })
            { IsBackground = true }.Start();
        }
@@ -1127,7 +1166,7 @@
        public string Tag;
        public string unitString;
        public SensorDiyView(HorizontalScrolViewLayout view,uint color,string value,string unitStr,string text,int setWidth = 60)
        public SensorDiyView(HorizontalScrolViewLayout view,uint color,string value,string unitStr, string unitStr2, string text,int setWidth = 60)
        {
            unitString = unitStr;
            if (string.IsNullOrEmpty(value))
@@ -1166,10 +1205,21 @@
                Text = text,
            };
            contentView.AddChidren(btnText);
            if(!string.IsNullOrEmpty(unitStr2))
            {
                btnText.Text += "(" + unitStr2 + ")";
        }
        public void UpdateValue(string value)
        }
        public void UpdateValue(string value,bool isInt)
        {
            if (value.Contains(".") && isInt)
            {
                value = value.Remove(value.IndexOf('.'), value.Length - value.IndexOf('.'));
            }
            btnValue.Text = value + unitString;
        }
    }