WJC
2020-04-02 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7
ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindTargetsPage.cs
@@ -11,19 +11,8 @@
    /// <summary>
    /// 按键管理
    /// </summary>
    public class BindTargetsPage : BindCommonLayout, ZigBee.Common.IStatus
    public class BindTargetsPage : BindCommonLayout
    {
        /// <summary>
        /// 按键模式接收
        /// </summary>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
            Shared.Application.RunOnMainThread(() =>
            {
            });
        }
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
@@ -32,32 +21,71 @@
            this.currentKey = key;
        }
        #region ◆ 变量申明__________________________
        ZigBee.Device.Panel currentKey;//当前按键对象
        VerticalFrameRefreshControl midVerticalRefreshLayout;//显示被绑定设备或场景的view
        int currentClusterID = 0;//按键当前簇ID
        #region 变量申明
        /// <summary>
        /// 当前按键对象
        /// </summary>
        ZigBee.Device.Panel currentKey;
        /// <summary>
        /// 显示被绑定设备或场景的view
        /// </summary>
        VerticalFrameRefreshControl midVerticalRefreshLayout;
        /// <summary>
        /// 按键当前簇ID
        /// </summary>
        int currentClusterID = 0;
        /// <summary>
        /// 空数据时的图片
        /// </summary>
        Button entryStatusPic;
        /// <summary>
        /// 空数据的提示
        /// </summary>
        Button btnPicTip;
        Action<List<BindListResponseObj>> action;//按键绑定表通知
        Action<List<BindListResponseObj>> devicBindAction;//设备被绑定通知
        private System.Collections.Generic.List<CommonDevice> localDeviceList = new System.Collections.Generic.List<CommonDevice>();//本地设备列表
        private System.Collections.Generic.List<SceneUI> scList = new System.Collections.Generic.List<SceneUI> { };//本地场景列表
        FrameLayout blankFrameLayout;//空数据显示布局
        List<int> typeModeList;//动态获取按键支持的模式大类型
        public List<ScenesListInfo> gwScenesList = new List<ScenesListInfo>();//网关中的场景列表
        /// <summary>
        /// 按键绑定表通知
        /// </summary>
        Action<List<BindListResponseObj>> action;
        /// <summary>
        /// 设备被绑定通知
        /// </summary>
        Action<List<BindListResponseObj>> devicBindAction;
        /// <summary>
        /// 本地设备列表
        /// </summary>
        private System.Collections.Generic.List<CommonDevice> localDeviceList = new System.Collections.Generic.List<CommonDevice>();
        /// <summary>
        /// 本地场景列表
        /// </summary>
        private System.Collections.Generic.List<SceneUI> scList = new System.Collections.Generic.List<SceneUI> { };
        /// <summary>
        /// 空数据显示布局
        /// </summary>
        FrameLayout blankFrameLayout;
        /// <summary>
        /// 动态获取按键支持的模式大类型
        /// </summary>
        List<int> typeModeList;
        /// <summary>
        /// 网关中的场景列表
        /// </summary>
        public List<ScenesListInfo> gwScenesList = new List<ScenesListInfo>();
        /// <summary>
        /// 是否支持读取
        /// </summary>
        bool IsRead = false;
        #endregion
        //初始化按键数据
        private void InitListInfo()
        /// <summary>
        /// 初始化按键数据
        /// </summary>
        void InitListInfo()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                    });
                    localDeviceList.Clear();
                    scList.Clear();
                    //获取本地设备列表
@@ -66,22 +94,19 @@
                        localDeviceList.Add(dev);
                    }
                    //获取本地场景列表
                    scList = Shared.Common.Room.AllRoomSceneUIList;
                    scList = HdlSceneLogic.Current.GetAllRoomSceneList();
                    //获取网关场景表
                    var gwSceneObj = await currentKey.GetSceneInfoAsync();
                    if (gwSceneObj != null && gwSceneObj.getSceneInfo != null)
                    if (gwScenesList.Count == 0)
                    {
                        gwScenesList = gwSceneObj.getSceneInfo.ScenesList;
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        var gwSceneObj = await currentKey.GetSceneInfoAsync();
                        if (gwSceneObj != null && gwSceneObj.getSceneInfo != null)
                        {
                            CommonPage.Loading.Hide();
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                            gwScenesList = gwSceneObj.getSceneInfo.ScenesList;
                        }
                    }
                    //动态获取按键支持的大类
                    typeModeList = await GetTypeMode();
                    #region 读取面板当前模式
                    //读取按键当前模式
                    var tempDeata = await currentKey.ReadPanelConfigureInfoAsync();
