| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq.Expressions; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared.Common; |
| | | using Shared.Phone.UserCenter.Device.Bind; |
| | | using Shared.Phone.UserCenter.Safety; |
| | | using ZigBee.Device; |
| | | using static ZigBee.Device.BindObj; |
| | | using static ZigBee.Device.Panel; |
| | | namespace Shared.Phone.UserCenter.DeviceBind |
| | | { |
| | | /// <summary> |
| | | /// 简约多功能面板 |
| | | /// 当前界面默认选择第一个楼层,第一个类型 |
| | | /// </summary> |
| | | public class PanelSimpleMutilfunctionTargetsForm : BindCommonLayout |
| | | { |
| | | public PanelSimpleMutilfunctionTargetsForm() |
| | | #region 构造函数 |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="deviceMac">简约多功能面板Mac</param> |
| | | public PanelSimpleMutilfunctionTargetsForm(Panel controlDev) |
| | | { |
| | | this.curControlDev = controlDev; |
| | | } |
| | | #endregion |
| | | |
| | | #region 变量申明 |
| | | /// <summary> |
| | | /// 控制设备 |
| | | /// </summary> |
| | | Panel curControlDev; |
| | | /// <summary> |
| | | /// 显示被绑定设备或场景的view |
| | | /// </summary> |
| | | VerticalFrameRefreshControl midVerticalScrolViewLayout; |
| | | /// <summary> |
| | | /// 显示绑定类型 |
| | | /// </summary> |
| | | FrameLayout typeFrameLayout; |
| | | /// <summary> |
| | | /// 绑定类型提示文本 |
| | | /// </summary> |
| | | Button btnTipText; |
| | | /// <summary> |
| | | /// 保存完成按钮 |
| | | /// </summary> |
| | | Button btnFinifh; |
| | | /// <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> |
| | | public List<BindListAllInfo> curBindTypeList = new List<BindListAllInfo>(); |
| | | /// <summary> |
| | | /// 当前类型 |
| | | /// 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风 |
| | | /// </summary> |
| | | int curBindType = 0; |
| | | /// <summary> |
| | | /// 是否支持读取 |
| | | /// </summary> |
| | | bool IsRead = false; |
| | | /// <summary> |
| | | /// 是否支持再次读取【当目标读取不全情况下重新读取】 |
| | | /// </summary> |
| | | bool IsAgain = false; |
| | | /// <summary> |
| | | /// 上一次读取端点 |
| | | /// </summary> |
| | | private int oldReadEpoint = 2; |
| | | /// <summary> |
| | | /// 特殊类型的个数【开关/插座/灯光】需要计算显示的个数 |
| | | /// </summary> |
| | | int specialTypeCount = 0; |
| | | /// <summary> |
| | | /// 回调绑定目标页面刷新 |
| | | /// </summary> |
| | | public Action<List<BindListResponseObj>> action; |
| | | #endregion |
| | | |
| | | #region UI设计 |
| | | /// <summary> |
| | | /// 目标页显示 |
| | | /// </summary> |
| | | public void Show() |
| | | { |
| | | //标题栏 |
| | | TitleUI(); |
| | | //中部UI【标题栏下的UI】 |
| | | MidFrameLayouUI(); |
| | | //类型栏UI |
| | | BindTypeUI(); |
| | | |
| | | CommonPage.Loading.Start(""); |
| | | InitLocalDeviceList(); |
| | | if (curControlDev.bindTargetsFromMutilfunctionPanelList.Count == 0) |
| | | { |
| | | IsRead = true; |
| | | } |
| | | else |
| | | { |
| | | IsRead = false; |
| | | } |
| | | InitData(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 标题栏 |
| | | /// </summary> |
| | | void TitleUI() |
| | | { |
| | | string titleText = ""; |
| | | titleText = Language.StringByID(R.MyInternationalizationString.uBindTargets); |
| | | |
| | | this.TopFrameLayout(this, titleText); |
| | | EventHandler<MouseEventArgs> eHandlerBack = (sender, e) => |
| | | { |
| | | RemoveFromParent(); |
| | | }; |
| | | this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300); |
| | | this.btnBack.MouseUpEventHandler += eHandlerBack; |
| | | this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack; |
| | | this.MidFrameLayout(this); |
| | | |
| | | var btnAddFrameLayout = new FrameLayout() |
| | | { |
| | | X = Application.GetRealWidth(772 - 58), |
| | | Width = Application.GetRealWidth(192), |
| | | }; |
| | | this.titleFrameLayout.AddChidren(btnAddFrameLayout); |
| | | |
| | | var btnBindAdd = new Button |
| | | { |
| | | X = Application.GetRealWidth(62), |
| | | Height = Application.GetMinReal(72), |
| | | Width = Application.GetMinReal(72), |
| | | UnSelectedImagePath = "BindPic/BindAdd.png", |
| | | }; |
| | | btnAddFrameLayout.AddChidren(btnBindAdd); |
| | | EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) => |
| | | { |
| | | var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev, curBindType); |
| | | Shared.Phone.UserView.HomePage.Instance.AddChidren(simpleMutilfunctionBindTargetsForm); |
| | | Shared.Phone.UserView.HomePage.Instance.PageIndex += 1; |
| | | simpleMutilfunctionBindTargetsForm.Show(); |
| | | Action action = () => |
| | | { |
| | | RefreshBindListUI(); |
| | | }; |
| | | simpleMutilfunctionBindTargetsForm.actionRefreshBindList += action; |
| | | }; |
| | | btnBindAdd.MouseDownEventHandler += eHandlerAdd; |
| | | btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 中部UI【标题栏下的UI】 |
| | | /// </summary> |
| | | void MidFrameLayouUI() |
| | | { |
| | | //类型栏1 |
| | | typeFrameLayout = new FrameLayout |
| | | { |
| | | X = Application.GetRealWidth(58 / 2), |
| | | Height = Application.GetRealHeight(323), |
| | | }; |
| | | this.midFrameLayout.AddChidren(typeFrameLayout); |
| | | |
| | | //设备栏 |
| | | midVerticalScrolViewLayout = new VerticalFrameRefreshControl() |
| | | { |
| | | Y = Application.GetRealHeight(323), |
| | | Height = Application.GetRealHeight(1065), |
| | | }; |
| | | this.midFrameLayout.AddChidren(midVerticalScrolViewLayout); |
| | | midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () => |
| | | { |
| | | midVerticalScrolViewLayout.BeginHeaderRefreshing(); |
| | | IsRead = true; |
| | | InitData(); |
| | | }; |
| | | |
| | | //底部保存栏 |
| | | var bottomFrameLayout = new FrameLayout() |
| | | { |
| | | Width = LayoutParams.MatchParent, |
| | | Height = Application.GetRealHeight(84 * 2 + 127), |
| | | Y = Application.GetRealHeight(1388), |
| | | }; |
| | | this.midFrameLayout.AddChidren(bottomFrameLayout); |
| | | |
| | | btnTipText = new Button() |
| | | { |
| | | Height = Application.GetRealHeight(84), |
| | | TextID = R.MyInternationalizationString.Tip, |
| | | TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, |
| | | TextSize = 12, |
| | | Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType), |
| | | TextAlignment = TextAlignment.Center, |
| | | }; |
| | | bottomFrameLayout.AddChidren(btnTipText); |
| | | |
| | | btnFinifh = new Button() |
| | | { |
| | | Width = Application.GetRealWidth(907), |
| | | Height = Application.GetRealHeight(127), |
| | | Y = Application.GetRealHeight(49 + 35), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Radius = (uint)Application.GetRealHeight(127) / 2, |
| | | TextID = R.MyInternationalizationString.Save, |
| | | BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack, |
| | | TextColor = Shared.Common.ZigbeeColor.Current.XMWhite, |
| | | IsBold = true, |
| | | TextSize = 16, |
| | | }; |
| | | bottomFrameLayout.AddChidren(btnFinifh); |
| | | btnFinifh.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | SaveTarget(); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 类型栏UI |
| | | /// </summary> |
| | | void BindTypeUI() |
| | | { |
| | | //匹配的类型列表 |
| | | var typeList = GetTypeList(); |
| | | int index = 0; |
| | | Button curentOldType = null; |
| | | FrameLayout curentOldTypeLayout = null; |
| | | foreach (var typeText in typeList) |
| | | { |
| | | var btnTypeLayout = new FrameLayout |
| | | { |
| | | Height = Application.GetMinRealAverage(159), |
| | | Width = Application.GetMinRealAverage(255), |
| | | Y = Application.GetRealHeight(23), |
| | | BackgroundImagePath = "Item/RoomIconBackground.png", |
| | | BorderWidth = 1, |
| | | }; |
| | | typeFrameLayout.AddChidren(btnTypeLayout); |
| | | |
| | | var btnType = new Button |
| | | { |
| | | Height = Application.GetRealHeight(58), |
| | | Width = Application.GetRealWidth(127), |
| | | Y = Application.GetRealHeight(58), |
| | | X = Application.GetRealWidth(14), |
| | | Text = typeText, |
| | | TextSize = 12, |
| | | TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, |
| | | Gravity = Gravity.Center, |
| | | }; |
| | | btnTypeLayout.AddChidren(btnType); |
| | | |
| | | btnType.IsSelected = false; |
| | | |
| | | if (index == 0) |
| | | { |
| | | btnTypeLayout.Y = Application.GetRealHeight(0); |
| | | btnTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; |
| | | btnType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite; |
| | | curentOldType = btnType; |
| | | curentOldTypeLayout = btnTypeLayout; |
| | | } |
| | | else |
| | | { |
| | | btnTypeLayout.Y = Application.GetRealHeight(0); |
| | | btnTypeLayout.X = index * Application.GetRealWidth(260); |
| | | if (index > 3) |
| | | { |
| | | btnTypeLayout.Y = Application.GetRealHeight(58 + 78); |
| | | if (index == 4) |
| | | { |
| | | btnTypeLayout.X = Application.GetRealWidth(0); |
| | | } |
| | | else |
| | | { |
| | | btnTypeLayout.X = (index - 4) * Application.GetRealWidth(260); |
| | | } |
| | | } |
| | | } |
| | | |
| | | EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) => |
| | | { |
| | | if (!curentOldType.IsSelected) |
| | | { |
| | | if (curentOldType != null) |
| | | { |
| | | curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3; |
| | | } |
| | | curentOldType = btnType; |
| | | curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite; |
| | | } |
| | | |
| | | if (btnTypeLayout.BorderWidth == 1) |
| | | { |
| | | if (curentOldTypeLayout != null) |
| | | { |
| | | curentOldTypeLayout.BorderWidth = 1; |
| | | curentOldTypeLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange; |
| | | curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackground.png"; |
| | | } |
| | | curentOldTypeLayout = btnTypeLayout; |
| | | curentOldTypeLayout.BorderWidth = 0; |
| | | curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; |
| | | } |
| | | |
| | | if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.scene)) |
| | | { |
| | | curBindType = 0; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13)) |
| | | { |
| | | curBindType = 1; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14)) |
| | | { |
| | | curBindType = 2; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15)) |
| | | { |
| | | curBindType = 3; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100)) |
| | | { |
| | | curBindType = 4; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600)) |
| | | { |
| | | curBindType = 5; |
| | | RefreshBindListUI(); |
| | | } |
| | | else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310)) |
| | | { |
| | | curBindType = 6; |
| | | RefreshBindListUI(); |
| | | } |
| | | }; |
| | | btnType.MouseUpEventHandler += eHandlerRoom; |
| | | btnTypeLayout.MouseUpEventHandler += eHandlerRoom; |
| | | index++; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定表显示 |
| | | /// </summary> |
| | | void RefreshBindListUI() |
| | | { |
| | | midVerticalScrolViewLayout.RemoveAll(); |
| | | curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curControlDev, curBindType); |
| | | //注意!同个按键端点如果支持绑定多种功能类型,需要注意如下处理 |
| | | //当更换设备功能类型后 |
| | | // 绑定的开关、插座、灯光所用的按键回路互相关联,所以这里重新获取将这三种类型的其他2种,为了获取正确的开关、插座、灯光绑定的个数 |
| | | switch (curBindType) |
| | | { |
| | | case 1: |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 2); |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 3); |
| | | break; |
| | | case 2: |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 1); |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 3); |
| | | break; |
| | | case 3: |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 1); |
| | | MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 2); |
| | | break; |
| | | } |
| | | int curIndex = 0; |
| | | for (int i = 0; i < curBindTypeList.Count; i++) |
| | | { |
| | | curIndex = i; |
| | | var bindObj = curBindTypeList[i]; |
| | | SceneUI curSceneUI = null; |
| | | |
| | | var rowLayout = new RowLayoutControl(midVerticalScrolViewLayout.rowSpace / 2); |
| | | rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite; |
| | | midVerticalScrolViewLayout.AddChidren(rowLayout); |
| | | rowLayout.frameTable.UseClickStatu = false; |
| | | var devicePic = rowLayout.frameTable.AddLeftIcon(); |
| | | devicePic.Y = Application.GetRealHeight(25);//49 |
| | | devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png"; |
| | | |
| | | #region 绑定数据处理 |
| | | int currentIndex = i; |
| | | var btnBindNameText = ""; |
| | | var btnFloorRoomNameText = ""; |
| | | if (currentIndex == curBindTypeList.Count - 1) |
| | | { |
| | | rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite; |
| | | } |
| | | |
| | | if (curBindType == 0) |
| | | { |
| | | //Scene |
| | | curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindObj.BindScenesId); |
| | | devicePic.UnSelectedImagePath = "Scene/SceneIcon.png"; |
| | | if (curSceneUI == null) |
| | | { |
| | | if (string.IsNullOrEmpty(bindObj.ESName)) |
| | | { |
| | | btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + "ID" + "_" + bindObj.BindScenesId.ToString(); |
| | | } |
| | | else |
| | | { |
| | | btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + bindObj.ESName; |
| | | } |
| | | btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed); |
| | | } |
| | | else |
| | | { |
| | | btnBindNameText = curSceneUI.Name; |
| | | string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id); |
| | | if (myName != null) |
| | | { |
| | | btnFloorRoomNameText = myName; |
| | | } |
| | | else |
| | | { |
| | | btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //被绑定设备图片【可能和外面设备等图片不同,因为这里是以功能来绑定的】 |
| | | //devicePic.UnSelectedImagePath = tempDev.IconPath; |
| | | var device = LocalDevice.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint); |
| | | switch (curBindType) |
| | | { |
| | | case 1: |
| | | devicePic.UnSelectedImagePath = "BindPic/Switch.png"; |
| | | break; |
| | | case 2: |
| | | devicePic.UnSelectedImagePath = "Device/Socket1.png"; |
| | | break; |
| | | case 3: |
| | | devicePic.UnSelectedImagePath = "Device/Light.png"; |
| | | break; |
| | | case 4: |
| | | if (device != null) |
| | | { |
| | | if (device.Type == DeviceType.WindowCoveringDevice) |
| | | { |
| | | var tempCur = device as Rollershade; |
| | | if (tempCur.WcdType == 4) |
| | | { |
| | | devicePic.UnSelectedImagePath = "BindPic/Curtain.png"; |
| | | } |
| | | else |
| | | { |
| | | devicePic.UnSelectedImagePath = "BindPic/Roller.png"; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case 5: |
| | | devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png"; |
| | | break; |
| | | case 6: |
| | | devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png"; |
| | | break; |
| | | } |
| | | |
| | | if (device != null) |
| | | { |
| | | //设备名字 |
| | | btnBindNameText = Common.LocalDevice.Current.GetDeviceEpointName(device); |
| | | |
| | | //获取设备所属房间 |
| | | var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(device); |
| | | |
| | | if (tempDevRoom != null) |
| | | { |
| | | var tempDevFloorId = tempDevRoom.FloorId; |
| | | //获取房间的名字 |
| | | var tempDevRoomName = tempDevRoom.Name; |
| | | //获取楼层的名字 |
| | | var tempDevFloorName = HdlResidenceLogic.Current.GetFloorNameById(tempDevFloorId); |
| | | if (string.IsNullOrEmpty(tempDevFloorName)) |
| | | { |
| | | if (string.IsNullOrEmpty(tempDevRoomName)) |
| | | { |
| | | btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed); |
| | | } |
| | | else |
| | | { |
| | | btnFloorRoomNameText = tempDevRoomName; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(tempDevRoomName)) |
| | | { |
| | | btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed); |
| | | } |
| | | else |
| | | { |
| | | btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | devicePic.TextAlignment = TextAlignment.CenterLeft; |
| | | devicePic.TextColor = UserCenterColor.Current.Gray; |
| | | devicePic.Text = Language.StringByID(R.MyInternationalizationString.uOffLine); |
| | | } |
| | | } |
| | | |
| | | var btnBindName = rowLayout.frameTable.AddTopView(btnBindNameText, 800); |
| | | var btnFloorRoomName = rowLayout.frameTable.AddBottomView(btnFloorRoomNameText, 800); |
| | | rowLayout.frameTable.AddBottomLine(); |
| | | var btnDel = rowLayout.AddDeleteControl(); |
| | | btnDel.ButtonClickEvent += (sender, e) => |
| | | { |
| | | ClearTargets(bindObj); |
| | | }; |
| | | #endregion |
| | | } |
| | | |
| | | switch (curBindType) |
| | | { |
| | | case 1: |
| | | btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount); |
| | | break; |
| | | case 2: |
| | | btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount); |
| | | break; |
| | | case 3: |
| | | btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount + MutilfunctionPanelMethod.curLightCount); |
| | | break; |
| | | default: |
| | | btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, curBindTypeList.Count); |
| | | break; |
| | | } |
| | | midVerticalScrolViewLayout.AdjustTableHeight(Application.GetRealHeight(23)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 数据处理 |
| | | /// <summary> |
| | | /// 获取本地列表 |
| | | /// </summary> |
| | | void InitLocalDeviceList() |
| | | { |
| | | localDeviceList.Clear(); |
| | | scList.Clear(); |
| | | //设备 |
| | | foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice) |
| | | { |
| | | localDeviceList.Add(dev); |
| | | } |
| | | //场景 |
| | | scList = HdlSceneLogic.Current.GetAllRoomSceneList(); |
| | | } |
| | | /// <summary> |
| | | /// 初始化设备数据 |
| | | /// </summary> |
| | | void InitData() |
| | | { |
| | | System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | try |
| | | { |
| | | //读取按键当前绑定目标 多功能面板目标总共需要读取本页的目标60个,3秒左右(3秒+200毫秒) |
| | | GetDeviceBindResponseAllData getBindList = null; |
| | | if (IsRead) |
| | | { |
| | | curControlDev.bindTargetsFromMutilfunctionPanelList.Clear(); |
| | | var epointList = new List<int>(); |
| | | for (int i = 2; i < 62; i++) |
| | | { |
| | | epointList.Add(i); |
| | | } |
| | | //读取上次没读全读目标 |
| | | if (IsAgain) |
| | | { |
| | | epointList.Clear(); |
| | | for (int i = oldReadEpoint; i < 62; i++) |
| | | { |
| | | epointList.Add(i); |
| | | } |
| | | } |
| | | |
| | | foreach (var epoint in epointList) |
| | | { |
| | | curControlDev.DeviceEpoint = epoint; |
| | | getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev); |
| | | if (getBindList != null && getBindList.getAllBindResponseData != null) |
| | | { |
| | | var bList = new List<BindListAllInfo>(); |
| | | foreach (var dev in getBindList.getAllBindResponseData.BindList) |
| | | { |
| | | var curD = new BindListAllInfo(); |
| | | curD.KeyMacAddr = curControlDev.DeviceAddr; |
| | | curD.KeyEpoint = epoint; |
| | | curD.BindCluster = dev.BindCluster; |
| | | curD.BindScenesId = dev.BindScenesId; |
| | | curD.BindMacAddr = dev.BindMacAddr; |
| | | curD.BindEpoint = dev.BindEpoint; |
| | | curD.BindType = dev.BindType; |
| | | bList.Add(curD); |
| | | } |
| | | curControlDev.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList); |
| | | |
| | | oldReadEpoint++; |
| | | } |
| | | else |
| | | { |
| | | if (oldReadEpoint < 62) |
| | | { |
| | | IsAgain = true; |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | midVerticalScrolViewLayout.EndHeaderRefreshing(); |
| | | CommonPage.Loading.Hide(); |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5007_1" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); |
| | | }); |
| | | break; |
| | | } |
| | | } |
| | | if (oldReadEpoint >= 61) |
| | | { |
| | | IsAgain = false; |
| | | oldReadEpoint = 2; |
| | | } |
| | | |
| | | //获取所有类型的绑定目标个数 |
| | | for (int i = 0; i < 7; i++) |
| | | { |
| | | curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curControlDev, i); |
| | | } |
| | | |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | midVerticalScrolViewLayout.EndHeaderRefreshing(); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | var mess = ex.Message; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存目标 |
| | | /// </summary> |
| | | /// <param name="curControlDev"></param> |
| | | void SaveTarget() |
| | | { |
| | | RemoveFromParent(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除多功能面板的目标 |
| | | /// </summary> |
| | | /// <param name="bindDevice"></param> |
| | | /// <param name="btnDel"></param> |
| | | /// <returns></returns> |
| | | private void RemoveTargets(BindListAllInfo bindDevice) |
| | | { |
| | | var delDevice = new DelDeviceBindData(); |
| | | delDevice.DeviceAddr = bindDevice.KeyMacAddr; |
| | | delDevice.Epoint = bindDevice.KeyEpoint; |
| | | |
| | | if (bindDevice.BindType == 0 || bindDevice.BindType == 1) |
| | | { |
| | | var removeDevice = new RemoveBindListObj(); |
| | | removeDevice.BindCluster = bindDevice.BindCluster; |
| | | removeDevice.BindType = 0; |
| | | removeDevice.BindMacAddr = bindDevice.BindMacAddr; |
| | | removeDevice.BindEpoint = bindDevice.BindEpoint; |
| | | delDevice.RemoveBindList.Add(removeDevice); |
| | | |
| | | //部分目标需要二次绑定第二种功能 |
| | | switch (curBindType) |
| | | { |
| | | case 3: |
| | | var device = LocalDevice.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint); |
| | | if (device != null) |
| | | { |
| | | if (device.Type == DeviceType.DimmableLight) |
| | | { |
| | | //灯光为调光时需要移除6,8 |
| | | var removeDevice2 = new RemoveBindListObj(); |
| | | removeDevice2.BindCluster = 6; |
| | | removeDevice2.BindType = 0; |
| | | removeDevice2.BindMacAddr = bindDevice.BindMacAddr; |
| | | removeDevice2.BindEpoint = bindDevice.BindEpoint; |
| | | delDevice.RemoveBindList.Add(removeDevice2); |
| | | } |
| | | } |
| | | break; |
| | | case 5: |
| | | //要移除空调:需要移除513,514 |
| | | var removeDevice3 = new RemoveBindListObj(); |
| | | removeDevice3.BindCluster = 514; |
| | | removeDevice3.BindType = 0; |
| | | removeDevice3.BindMacAddr = bindDevice.BindMacAddr; |
| | | removeDevice3.BindEpoint = bindDevice.BindEpoint; |
| | | delDevice.RemoveBindList.Add(removeDevice3); |
| | | break; |
| | | } |
| | | } |
| | | else if (bindDevice.BindType == 2) |
| | | { |
| | | var removeDevice = new RemoveBindListObj(); |
| | | removeDevice.BindCluster = bindDevice.BindCluster; |
| | | removeDevice.BindType = 1; |
| | | removeDevice.BindScenesId = bindDevice.BindScenesId; |
| | | delDevice.RemoveBindList.Add(removeDevice); |
| | | } |
| | | |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | try |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | CommonPage.Loading.Start(""); |
| | | }); |
| | | var delResult = new DelDeviceBindResponseAllData(); |
| | | delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice); |
| | | if (delResult == null) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5003" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | if (delResult.removeBindResultResponseData == null) |
| | | { |
| | | if (delResult.delDeviceBindResponseData != null) |
| | | { |
| | | foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList) |
| | | { |
| | | if (d.Result == 0 || d.Result == 1) |
| | | { |
| | | if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) |
| | | { |
| | | curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail) + "(" + "5003_8" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5003_9" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (delResult.removeBindResultResponseData.Result == 0) |
| | | { |
| | | if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) |
| | | { |
| | | curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清除多功能面板的目标 |
| | | /// </summary> |
| | | /// <param name="bindDevice"></param> |
| | | /// <param name="btnDel"></param> |
| | | /// <returns></returns> |
| | | private void ClearTargets(BindListAllInfo bindDevice) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | try |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | CommonPage.Loading.Start(""); |
| | | }); |
| | | var currentKey = new Panel(); |
| | | currentKey.DeviceAddr = bindDevice.KeyMacAddr; |
| | | currentKey.DeviceEpoint = bindDevice.KeyEpoint; |
| | | currentKey.CurrentGateWayId = curControlDev.CurrentGateWayId; |
| | | var bindResult = HdlDeviceBindLogic.Current.ClearBindInfoAsync(currentKey); |
| | | if (bindResult != null && bindResult.clearBindInfoResponseData != null) |
| | | { |
| | | if (bindResult.clearBindInfoResponseData.Result != 0) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(CommonPage.Instance); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) |
| | | { |
| | | curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | RefreshBindListUI(); |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5006" + ")", Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance); |
| | | }); |
| | | } |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | CommonPage.Loading.Hide(); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 匹配的类型列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private List<string> GetTypeList() |
| | | { |
| | | List<string> textTypelist = new List<string> { }; |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.scene)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600)); |
| | | textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310)); |
| | | return textTypelist; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |