xm
2020-07-10 acb2b278663952ce555b06a2e821f359225f15e0
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/DeviceControls/DeviceObjectControl.cs
New file
@@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 做成一个显示设备类型+设备MAC备注的RowLayout
    /// </summary>
    public class DeviceObjectControl : RowLayoutControl
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 设备的Mac地址
        /// </summary>
        public string deviceMac = string.Empty;
        /// <summary>
        /// 只会刷新一次
        /// </summary>
        private bool hadRefresh = false;
        /// <summary>
        /// 传感器推送中
        /// </summary>
        private bool sensorPushing = false;
        /// <summary>
        /// 在线状态
        /// </summary>
        private bool m_isOnline = true;
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool IsOnline
        {
            get { return m_isOnline; }
            set
            {
                if (m_isOnline != value)
                {
                    m_isOnline = value;
                    //设置在线状态的特效
                    this.SetOnlineStatu(m_isOnline);
                }
            }
        }
        /// <summary>
        /// 图标控件
        /// </summary>
        public IconViewControl btnIcon = null;
        /// <summary>
        /// 设备备注控件
        /// </summary>
        private NormalViewControl btnDeviceName = null;
        /// <summary>
        /// 设备房间控件
        /// </summary>
        private NormalViewControl btnDeviceRoom = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 做成一个显示设备类型+设备MAC备注的RowLayout
        /// </summary>
        /// <param name="i_deviceMac">设备的Mac地址</param>
        /// <param name="i_ChidrenYaxis">子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可)</param>
        public DeviceObjectControl(string i_deviceMac, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
        {
            this.deviceMac = i_deviceMac;
        }
        /// <summary>
        /// 初始化内部控件
        /// </summary>
        public void InitControl()
        {
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(this.deviceMac);
            if (listDevice.Count == 0)
            {
                //针对单纯只有一个200端点的设备
                listDevice.Add(Common.LocalDevice.Current.GetOTADevice(this.deviceMac));
            }
            //图标
            btnIcon = frameTable.AddLeftIcon(81);
            Common.LocalDevice.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
            //设备
            string deviceName = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
            btnDeviceName = frameTable.AddTopView(deviceName, 800);
            frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
            //房间
            string roomName = Common.LocalDevice.Current.GeteRealDeviceRoomName(listDevice[0]);
            btnDeviceRoom = frameTable.AddBottomView(roomName, 800);
            //底线
            frameTable.AddBottomLine();
            //设置在线状态的特效
            this.IsOnline = Common.LocalDevice.Current.CheckDeviceIsOnline(listDevice[0]);
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 设置在线状态的特效
        /// </summary>
        /// <param name="i_isOnline"></param>
        private void SetOnlineStatu(bool i_isOnline)
        {
            if (i_isOnline == false)
            {
                btnDeviceName.TextColor = UserCenterColor.Current.TextGrayColor1;
            }
            else
            {
                btnDeviceName.TextColor = UserCenterColor.Current.TextColor1;
            }
        }
        /// <summary>
        /// 刷新全部显示信息
        /// </summary>
        /// <param name="compel">是否强制执行</param>
        public void RefreshControlInfo(bool compel = false)
        {
            if (hadRefresh == true && compel == false)
            {
                return;
            }
            hadRefresh = true;
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(this.deviceMac);
            if (listDevice.Count == 0)
            {
                //针对单纯只有一个200端点的设备
                listDevice.Add(Common.LocalDevice.Current.GetOTADevice(this.deviceMac));
            }
            //图标
            Common.LocalDevice.Current.SetDeviceObjectIconToControl(btnIcon, listDevice);
            //设备
            btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
            //设备房间
            btnDeviceRoom.Text = Common.LocalDevice.Current.GeteRealDeviceRoomName(listDevice[0]);
        }
        /// <summary>
        /// 显示传感器上报的特效
        /// </summary>
        public void StartSensorPushAppeal()
        {
            if (this.sensorPushing == true)
            {
                //传感器正在特效中
                return;
            }
            this.sensorPushing = true;
            //设备
            uint oldTextColor1 = btnDeviceName.TextColor;
            btnDeviceName.TextColor = UserCenterColor.Current.TextOrangeColor;
            //设备房间
            uint oldTextColor2 = btnDeviceRoom.TextColor;
            btnDeviceRoom.TextColor = UserCenterColor.Current.TextOrangeColor;
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(5000);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (btnDeviceName.Parent != null)
                    {
                        //设备
                        btnDeviceName.TextColor = oldTextColor1;
                        //设备房间
                        btnDeviceRoom.TextColor = oldTextColor2;
                    }
                    this.sensorPushing = false;
                }, ShowErrorMode.NO);
            });
        }
        #endregion
    }
}