@@ -106,82 +131,87 @@
                            {
                                currentClusterID = 258;
                            }
                            currentKey.ReSave();
                            //读取按键当前绑定目标
                            var getBindList = await currentKey.GetDeviceBindAsync();
                            var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                            var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                            if (getBindList != null && getBindList.getAllBindResponseData != null)
                            {
                                currentKey.bindList.Clear();
                                foreach (var b in getBindList.getAllBindResponseData.BindList)
                                {
                                    if (b.BindCluster == currentClusterID)
                                    {
                                        if (b.BindCluster == 6)
                                        {
                                            if (b.BindType == 2)
                                            {
                                                bindSceneListTemp.Add(b);
                                            }
                                            else
                                            {
                                                bindDeviceListTemp.Add(b);
                                            }
                                        }
                                        else
                            //读取按键当前绑定目标
                            GetDeviceBindResponseAllData getBindList = null;
                            if (IsRead)
                            {
                                getBindList = await currentKey.GetDeviceBindAsync();
                                var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                if (getBindList != null && getBindList.getAllBindResponseData != null)
                                {
                                    currentKey.bindList.Clear();
                                    foreach (var b in getBindList.getAllBindResponseData.BindList)
                                    {
                                        if (b.BindCluster == currentClusterID)
                                        {
                                            if (currentClusterID == 8)
                                            if (b.BindCluster == 6)
                                            {
                                                if (b.BindCluster == 8)
                                                if (b.BindType == 2)
                                                {
                                                    currentKey.bindList.Add(b);
                                                    bindSceneListTemp.Add(b);
                                                }
                                                else
                                                {
                                                    bindDeviceListTemp.Add(b);
                                                }
                                            }
                                            else
                                            {
                                                currentKey.bindList.Add(b);
                                                if (currentClusterID == 8)
                                                {
                                                    if (b.BindCluster == 8)
                                                    {
                                                        currentKey.bindList.Add(b);
                                                    }
                                                }
                                                else
                                                {
                                                    currentKey.bindList.Add(b);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Application.RunOnMainThread(() =>
                                else
                                {
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                });
                                    Application.RunOnMainThread(() =>
                                    {
                                        CommonPage.Loading.Hide();
                                        midVerticalRefreshLayout.EndHeaderRefreshing();
                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                        return;
                                    });
                                }
                                if (currentKey.panelMode == 1)
                                {
                                    currentKey.bindList = bindSceneListTemp;
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddScene);
                                }
                                else if (currentKey.panelMode == 100 || currentKey.panelMode == 101 || currentKey.panelMode == 102)
                                {
                                    currentKey.bindList = bindDeviceListTemp;
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddSwitch);
                                }
                                else if (currentKey.panelMode == 200 || currentKey.panelMode == 201 || currentKey.panelMode == 203 || currentKey.panelMode == 204 || currentKey.panelMode == 205)
                                {
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddDimmer);
                                }
                                else if (currentKey.panelMode == 300 || currentKey.panelMode == 301 || currentKey.panelMode == 302 || currentKey.panelMode == 303 || currentKey.panelMode == 304)
                                {
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddCurtain);
                                }
                            }
                            if (currentKey.panelMode == 1)
                            {
                                currentKey.bindList = bindSceneListTemp;
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddScene);
                            }
                            else if (currentKey.panelMode == 100 || currentKey.panelMode == 101 || currentKey.panelMode == 102)
                            {
                                currentKey.bindList = bindDeviceListTemp;
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddSwitch);
                            }
                            else if (currentKey.panelMode == 200 || currentKey.panelMode == 201 || currentKey.panelMode == 203 || currentKey.panelMode == 204 || currentKey.panelMode == 205)
                            {
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddDimmer);
                            }
                            else if (currentKey.panelMode == 300 || currentKey.panelMode == 301 || currentKey.panelMode == 302 || currentKey.panelMode == 303 || currentKey.panelMode == 304)
                            {
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddCurtain);
                            }
                            currentKey.ReSave();
                        }
                        #endregion
                        //动态获取按键支持的大类
                        typeModeList = await GetTypeMode();
                        #endregion
                        Application.RunOnMainThread(() =>
                        {
                            RefreshList();
                            CommonPage.Loading.Hide();
                            midVerticalRefreshLayout.EndHeaderRefreshing();
                        });
                    }
                    else
@@ -189,7 +219,7 @@
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                            midVerticalRefreshLayout.EndHeaderRefreshing();
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                        return;
@@ -216,13 +246,14 @@
            var btnAddFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(913),
                X = Application.GetRealWidth(888),
                Width = Application.GetRealWidth(192),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
            var btnBindAdd = new Button
            {
                X = Application.GetRealWidth(62),
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(72),
                UnSelectedImagePath = "BindPic/BindAdd.png",
@@ -310,6 +341,14 @@
            #endregion
            CommonPage.Loading.Start("");
            middleFrameLayout();
            if (currentKey.bindList.Count == 0)
            {
                IsRead = true;
            }
            else
            {
                IsRead = false;
            }
            InitListInfo();
        }
