陈嘉乐
2020-05-28 f759dc1e6f49c53733eafda82207c85af18f9931
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,24 +21,61 @@
            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>
        bool IsRead = false;
        #endregion
        //初始化按键数据
        /// <summary>
        /// 初始化按键数据
        /// </summary>
        void InitListInfo()
        {
            System.Threading.Tasks.Task.Run(async () =>
@@ -64,18 +90,13 @@
                        localDeviceList.Add(dev);
                    }
                    //获取本地场景列表
                    scList = Shared.Common.Room.AllRoomSceneUIList;
                    //获取网关场景表
                    var gwSceneObj = await currentKey.GetSceneInfoAsync();
                    if (gwSceneObj != null && gwSceneObj.getSceneInfo != null)
                    {
                        gwScenesList = gwSceneObj.getSceneInfo.ScenesList;
                    }
                    scList = HdlSceneLogic.Current.GetAllRoomSceneList();
                    //动态获取按键支持的大类
                    typeModeList = await GetTypeMode();
                    #region 读取面板当前模式
                    //读取按键当前模式
                    var tempDeata = await currentKey.ReadPanelConfigureInfoAsync();
                    var tempDeata = HdlDeviceBindLogic.Current.ReadPanelConfigureInfoAsync(currentKey);
                    if (tempDeata != null && tempDeata.deviceStatusReportData != null)
                    {
                        foreach (var attr in tempDeata.deviceStatusReportData.AttriBute)
@@ -97,12 +118,12 @@
                            {
                                currentClusterID = 258;
                            }
                            currentKey.ReSave();
                            //读取按键当前绑定目标
                            GetDeviceBindResponseAllData getBindList = null;
                            if (IsRead)
                            {
                                getBindList = await currentKey.GetDeviceBindAsync();
                                getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(currentKey);
                                var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                if (getBindList != null && getBindList.getAllBindResponseData != null)
@@ -146,6 +167,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;
                                    });
@@ -169,12 +191,14 @@
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddCurtain);
                                }
                            }
                            currentKey.ReSave();
                        }
                        #endregion 
                        Application.RunOnMainThread(() =>
                        {
                            RefreshList();
                            CommonPage.Loading.Hide();
                            midVerticalRefreshLayout.EndHeaderRefreshing();
                        });
                    }
                    else
@@ -182,6 +206,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;
@@ -208,15 +233,16 @@
            var btnAddFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(913),
                X = Application.GetRealWidth(772 - 58),
                Width = Application.GetRealWidth(192),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
            var btnBindAdd = new Button
            {
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(72),
                X = Application.GetRealWidth(62),
                Height = Application.GetMinReal(72),
                Width = Application.GetMinReal(72),
                UnSelectedImagePath = "BindPic/BindAdd.png",
            };
            btnAddFrameLayout.AddChidren(btnBindAdd);
@@ -231,7 +257,7 @@
                    {
                        currentClusterID = 6;
                        currentKey.panelMode = 1;
                        var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey, gwScenesList);
                        var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(addScenePage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        addScenePage.Show();
@@ -313,6 +339,7 @@
            InitListInfo();
        }
        /// <summary>
        /// 中部布局
        /// </summary>
@@ -320,6 +347,7 @@
        {
            midVerticalRefreshLayout = new VerticalFrameRefreshControl(29)
            {
                Height = this.midFrameLayout.Height + 1,
            };
            this.midFrameLayout.AddChidren(midVerticalRefreshLayout);
            midVerticalRefreshLayout.BeginHeaderRefreshingAction += () =>
@@ -327,7 +355,6 @@
                midVerticalRefreshLayout.BeginHeaderRefreshing();
                IsRead = true;
                InitListInfo();
                midVerticalRefreshLayout.EndHeaderRefreshing();
            };
            BlankPicUI();
@@ -410,6 +437,7 @@
                    midVerticalRefreshLayout.AddChidrenRow(rowLayout);
                    rowLayout.frameTable.UseClickStatu = false;
                    var devicePic = rowLayout.frameTable.AddLeftIcon();
                    devicePic.Y = Application.GetRealHeight(49);
                    devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png";
                    #region 绑定数据处理
@@ -429,7 +457,7 @@
                    }
                    if (isExistScene)
                    {
                        curSceneUI = Room.CurrentRoom.GetSceneUIBySceneId(bindDevice.BindScenesId);
                        curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindDevice.BindScenesId);
                        devicePic.UnSelectedImagePath = "Scene/SceneIcon.png";
                        if (curSceneUI == null)
                        {
@@ -445,9 +473,14 @@
                        else
                        {
                            btnBindNameText = curSceneUI.Name;
                            if (curSceneUI.GetZone() != null)
                            string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id);
                            if (myName != null)
                            {
                                btnFloorRoomNameText = curSceneUI.GetZone();
                                btnFloorRoomNameText = myName;
                            }
                            else
                            {
                                btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                            }
                        }
                    }
