2
wei
2021-03-09 d41f1d4a478c1afcc43f3a5abb0ba76e376bc7c1
HDL_ON/UI/UI2/FuntionControlView/Electrical/TuyaWaterValvePage.cs
@@ -16,17 +16,19 @@
        /// </summary>
        private PicViewControl btnPictrue = null;
        /// <summary>
        /// 滤芯使用率控件
        /// 控制器控制状态提示文本按钮
        /// </summary>
        private NormalViewControl btnUsePersent = null;
        NormalViewControl btnControlTip = null;
        /// <summary>
        /// 天气延时
        /// 控制器控制时间提示文本按钮
        /// </summary>
        private NormalViewControl btnWeatherDelay = null;
        NormalViewControl btnControlTimeTip = null;
        /// <summary>
        /// 湿度
        ///
        /// </summary>
        private NormalViewControl btnWeatherDelayControl = null;
        private IconViewControl btnTimeSet = null;
        /// <summary>
        /// 开关控件
        /// </summary>
@@ -40,14 +42,18 @@
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.SetTitleText(Language.StringByID(StringId.AirCleaner));
            base.SetTitleText(Language.StringByID(StringId.WaterValve));
            //添加第二索引页
            this.AddSecondPage();
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //刷新界面状态
            this.RefreshFormStatu();
            //读取状态
            new System.Threading.Thread(() =>
            {
                Control.Ins.ReadFunctionsInfo(new List<string>() { device.deviceId});
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
@@ -56,8 +62,8 @@
        private void InitFrameWhiteContent1()
        {
            //图片控件
            this.btnPictrue = new PicViewControl(94, 130);
            btnPictrue.Y = Application.GetRealHeight(90);
            this.btnPictrue = new PicViewControl(130, 118);
            btnPictrue.Y = Application.GetRealHeight(95);
            btnPictrue.Gravity = Gravity.CenterHorizontal;
            btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveBg.png";
            btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveOnBg.png";
@@ -66,6 +72,43 @@
            {
                //发送开关命令
                this.SendSwitchComand();
            };
            btnControlTip = new NormalViewControl(300,30, true)
            {
                Y = Application.GetRealHeight(231),
                TextAlignment = TextAlignment.Center,
                Gravity = Gravity.CenterHorizontal,
                TextSize = CSS_FontSize.TextFontSize,
                SelectedTextColor = CSS_Color.MainColor,
                TextColor = CSS_Color.TextualColor,
                TextID = StringId.ControllerNotOn,
            };
            FrameWhiteCentet1.AddChidren(btnControlTip);
            btnControlTimeTip = new NormalViewControl(300, 30, true)
            {
                Y = Application.GetRealHeight(252),
                Gravity = Gravity.CenterHorizontal,
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.TextFontSize,
                //TextColor = 0x00000000,
                SelectedTextColor = CSS_Color.TextualColor,
                TextColor = CSS_Color.TextualColor,
                Text = "00:00:00"
            };
            FrameWhiteCentet1.AddChidren(btnControlTimeTip);
            btnTimeSet = new IconViewControl(50)
            {
                Y = Application.GetRealHeight(365),
                Gravity = Gravity.CenterHorizontal,
                UnSelectedImagePath = "FunctionIcon/Electrical/WaterValve/SetTimeIcon.png",
                SelectedImagePath = "FunctionIcon/Electrical/WaterValve/SetTimeIcon.png",
            };
            FrameWhiteCentet1.AddChidren(btnTimeSet);
            btnTimeSet.ButtonClickEvent = (sender, e) => {
                SetControlTime();
            };
            //开关图标
@@ -80,6 +123,8 @@
                //发送开关命令
                this.SendSwitchComand();
            };
            var pack = new DAL.Server.HttpServerRequest().GetDeviceInfoList(new List<string>() { base.device.deviceId  });
        }
        #endregion
@@ -111,7 +156,6 @@
            this.btnSwitch.CanClick = false;
            string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
            //btnSwitch.IsSelected = !btnSwitch.IsSelected;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
@@ -136,16 +180,103 @@
        {
            Application.RunOnMainThread(() =>
            {
                foreach (var data in this.device.attributes)
                var onoffStatu = device.attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff);
                var timeStatu = device.attributes.Find((obj) => obj.key == FunctionAttributeKey.TuyaWaterTime);
                if (onoffStatu != null)
                {
                    if (data.key == FunctionAttributeKey.OnOff)
                    if (onoffStatu.state == "on")
                    {
                        this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = data.curValue.ToString() == "on";
                        btnControlTip.TextID = StringId.ControllerOn;
                    }
                    else
                    {
                        btnControlTip.TextID = StringId.ControllerNotOn;
                    }
                    this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = onoffStatu.state.ToString() == "on";
                }
                if (timeStatu != null)
                {
                    int.TryParse(timeStatu.state, out waterRunningTime);
                }
                RefreshTimeButton();
            });
        }
        System.Threading.Thread refreshTimeThread;
        int waterRunningTime = 0;
        /// <summary>
        /// 刷新水阀时间文本
        /// </summary>
        private void RefreshTimeButton()
        {
            if (refreshTimeThread == null || refreshTimeThread.ThreadState == System.Threading.ThreadState.Stopped)
            {
                refreshTimeThread = new System.Threading.Thread(() =>
                {
                    while (waterRunningTime >= 0)
                    {
                        if (waterRunningTime > 0)
                        {
                            waterRunningTime--;
                        }
                        var sce = waterRunningTime % 60;
                        var min = 0;
                        if(waterRunningTime > 60)
                        {
                            min = (waterRunningTime - sce) / 60 %60;
                        }
                        var hour = 0;
                        if(waterRunningTime > 360)
                        {
                             hour = (waterRunningTime - sce - (min * 60)) / 3600;
                        }
                        Application.RunOnMainThread(() =>
                        {
                            btnControlTimeTip.Text = $"{hour.ToString().PadLeft(2,'0')}:{min.ToString().PadLeft(2, '0')}:{sce.ToString().PadLeft(2, '0')}";
                        });
                        System.Threading.Thread.Sleep(1000);
                    }
                })
                { IsBackground = true };
            }
            refreshTimeThread.Start();
        }
        public override void RemoveFromParent()
        {
            if (refreshTimeThread != null)
            {
                refreshTimeThread.Abort();
            }
            base.RemoveFromParent();
        }
        #endregion
        private void SetControlTime()
        {
            var timeControl = new BottomTimeSelectControl();
            timeControl.RowCount = 5;
            timeControl.InitControl(0,0);
            timeControl.FinishEvent = (type,hours,min) => {
                if (type == 1)//0:取消;1:确定
                {
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        var time = hours * 60 * 60 + min * 60;
                        var dic = new Dictionary<string, string>();
                        dic.Add(FunctionAttributeKey.TuyaWaterTime, time.ToString());
                        Control.Ins.SendWriteCommand(this.device, dic, true);
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            waterRunningTime = time;
                            this.btnControlTimeTip.Text = $"{hours.ToString().PadLeft(2, '0')}:{min.ToString().PadLeft(2, '0')}:00";
                        });
                    });
                }
            };
        }
    }
}