@@ -325,8 +364,8 @@
            midVerticalRefreshLayout.BeginHeaderRefreshingAction += () =>
            {
                midVerticalRefreshLayout.BeginHeaderRefreshing();
                IsRead = true;
                InitListInfo();
                midVerticalRefreshLayout.EndHeaderRefreshing();
            };
            BlankPicUI();
@@ -409,6 +448,7 @@
                    midVerticalRefreshLayout.AddChidrenRow(rowLayout);
                    rowLayout.frameTable.UseClickStatu = false;
                    var devicePic = rowLayout.frameTable.AddLeftIcon();
                    devicePic.Y = Application.GetRealHeight(49);
                    devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png";
                    #region 绑定数据处理
@@ -428,7 +468,7 @@
                    }
                    if (isExistScene)
                    {
                        curSceneUI = Room.CurrentRoom.GetSceneUIBySceneId(bindDevice.BindScenesId);
                        curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindDevice.BindScenesId);
                        devicePic.UnSelectedImagePath = "Scene/SceneIcon.png";
                        if (curSceneUI == null)
                        {
@@ -444,9 +484,10 @@
                        else
                        {
                            btnBindNameText = curSceneUI.Name;
                            if (curSceneUI.GetZone() != null)
                            string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id);
                            if (myName != null)
                            {
                                btnFloorRoomNameText = curSceneUI.GetZone();
                                btnFloorRoomNameText = myName;
                            }
                        }
                    }
@@ -459,7 +500,7 @@
                            if (tempDev != null)
                            {
                                //获取设备所属房间
                                var tempDevRoom = Common.Room.CurrentRoom.GetRoomByDevice(tempDev);
                                var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
                                if (tempDevRoom != null)
                                {
@@ -476,15 +517,12 @@
                                    {
                                        btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName;
                                    }
                                }
                                var deviceUi = Common.LocalDevice.Current.GetDeviceUI(tempDev);
                                if (deviceUi != null)
                                {
                                    devicePic.UnSelectedImagePath = deviceUi.IconPath;
                                    devicePic.Width = Application.GetRealWidth(110);
                                    devicePic.Text = "";
                                }
                                if (tempDev.DeviceEpointName == "")
                                }
                                devicePic.UnSelectedImagePath = tempDev.IconPath;
                                devicePic.Text = "";
                                if (string.IsNullOrEmpty(tempDev.DeviceEpointName))
                                {
                                    btnBindNameText = tempDev.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit);
                                }
@@ -496,7 +534,6 @@
                            else
                            {
                                btnBindNameText = bindDevice.BindMacAddr + "_" + bindDevice.BindEpoint;
                                devicePic.Width = Application.GetMinRealAverage(200);
                                devicePic.TextAlignment = TextAlignment.CenterLeft;
                                devicePic.TextColor = UserCenterColor.Current.Gray;
                                devicePic.Text = Language.StringByID(R.MyInternationalizationString.uOffLine);
@@ -528,7 +565,7 @@
            modeRowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
            midVerticalRefreshLayout.AddChidrenRow(modeRowLayout);
            modeRowLayout.frameTable.UseClickStatu = false;
            modeRowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.keyMode), 500);
            modeRowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.keyMode), 400);
            var btnKeyModeTipText = "";
            #region 当前模式文本显示
            switch (currentKey.panelMode)
@@ -574,7 +611,7 @@
                    break;
            }
            #endregion
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 500);
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 800);
            modeRowLayout.frameTable.AddBottomLine();
            var btnDel = modeRowLayout.AddDeleteControl();
            //一键清除按键事件
@@ -639,7 +676,7 @@
                         }
                         CommonPage.Loading.Hide();
                     }
                 };
                 };
            };
        }
@@ -856,7 +893,7 @@
                                         currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                         dialog.Close();
                                     }
                                 };
                                 };
                            }
                        }
                        else
@@ -909,7 +946,7 @@
                                         currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                         dialog.Close();
                                     }
                                 };
                                 };
                            }
                        }
                        else
@@ -1059,7 +1096,10 @@
            }
        }
        //获取按键支持的大类
        /// <summary>
        /// 获取按键支持的大类
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task<List<int>> GetTypeMode()
        {
            if (typeModeList != null)
@@ -1237,18 +1277,6 @@
            localDeviceList.Clear();
            scList.Clear();
            base.RemoveFromParent();
        }
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
        public void ChangedISceneStatus(Scene scene)
        {
        }
    }
}