@@ -460,7 +493,7 @@
                            if (tempDev != null)
                            {
                                //获取设备所属房间
                                var tempDevRoom = Common.Room.CurrentRoom.GetRoomByDevice(tempDev);
                                var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
                                if (tempDevRoom != null)
                                {
@@ -471,21 +504,32 @@
                                    var tempDevFloorName = Common.Config.Instance.Home.GetFloorNameById(tempDevFloorId);
                                    if (string.IsNullOrEmpty(tempDevFloorName))
                                    {
                                        btnFloorRoomNameText = tempDevRoomName;
                                        if (string.IsNullOrEmpty(tempDevRoomName))
                                        {
                                            btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                                        }
                                        else
                                        {
                                            btnFloorRoomNameText = tempDevRoomName;
                                        }
                                    }
                                    else
                                    {
                                        btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName;
                                        if (string.IsNullOrEmpty(tempDevRoomName))
                                        {
                                            btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                                        }
                                        else
                                        {
                                            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);
                                }
@@ -497,7 +541,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);
@@ -529,7 +572,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)
@@ -575,7 +618,7 @@
                    break;
            }
            #endregion
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 500);
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 800);
            modeRowLayout.frameTable.AddBottomLine();
            var btnDel = modeRowLayout.AddDeleteControl();
            //一键清除按键事件
@@ -591,7 +634,7 @@
                     try
                     {
                         CommonPage.Loading.Start("");
                         var bindResult = await currentKey.ClearBindInfoAsync();
                         var bindResult = HdlDeviceBindLogic.Current.ClearBindInfoAsync(currentKey);
                         if (bindResult != null && bindResult.clearBindInfoResponseData != null)
                         {
                             if (bindResult.clearBindInfoResponseData.Result != 0)
@@ -602,11 +645,11 @@
                             }
                             else
                             {
                                 var temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                 if (temp.setWritableValueResponData?.Status != 0)
                                 var temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Default);
                                 if (temp != null && temp.setWritableValueResponData?.Status != 0)
                                 {
                                     var temp1 = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                     if (temp1.setWritableValueResponData?.Status != 0)
                                     var temp1 = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Default);
                                     if (temp1 != null && temp1.setWritableValueResponData?.Status != 0)
                                     {
                                         new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                                     }
@@ -635,7 +678,6 @@
                             currentKey.bindList.Clear();
                             RefreshList();
                             //如果是场景,用户删除清空当前到房间列表
                             currentKey.RoomId = "";
                             currentKey.ReSave();
                         }
                         CommonPage.Loading.Hide();
@@ -662,8 +704,8 @@
            var sidelipFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(628),
                Width = Application.GetRealWidth(415),
                Height = Application.GetMinReal(628),
                Width = Application.GetMinReal(415),
                Y = Application.GetRealHeight(115 + 45),
                X = Application.GetRealWidth(605),
                BackgroundImagePath = "DoorLock/SideslipPic.png",
@@ -684,26 +726,34 @@
            if (typeModeList == null)
            {
                //再次动态获取按键支持的大类
                CommonPage.Loading.Start();
                Application.RunOnMainThread(() =>
                {
                    CommonPage.Loading.Start();
                });
                typeModeList = await GetTypeMode();
                if (typeModeList == null)
                {
                    Application.RunOnMainThread(() =>
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        CommonPage.Loading.Hide();
                    });
                    CommonPage.Loading.Hide();
                    dialog.Close();
                    return;
                }
                else
                {
                    CommonPage.Loading.Hide();
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Hide();
                    });
                }
            }
            int count = 0;
            foreach (var value in typeModeList)
            {
                count++;
                #region  rowView
                var rowView = new FrameLayout()
                {
@@ -839,7 +889,7 @@
                                     var result = await RemoveTargets(bindSc, line2);
                                     if (result == 0)
                                     {
                                         var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey, gwScenesList);
                                         var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey);
                                         Shared.Phone.UserView.HomePage.Instance.AddChidren(addScenePage);
                                         Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                         addScenePage.Show();
@@ -862,7 +912,7 @@
                        }
                        else
                        {
                            var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey, gwScenesList);
                            var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey);
                            Shared.Phone.UserView.HomePage.Instance.AddChidren(addScenePage);
                            Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                            addScenePage.Show();
@@ -1060,9 +1110,19 @@
            }
        }
        //获取按键支持的大类
        /// <summary>
        /// 获取按键支持的大类
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task<List<int>> GetTypeMode()
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //则默认全部功能都给它
                typeModeList = new List<int>() { 1, 100, 200, 300, 0, 101, 102 };
                return typeModeList;
            }
            if (typeModeList != null)
            {
                typeModeList.Clear();
@@ -1118,7 +1178,7 @@
            {
                CommonPage.Loading.Start("");
                var delResult = new DelDeviceBindResponseAllData();
                delResult = await currentKey.DelDeviceBindAsync(delDevice);
                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
                if (delResult != null && delResult.delDeviceBindResponseData != null)
                {
                    if (delResult.delDeviceBindResponseData?.RemoveBindList != null)
@@ -1135,7 +1195,6 @@
                                    {
                                        currentKey.panelMode = 65535;
                                    }
                                    currentKey.RoomId = "";
                                    currentKey.ReSave();
                                    return 0;
                                    break;
@@ -1145,7 +1204,7 @@
                                    {
                                        CommonPage.Loading.Start("");
                                        var getBindList = await currentKey.GetDeviceBindAsync();
                                        var getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(currentKey);
                                        var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                        var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                        if (getBindList != null)
@@ -1238,18 +1297,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)
        {
        }
    }
}