using System;
|
using System.Collections.Generic;
|
using System.Linq.Expressions;
|
using Shared.Common;
|
using Shared.Phone.UserCenter.Safety;
|
using ZigBee.Device;
|
using static ZigBee.Device.BindObj;
|
using static ZigBee.Device.Panel;
|
|
namespace Shared.Phone.UserCenter.DeviceBind
|
{
|
public class PanelFangyueFreshAirTargetsForm : BindCommonLayout
|
{
|
#region 构造函数
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="device"></param>
|
/// <param name="deviceBindType">1:新风;2:温度传感器;3:湿度传感器</param>
|
public PanelFangyueFreshAirTargetsForm(CommonDevice device, int deviceBindType)
|
{
|
this.curControlDev = device as FreshAir;
|
this.curDeviceBindType = deviceBindType;
|
}
|
#endregion
|
|
#region 变量申明
|
/// <summary>
|
/// 当前控制设备
|
/// </summary>
|
//CommonDevice currentControlDevice;
|
/// <summary>
|
/// 当前新风面板【控制设备】
|
/// </summary>
|
FreshAir curControlDev;
|
/// <summary>
|
/// 显示被绑定设备或场景的view
|
/// </summary>
|
VerticalFrameRefreshControl midVerticalScrolViewLayout;
|
/// <summary>
|
/// 显示房间的view
|
/// </summary>
|
HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
|
/// <summary>
|
/// 按键配置的目标列表
|
/// </summary>
|
List<CommonDevice> targetList = new List<CommonDevice>();
|
/// <summary>
|
/// 面板中已经存在的目标列表
|
/// </summary>
|
List<CommonDevice> oldTargetList = new List<CommonDevice>();
|
/// <summary>
|
/// 当前设备绑定类型
|
/// 1:新风
|
/// 2:温度传感器
|
/// 3:湿度传感器
|
/// 4:PM2.5传感器
|
/// </summary>
|
int curDeviceBindType = 0;
|
/// <summary>
|
/// 本地房间列表
|
/// </summary>
|
List<Room> supportRoomList = new List<Room>();
|
/// <summary>
|
/// 当绑定表变化后的回调
|
/// </summary>
|
public Action<List<BindListResponseObj>> action;
|
/// <summary>
|
/// 保存完成按钮
|
/// </summary>
|
Button btnFinifh;
|
/// <summary>
|
/// 楼层文本
|
/// </summary>
|
Button btnFloorText;
|
/// <summary>
|
/// 楼层列表
|
/// </summary>
|
Dictionary<string, string> dicFloorList;
|
/// <summary>
|
/// 所有房间中支持被绑定的设备列表
|
/// </summary>
|
List<CommonDevice> currentPanelSupportBindDeviceList = new List<CommonDevice>();
|
/// <summary>
|
/// 当前房间中支持被绑定的设备列表
|
/// </summary>
|
List<CommonDevice> currentRoomSupportBindDeviceList = new List<CommonDevice>();
|
/// <summary>
|
/// 面板中存在的键值
|
/// </summary>
|
List<String> panelBindListKey = null;
|
#endregion
|
|
#region UI设计
|
/// <summary>
|
/// 目标页显示
|
/// </summary>
|
public void Show()
|
{
|
#region 标题栏
|
string titleText = "";
|
switch (curDeviceBindType)
|
{
|
case 1:
|
titleText = Language.StringByID(R.MyInternationalizationString.BindFreshAirTarget);
|
break;
|
case 2:
|
titleText = Language.StringByID(R.MyInternationalizationString.TemperatureSource);
|
break;
|
case 3:
|
titleText = Language.StringByID(R.MyInternationalizationString.HumiditySource);
|
break;
|
case 4:
|
titleText = Language.StringByID(R.MyInternationalizationString.PM25Source);
|
break;
|
}
|
this.TopFrameLayout(this, titleText);
|
EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 200 - 58);
|
this.btnBack.MouseUpEventHandler += eHandlerBack;
|
this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
|
this.MidFrameLayout(this);
|
#endregion
|
|
//添加楼层UI
|
BindDownFrameLayout();
|
//标题栏下的UI
|
MidFrameLayoutContent();
|
//初始化设备数据
|
InitData();
|
}
|
|
/// <summary>
|
/// 添加楼层UI
|
/// </summary>
|
void BindDownFrameLayout()
|
{
|
var btnAddFrameLayout = new FrameLayout
|
{
|
X = Application.GetRealWidth(830),
|
};
|
this.titleFrameLayout.AddChidren(btnAddFrameLayout);
|
|
btnFloorText = new Button
|
{
|
Width = Application.GetRealWidth(110),
|
X = Application.GetRealWidth(15),
|
Text = Language.StringByID(R.MyInternationalizationString.FirstFloor),
|
TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
|
TextSize = 14,
|
IsBold = true,
|
TextAlignment = TextAlignment.CenterRight,
|
};
|
btnAddFrameLayout.AddChidren(btnFloorText);
|
|
var btnBindDown = new Button
|
{
|
Height = Application.GetMinReal(69),
|
Width = Application.GetMinReal(69),
|
X = Application.GetRealWidth(200 - 77),
|
UnSelectedImagePath = "BindPic/BindDown.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnAddFrameLayout.AddChidren(btnBindDown);
|
btnBindDown.MouseDownEventHandler += (sender, e) =>
|
{
|
SideslipFramelayout();
|
};
|
if (Common.Config.Instance.Home.FloorDics.Count == 0)
|
{
|
btnAddFrameLayout.Width = 0;
|
}
|
else
|
{
|
btnAddFrameLayout.Width = Application.GetRealWidth(200);
|
}
|
}
|
|
/// <summary>
|
/// 中部UI【标题栏下的UI】
|
/// </summary>
|
async void MidFrameLayoutContent()
|
{
|
var btnMidTopLayout = new FrameLayout
|
{
|
Height = Application.GetRealHeight(389 - 184),
|
};
|
this.midFrameLayout.AddChidren(btnMidTopLayout);
|
|
//房间栏
|
btnHorizontalScrolViewLayout = new HorizontalScrolViewLayout
|
{
|
X = Application.GetRealWidth(58),
|
};
|
btnMidTopLayout.AddChidren(btnHorizontalScrolViewLayout);
|
|
//设备栏
|
midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
|
{
|
Y = btnMidTopLayout.Bottom,
|
Height = Application.GetRealHeight(1145),
|
};
|
this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
|
|
//底部保存栏
|
var bottomFrameLayout = new FrameLayout()
|
{
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight(127),
|
Y = Application.GetRealHeight(1472),
|
};
|
this.midFrameLayout.AddChidren(bottomFrameLayout);
|
|
btnFinifh = new Button()
|
{
|
Width = Application.GetRealWidth(907),
|
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 += async (sender, e) =>
|
{
|
SaveTarget();
|
};
|
}
|
|
/// <summary>
|
/// 面板绑定目标表显示
|
/// </summary>
|
/// <param name="gateway">Gateway.</param>
|
/// <param name="key">Key.</param>
|
void RefreshRoomList(Room curRoom, ref int index2)
|
{
|
if (supportRoomList.Count == 0)
|
{
|
return;
|
}
|
btnHorizontalScrolViewLayout.RemoveAll();
|
Button curentOldRoom = null;
|
FrameLayout curentOldRoomFrameLayout = null;
|
int index = 0;
|
var roomTempList = GetSupportRoomList(curRoom);
|
for (int i = 0; i < roomTempList.Count; i++)
|
{
|
var room = roomTempList[i];
|
//房间
|
var btnRoomFrameLayout = new FrameLayout
|
{
|
Height = Application.GetMinReal(159),
|
Width = Application.GetMinReal(255),
|
Y = Application.GetRealHeight(23),
|
X = Application.GetRealWidth(5),
|
BackgroundImagePath = "Item/RoomIconBackground.png",
|
BorderWidth = 1,
|
};
|
btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayout);
|
|
var btnRoom = new Button
|
{
|
Height = Application.GetRealHeight(58),
|
Width = Application.GetRealWidth(127),
|
Y = Application.GetRealHeight(58),
|
X = Application.GetRealWidth(14),
|
Text = room.Name,
|
TextSize = 12,
|
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
|
Gravity = Gravity.Center,
|
};
|
btnRoomFrameLayout.AddChidren(btnRoom);
|
|
btnRoom.IsSelected = false;
|
if (index == 0)
|
{
|
btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
|
curentOldRoom = btnRoom;
|
curentOldRoomFrameLayout = btnRoomFrameLayout;
|
}
|
EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) =>
|
{
|
//ChangeRoom(curRoom, room, btnRoom, curentOldRoom, btnRoomFrameLayout, curentOldRoomFrameLayout);
|
if (!btnRoom.IsSelected)
|
{
|
if (curentOldRoom != null)
|
{
|
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
|
}
|
curentOldRoom = btnRoom;
|
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
|
}
|
|
if (btnRoomFrameLayout.BorderWidth == 1)
|
{
|
if (curentOldRoomFrameLayout != null)
|
{
|
curentOldRoomFrameLayout.BorderWidth = 1;
|
curentOldRoomFrameLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
|
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
|
}
|
curentOldRoomFrameLayout = btnRoomFrameLayout;
|
curentOldRoomFrameLayout.BorderWidth = 0;
|
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
}
|
curRoom = room;
|
curControlDev.RoomId = room.Id;
|
if (curRoom.ListSceneId.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
RefreshDeviceList(curRoom);
|
};
|
btnRoom.MouseUpEventHandler += eHandlerRoom;
|
btnRoomFrameLayout.MouseUpEventHandler += eHandlerRoom;
|
index++;
|
}
|
BindInfo.FinishDisplay(roomTempList, btnFinifh);
|
}
|
|
/// <summary>
|
/// 按键绑目标表显示
|
/// </summary>
|
/// <param name="curRoom"></param>
|
void RefreshDeviceList(Room curRoom)
|
{
|
midVerticalScrolViewLayout.RemoveAll();
|
Button oldDevice = null;
|
int curIndex = 0;
|
|
currentRoomSupportBindDeviceList = GetCurRoomSupportDeviceList(curRoom);
|
if (currentRoomSupportBindDeviceList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
return;
|
}
|
foreach (var device in currentRoomSupportBindDeviceList)
|
{
|
#region 绑定表UI显(无数据处理)
|
var rowLayout = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(23 + 127),
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
|
};
|
midVerticalScrolViewLayout.AddChidren(rowLayout);
|
|
var devicePic = new Button()
|
{
|
X = Application.GetMinRealAverage(58),
|
Y = Application.GetMinRealAverage(46),
|
Width = Application.GetMinRealAverage(81),
|
Height = Application.GetMinRealAverage(81),
|
UnSelectedImagePath = device.IconPath,
|
};
|
rowLayout.AddChidren(devicePic);
|
|
var btnBindName = new Button()
|
{
|
Width = Application.GetRealWidth(790),
|
X = devicePic.Right + Application.GetRealWidth(20),
|
TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 15,
|
Text = Common.LocalDevice.Current.GetDeviceEpointName(device),
|
};
|
rowLayout.AddChidren(btnBindName);
|
|
var btnChoose = new Button()
|
{
|
Width = Application.GetMinReal(60),
|
Height = Application.GetMinReal(60),
|
X = Application.GetRealWidth(861 + 81),
|
Y = Application.GetRealHeight(35),
|
SelectedImagePath = "DoorLock/SelectedIcon.png",
|
Visible = false,
|
};
|
rowLayout.AddChidren(btnChoose);
|
|
var line2 = new Button()
|
{
|
Y = rowLayout.Height - 1,
|
X = devicePic.Right + Application.GetRealWidth(20),
|
Width = Application.GetRealWidth(965 - 116),
|
Height = 1,
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
|
};
|
rowLayout.AddChidren(line2);
|
|
if (curIndex == currentPanelSupportBindDeviceList.Count - 1)
|
{
|
line2.Visible = false;
|
}
|
|
#endregion
|
|
string mianKey = device.DeviceAddr + device.DeviceEpoint;
|
if (targetList.Count != 0)
|
{
|
// if(curControlDev!=null)
|
// {
|
// foreach (var bindedSc in curControlDev.bindList)
|
// {
|
// if (bindedSc.BindMacAddr + bindedSc.BindEpoint == mianKey)
|
// {
|
// btnChoose.IsSelected = true;
|
// btnChoose.Visible = true;
|
// oldDevice = btnChoose;
|
// targetList.Add(device);
|
// }
|
// }
|
// }
|
|
//}
|
//else
|
//{
|
foreach (var bindedDev in targetList)
|
{
|
if (bindedDev.DeviceAddr + bindedDev.DeviceEpoint == mianKey)
|
{
|
btnChoose.IsSelected = true;
|
btnChoose.Visible = true;
|
oldDevice = btnChoose;
|
}
|
}
|
}
|
|
EventHandler<MouseEventArgs> hander = (sender, e) =>
|
{
|
//ChangeTarget(device, btnChoose, oldDevice);
|
if (curControlDev.bindList.Count != 0)
|
{
|
if (btnChoose.IsSelected)
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindExist), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
|
return;
|
}
|
}
|
|
if (!btnChoose.IsSelected)
|
{
|
if (oldDevice != null)
|
{
|
oldDevice.IsSelected = false;
|
oldDevice.Visible = false;
|
}
|
oldDevice = btnChoose;
|
oldDevice.IsSelected = true;
|
oldDevice.Visible = true;
|
targetList.Clear();
|
targetList.Add(device);
|
}
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
};
|
rowLayout.MouseUpEventHandler += hander;
|
devicePic.MouseUpEventHandler += hander;
|
btnBindName.MouseUpEventHandler += hander;
|
btnChoose.MouseUpEventHandler += hander;
|
curIndex++;
|
}
|
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
}
|
|
/// <summary>
|
/// 楼层选择的侧边栏
|
/// </summary>
|
void SideslipFramelayout()
|
{
|
var dialog = new Dialog
|
{
|
};
|
dialog.Show();
|
|
var flMain = new FrameLayout { BackgroundColor = 0x00000000 };
|
dialog.AddChidren(flMain);
|
flMain.MouseUpEventHandler += (sender11, e11) =>
|
{
|
dialog.Close();
|
};
|
|
var sidelipFrameLayout = new FrameLayout()
|
{
|
Height = Application.GetMinReal(783),
|
Width = Application.GetMinReal(449),
|
Y = Application.GetRealHeight(161),
|
X = Application.GetRealWidth(596),
|
BackgroundImagePath = "DoorLock/SideslipPic.png",
|
};
|
flMain.AddChidren(sidelipFrameLayout);
|
|
var btnSelectFloor = new Button()
|
{
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(58),
|
X = Application.GetRealWidth(81),
|
Y = Application.GetRealHeight(81),
|
TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
|
TextSize = 14,
|
IsBold = true,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextID = R.MyInternationalizationString.SelectFloor,
|
};
|
sidelipFrameLayout.AddChidren(btnSelectFloor);
|
|
var sidelipVerticalScrolViewLayout = new VerticalScrolViewLayout()
|
{
|
Height = Application.GetRealHeight(600),
|
Y = btnSelectFloor.Bottom,
|
};
|
sidelipFrameLayout.AddChidren(sidelipVerticalScrolViewLayout);
|
|
Button oldbutton = null;
|
Button oldbuttonText = null;
|
foreach (var floorId in dicFloorList.Keys)
|
{
|
var rowFrameLayout = new RowLayout()
|
{
|
Height = Application.GetRealHeight(150),
|
LineColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
|
X = Application.GetRealWidth(81),
|
};
|
sidelipVerticalScrolViewLayout.AddChidren(rowFrameLayout);
|
|
var btnAllMethod = new Button()
|
{
|
Width = Application.GetMinReal(81),
|
Height = Application.GetMinReal(81),
|
Y = Application.GetRealHeight(55),
|
UnSelectedImagePath = "Floor/Floor.png",
|
SelectedImagePath = "Floor/FloorSelected.png",
|
};
|
rowFrameLayout.AddChidren(btnAllMethod);
|
|
var btnMethodText = new Button()
|
{
|
Width = Application.GetRealWidth(311),
|
Height = Application.GetRealHeight(58),
|
X = Application.GetRealWidth(92),
|
Y = Application.GetRealHeight(69),
|
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
|
TextSize = 14,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = dicFloorList[floorId],
|
};
|
rowFrameLayout.AddChidren(btnMethodText);
|
|
if (curControlDev.currentSelectFloorId == floorId)
|
{
|
btnAllMethod.IsSelected = true;
|
btnAllMethod.IsBold = true;
|
btnMethodText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
|
EventHandler<MouseEventArgs> hander = (sender, e) =>
|
{
|
//ChangeFloor(dialog, floorId, btnMethodText, oldbuttonText, oldbutton);
|
var curFloorId = floorId;
|
curControlDev.currentSelectFloorId = curFloorId;
|
btnFloorText.Text = dicFloorList[curFloorId];
|
if (curControlDev.currentSelectFloorId == curFloorId)
|
{
|
return;
|
}
|
curControlDev.currentSelectFloorId = curFloorId;
|
btnFloorText.Text = dicFloorList[curFloorId];
|
|
//获取楼层中房间列表
|
supportRoomList = GetFloorRoomList();
|
if (supportRoomList.Count == 0)
|
{
|
return;
|
}
|
var curRoom = new Room();
|
if (supportRoomList.Count != 0)
|
{
|
curRoom = supportRoomList[0];
|
}
|
else
|
{
|
curRoom = new Shared.Common.Room();
|
supportRoomList.Add(curRoom);
|
}
|
|
if (!btnMethodText.IsSelected)
|
{
|
if (oldbutton != null)
|
{
|
oldbutton.IsSelected = false;
|
}
|
if (oldbuttonText != null)
|
{
|
oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
|
}
|
oldbutton = btnMethodText;
|
oldbuttonText = btnMethodText;
|
btnMethodText.IsSelected = true;
|
oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
oldbuttonText.IsBold = true;
|
}
|
|
int index = 0;
|
RefreshRoomList(curRoom, ref index);
|
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
dialog.Close();
|
};
|
btnAllMethod.MouseUpEventHandler += hander;
|
rowFrameLayout.MouseUpEventHandler += hander;
|
btnMethodText.MouseUpEventHandler += hander;
|
}
|
}
|
#endregion
|
|
#region 数据处理
|
/// <summary>
|
/// 初始化设备数据
|
/// </summary>
|
void InitData()
|
{
|
System.Threading.Tasks.Task.Run(async () =>
|
{
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Start("");
|
});
|
|
//获取楼层
|
dicFloorList = HdlRoomLogic.Current.GetFloorSortList();
|
curControlDev.currentSelectFloorId = BindInfo.GetCurrentSelectFloorId();
|
if (BindInfo.GetCurrentSelectFloorIdName() != null)
|
{
|
btnFloorText.Text = BindInfo.GetCurrentSelectFloorIdName();
|
|
}
|
|
//获取楼层中房间列表
|
supportRoomList = GetFloorRoomList();
|
if (supportRoomList.Count == 0)
|
{
|
return;
|
}
|
|
//获取所有房间中匹配的能绑的目标
|
currentPanelSupportBindDeviceList = GetAllRoomSupportDeviceList();
|
|
//获取面板中存在的绑定目标
|
var panelBindListRes = await this.curControlDev.GetDeviceBindAsync();
|
if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
|
{
|
curControlDev.bindList.Clear();
|
foreach (var bDev in panelBindListRes.getAllBindResponseData.BindList)
|
{
|
curControlDev.bindList.Add(bDev);
|
}
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
midVerticalScrolViewLayout.EndHeaderRefreshing();
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
|
});
|
}
|
targetList.Clear();
|
//选中目标列表 targetList
|
if (currentPanelSupportBindDeviceList.Count != 0 && curControlDev.bindList.Count != 0)
|
{
|
foreach (var bindDev in currentPanelSupportBindDeviceList)
|
{
|
var mainKey = bindDev.DeviceAddr + bindDev.DeviceEpoint;
|
var dev = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
|
if (dev != null)
|
{
|
var device = LocalDevice.Current.GetDevice(bindDev.DeviceAddr, bindDev.DeviceEpoint);
|
if (device != null)
|
{
|
//获取设备类型的
|
var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
//新风面板的新风设备,则不显示
|
if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
|
{
|
continue;
|
}
|
if (device.Type == DeviceType.FreshAir)
|
{
|
targetList.Add(device);
|
oldTargetList.Add(device);
|
}
|
}
|
|
}
|
}
|
}
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (supportRoomList.Count != 0)
|
{
|
Shared.Common.Room curRoom = supportRoomList[0];
|
int index = 0;
|
RefreshRoomList(curRoom, ref index);
|
RefreshDeviceList(curRoom);
|
|
if (curRoom.ListDevice.Count == 0 || targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
}
|
CommonPage.Loading.Hide();
|
});
|
}
|
});
|
}
|
|
/// <summary>
|
/// 切换楼层
|
/// </summary>
|
/// <param name="dialog"></param>
|
/// <param name="curFloorId"></param>
|
/// <param name="btnMethodText"></param>
|
/// <param name="oldbuttonText"></param>
|
/// <param name="oldbutton"></param>
|
void ChangeFloor(Dialog dialog, string curFloorId, Button btnMethodText, Button oldbuttonText, Button oldbutton)
|
{
|
if (curControlDev.currentSelectFloorId == curFloorId)
|
{
|
return;
|
}
|
curControlDev.currentSelectFloorId = curFloorId;
|
btnFloorText.Text = dicFloorList[curFloorId];
|
|
//获取楼层中房间列表
|
supportRoomList = GetFloorRoomList();
|
if (supportRoomList.Count == 0)
|
{
|
return;
|
}
|
var curRoom = new Room();
|
if (supportRoomList.Count != 0)
|
{
|
curRoom = supportRoomList[0];
|
}
|
else
|
{
|
curRoom = new Shared.Common.Room();
|
supportRoomList.Add(curRoom);
|
}
|
|
if (!btnMethodText.IsSelected)
|
{
|
if (oldbutton != null)
|
{
|
oldbutton.IsSelected = false;
|
}
|
if (oldbuttonText != null)
|
{
|
oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
|
}
|
oldbutton = btnMethodText;
|
oldbuttonText = btnMethodText;
|
btnMethodText.IsSelected = true;
|
oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
oldbuttonText.IsBold = true;
|
}
|
|
int index = 0;
|
RefreshRoomList(curRoom, ref index);
|
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
dialog.Close();
|
}
|
|
/// <summary>
|
/// 切换房间
|
/// </summary>
|
/// <param name="curRoom"></param>
|
/// <param name="room"></param>
|
/// <param name="btnRoom"></param>
|
/// <param name="curentOldRoom"></param>
|
/// <param name="btnRoomFrameLayout"></param>
|
/// <param name="curentOldRoomFrameLayout"></param>
|
void ChangeRoom(Room curRoom, Room room, Button btnRoom, Button curentOldRoom, FrameLayout btnRoomFrameLayout, FrameLayout curentOldRoomFrameLayout)
|
{
|
if (!btnRoom.IsSelected)
|
{
|
if (curentOldRoom != null)
|
{
|
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
|
}
|
curentOldRoom = btnRoom;
|
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
|
}
|
|
if (btnRoomFrameLayout.BorderWidth == 1)
|
{
|
if (curentOldRoomFrameLayout != null)
|
{
|
curentOldRoomFrameLayout.BorderWidth = 1;
|
curentOldRoomFrameLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
|
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
|
}
|
curentOldRoomFrameLayout = btnRoomFrameLayout;
|
curentOldRoomFrameLayout.BorderWidth = 0;
|
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
}
|
curRoom = room;
|
curControlDev.RoomId = room.Id;
|
if (curRoom.ListSceneId.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
RefreshDeviceList(curRoom);
|
}
|
|
/// <summary>
|
/// 切换绑定目标
|
/// </summary>
|
void ChangeTarget(CommonDevice device, Button btnChoose, Button oldDevice)
|
{
|
if (curControlDev.bindList.Count != 0)
|
{
|
if (btnChoose.IsSelected)
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindExist), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
|
return;
|
}
|
}
|
|
if (!btnChoose.IsSelected)
|
{
|
if (oldDevice != null)
|
{
|
oldDevice.IsSelected = false;
|
oldDevice.Visible = false;
|
}
|
oldDevice = btnChoose;
|
oldDevice.IsSelected = true;
|
oldDevice.Visible = true;
|
targetList.Clear();
|
targetList.Add(device);
|
}
|
if (targetList.Count == 0)
|
{
|
btnFinifh.Enable = false;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
|
}
|
else
|
{
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
}
|
}
|
|
/// <summary>
|
/// 保存目标
|
/// </summary>
|
/// <param name="curControlDev"></param>
|
void SaveTarget()
|
{
|
bool isFinish = false;
|
|
//空目标
|
if (targetList.Count == 0)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var myTip = new Tip();
|
myTip.Direction = AMPopTipDirection.None;
|
myTip.CloseTime = 2;
|
myTip.Text = Language.StringByID(R.MyInternationalizationString.BindDeviceTargetIsEmpty);
|
myTip.Show(Common.CommonPage.Instance);
|
});
|
return;
|
}
|
else
|
{
|
//已经绑定过的目标
|
if (checkExistDevice())
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var myTip = new Tip();
|
myTip.Direction = AMPopTipDirection.None;
|
myTip.CloseTime = 2;
|
myTip.Text = Language.StringByID(R.MyInternationalizationString.BindExist);
|
myTip.Show(Common.CommonPage.Instance);
|
});
|
return;
|
}
|
|
System.Threading.Tasks.Task.Run(async () =>
|
{
|
try
|
{
|
Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
|
|
//删除已经存在的目标
|
if (oldTargetList.Count != 0)
|
{
|
foreach (var bd in oldTargetList)
|
{
|
await RemoveTargets(bd);
|
}
|
}
|
|
//添加新的目标
|
var addBindeDev = new AddBindData();
|
addBindeDev.DeviceAddr = curControlDev.DeviceAddr;
|
addBindeDev.Epoint = curControlDev.DeviceEpoint;
|
foreach (var de in targetList)
|
{
|
var addBindInfo = new AddBindListObj();
|
switch (curDeviceBindType)
|
{
|
case 1:
|
addBindInfo.BindCluster = 514;
|
break;
|
case 2:
|
addBindInfo.BindCluster = 1026;
|
break;
|
case 3:
|
addBindInfo.BindCluster = 1029;
|
break;
|
}
|
addBindInfo.BindType = 0;
|
addBindInfo.BindMacAddr = de.DeviceAddr;
|
addBindInfo.BindEpoint = de.DeviceEpoint;
|
addBindeDev.BindList.Add(addBindInfo);
|
}
|
|
var dev = new AddedDeviceBindResponseAllData();
|
dev = await curControlDev.AddDeviceBindAsync(addBindeDev);
|
if (dev.addedDeviceBindResponseData == null)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
|
});
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
return;
|
}
|
else
|
{
|
if (dev.addedDeviceBindResponseData.Result == 0)
|
{
|
curControlDev.bindList = dev.addedDeviceBindResponseData.BindList;
|
targetList.Clear();
|
isFinish = true;
|
if (isFinish)
|
{
|
if (action != null)
|
{
|
action(curControlDev.bindList);
|
}
|
this.RemoveFromParent();
|
}
|
else
|
{
|
this.RemoveFromParent();
|
}
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
});
|
}
|
else if (dev.addedDeviceBindResponseData.Result == 1)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
new Tip()
|
{
|
MaxWidth = 150,
|
Text = Language.StringByID(R.MyInternationalizationString.BindFailed),
|
Direction = AMPopTipDirection.None,
|
CloseTime = 1
|
}.Show(CommonPage.Instance);
|
});
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
return;
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
new Tip()
|
{
|
MaxWidth = 150,
|
Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError),
|
Direction = AMPopTipDirection.None,
|
CloseTime = 1
|
}.Show(CommonPage.Instance);
|
});
|
btnFinifh.Enable = true;
|
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
|
return;
|
}
|
}
|
}
|
catch
|
{
|
}
|
});
|
}
|
}
|
|
/// <summary>
|
/// 删除存在的目标
|
/// </summary>
|
/// <param name="bindDevice"></param>
|
/// <param name="btnDel"></param>
|
/// <returns></returns>
|
private async System.Threading.Tasks.Task<int> RemoveTargets(CommonDevice delDev)
|
{
|
var delDevice = new DelDeviceBindData();
|
delDevice.DeviceAddr = curControlDev.DeviceAddr;
|
delDevice.Epoint = curControlDev.DeviceEpoint;
|
|
var removeDevice = new RemoveBindListObj();
|
removeDevice.BindType = 0;
|
switch (curDeviceBindType)
|
{
|
case 1:
|
removeDevice.BindCluster = 514;
|
break;
|
case 2:
|
removeDevice.BindCluster = 1026;
|
break;
|
case 3:
|
removeDevice.BindCluster = 1029;
|
break;
|
}
|
removeDevice.BindMacAddr = delDev.DeviceAddr;
|
removeDevice.BindEpoint = delDev.DeviceEpoint;
|
delDevice.RemoveBindList.Add(removeDevice);
|
|
try
|
{
|
CommonPage.Loading.Start("");
|
var delResult = new DelDeviceBindResponseAllData();
|
delResult = await curControlDev.DelDeviceBindAsync(delDevice);
|
if (delResult != null && delResult.delDeviceBindResponseData != null)
|
{
|
if (delResult.delDeviceBindResponseData?.RemoveBindList != null)
|
{
|
foreach (var re in delResult.delDeviceBindResponseData.RemoveBindList)
|
{
|
switch (re.Result)
|
{
|
case 0:
|
return 0;
|
break;
|
case 1:
|
return 1;
|
break;
|
case 2:
|
return 2;
|
break;
|
}
|
}
|
}
|
}
|
}
|
catch { }
|
|
return -1;
|
}
|
|
/// <summary>
|
/// 检测目标是否被绑定过
|
/// </summary>
|
/// <returns></returns>
|
private bool checkExistDevice()
|
{
|
bool exist = false;
|
foreach (var oldDev in oldTargetList)
|
{
|
var key = oldDev.DeviceAddr + oldDev.DeviceEpoint;
|
var result = targetList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == key));
|
if (result != null)
|
{
|
exist = true;
|
}
|
else
|
{
|
exist = false;
|
}
|
}
|
return exist;
|
}
|
|
/// <summary>
|
/// 能显示的房间列表
|
/// </summary>
|
private List<Room> GetSupportRoomList(Room curRoom)
|
{
|
var roomTempList = new List<Room>();
|
for (int i = 0; i < supportRoomList.Count; i++)
|
{
|
var room = supportRoomList[i];
|
//如果房间为喜爱[后来改名为常用房间],则不显示
|
if (room.IsLove == true)
|
{
|
continue;
|
}
|
|
//如果房间中没有设备,则不显示
|
if (room.ListDevice.Count == 0)
|
{
|
continue;
|
}
|
|
roomTempList.Add(room);
|
if (roomTempList.Count != 0)
|
{
|
curRoom = roomTempList[0];
|
}
|
}
|
return roomTempList;
|
}
|
|
/// <summary>
|
/// 获取楼层对应的房间列表
|
/// </summary>
|
/// <returns></returns>
|
private List<Room> GetFloorRoomList()
|
{
|
supportRoomList.Clear();
|
var supportRoomListTemp = new List<Room>();
|
var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
|
if (Common.Config.Instance.Home.FloorDics.Count == 0)
|
{
|
// 获取没有楼层房间
|
foreach (var room in listAllRoom)
|
{
|
if (string.IsNullOrEmpty(room.FloorId))
|
{
|
if (room.IsLove)
|
{
|
continue;
|
}
|
supportRoomListTemp.Add(room);
|
}
|
}
|
}
|
else
|
{
|
// 获取楼层对应对房间
|
foreach (var room in listAllRoom)
|
{
|
if (room.FloorId == curControlDev.currentSelectFloorId)
|
{
|
if (room.IsLove)
|
{
|
continue;
|
}
|
supportRoomListTemp.Add(room);
|
}
|
}
|
}
|
return supportRoomListTemp;
|
}
|
|
/// <summary>
|
/// 房间中匹配的支持绑定的所有目标列表
|
/// </summary>
|
/// <returns></returns>
|
List<CommonDevice> GetAllRoomSupportDeviceList()
|
{
|
currentPanelSupportBindDeviceList.Clear();
|
List<CommonDevice> currentPanelBindSupportDeviceListTemp = new List<CommonDevice>();
|
switch (curDeviceBindType)
|
{
|
case 1:
|
foreach (var r in supportRoomList)
|
{
|
if (r.ListDevice.Count == 0)
|
{
|
continue;
|
}
|
foreach (var deviceKeys in r.ListDevice)
|
{
|
var device = LocalDevice.Current.GetDevice(deviceKeys);
|
if (device != null)
|
{
|
////获取设备类型的
|
//var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
////新风面板的新风设备,则不显示
|
//if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
|
//{
|
// continue;
|
//}
|
if (device.Type == DeviceType.FreshAir)
|
{
|
currentPanelBindSupportDeviceListTemp.Add(device);
|
}
|
}
|
}
|
}
|
break;
|
case 2:
|
break;
|
case 3:
|
break;
|
case 4:
|
break;
|
}
|
return currentPanelBindSupportDeviceListTemp;
|
}
|
|
/// <summary>
|
/// 获取当前房间中匹配的支持绑定的设备列表
|
/// </summary>
|
/// <returns></returns>
|
List<CommonDevice> GetCurRoomSupportDeviceList(Room curRoom)
|
{
|
currentRoomSupportBindDeviceList.Clear();
|
List<CommonDevice> curRoomDeviceListTemp = new List<CommonDevice>();
|
switch (curDeviceBindType)
|
{
|
case 1:
|
foreach (var deviceKeys in curRoom.ListDevice)
|
{
|
var device = LocalDevice.Current.GetDevice(deviceKeys);
|
if (device != null)
|
{
|
////获取设备类型的
|
//var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
////新风面板的新风设备,则不显示
|
//if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
|
//{
|
// continue;
|
//}
|
if (device.Type == DeviceType.FreshAir)
|
{
|
curRoomDeviceListTemp.Add(device);
|
}
|
}
|
}
|
break;
|
case 2:
|
break;
|
case 3:
|
break;
|
case 4:
|
break;
|
}
|
return curRoomDeviceListTemp;
|
}
|
#endregion
|
}
|
}
|