using System;
|
using System.Collections.Generic;
|
using Shared.Common;
|
namespace Shared.Phone.Device.Category
|
{
|
public class CategorySceneSelectDeviceByRoom:FrameLayout
|
{
|
public CategorySceneSelectDeviceByRoom()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor;
|
Tag = "categoryAddScene";
|
}
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
public void Show(List<SceneTargetDeviceUI> sceneTargetDevicesList, ZigBee.Device.DeviceType deviceType, bool isFromRoom = false)
|
{
|
#region topview
|
var topBGView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(CommonPage.Navigation_Height),
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
|
};
|
AddChidren(topBGView);
|
var topView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
|
Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
|
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
|
};
|
AddChidren(topView);
|
|
var title = new Button()
|
{
|
Text = $"{Language.StringByID(R.MyInternationalizationString.Add)}{DeviceUI.GetDeviceTypeName(deviceType)}",
|
TextSize = 20,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
|
Gravity = Gravity.CenterHorizontal
|
};
|
topView.AddChidren(title);
|
var back = new Device.CommonForm.BackButton() { };
|
topView.AddChidren(back);
|
back.MouseUpEventHandler += (sender, e) =>
|
{
|
this.RemoveFromParent();
|
};
|
#endregion
|
|
#region midFL
|
var roomBodyView = new VerticalScrolViewLayout()
|
{
|
Y = topView.Bottom,
|
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
AddChidren(roomBodyView);
|
foreach (var room in Shared.Common.Room.Lists)
|
{
|
if (room.DeviceUIList.Find((obj) => obj.CommonDevice.Type == deviceType) == null)
|
{
|
continue;
|
}
|
var roomRowView = new RowLayout()
|
{
|
Height = Application.GetRealHeight(170),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
LineColor = ZigbeeColor.Current.GXCLineColor
|
};
|
roomBodyView.AddChidren(roomRowView);
|
var roomFL = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(170),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
};
|
roomRowView.AddChidren(roomFL);
|
var roomNameBtn = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Width = Application.GetRealWidth(500),
|
Text = room.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
Gravity = Gravity.CenterVertical
|
};
|
roomFL.AddChidren(roomNameBtn);
|
var nextBtn = new Button()
|
{
|
X = roomRowView.Width - Application.GetRealWidth(150),
|
Height = Application.GetMinRealAverage(110),
|
Width = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = "Item/Next.png",
|
SelectedImagePath = "Item/DownSelected.png",
|
Gravity = Gravity.CenterVertical
|
};
|
roomFL.AddChidren(nextBtn);
|
|
//展开,如果房间有对应的设备就展示,否则返回
|
//还要判断是支持场景功能 输入镞为5********后期开会决定不需要判断
|
EventHandler<MouseEventArgs> nextHandler = (sender, e) =>
|
{
|
List<DeviceUI> sameTypeList = new List<DeviceUI>();
|
foreach (var device in room.DeviceUIList)
|
{
|
if (device.CommonDevice == null)
|
{
|
continue;
|
}
|
if (device.CommonDevice.Type == deviceType)
|
{
|
if (sceneTargetDevicesList.Find((obj) => obj.Type == 0 && obj.DeviceUI.CommonDevice.DeviceAddr == device.CommonDevice.DeviceAddr && obj.DeviceUI.CommonDevice.DeviceEpoint == device.CommonDevice.DeviceEpoint) != null)
|
{
|
continue;
|
}
|
sameTypeList.Add(device);
|
}
|
}
|
if (sameTypeList.Count == 0)
|
{
|
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TheRoomNoDeviceAddToScene), Language.StringByID(R.MyInternationalizationString.Close));
|
alert.Show();
|
return;
|
}
|
nextBtn.IsSelected = !nextBtn.IsSelected;
|
if (nextBtn.IsSelected)
|
{
|
roomRowView.Height = Application.GetRealHeight(170 * (sameTypeList.Count+1));
|
for (int i = 0; i < sameTypeList.Count;i++)
|
{
|
var device = sameTypeList[i];
|
var deviceRowView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(170 * (i + 1)),
|
Height = Application.GetRealHeight(170),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
Tag="deviceRowViewDetail"
|
};
|
roomRowView.AddChidren(deviceRowView);
|
var deviceLine = new Button()
|
{
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
deviceRowView.AddChidren(deviceLine);
|
var deviceIMG = new Button()
|
{
|
X = Application.GetRealWidth(50),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = device.IconPath,
|
SelectedImagePath = device.IconPath,
|
Gravity = Gravity.CenterVertical
|
};
|
deviceRowView.AddChidren(deviceIMG);
|
var deviceName = new Button()
|
{
|
X = deviceIMG.Right + Application.GetRealWidth(50),
|
Width = Application.GetRealWidth(700),
|
Height = Application.GetRealHeight(110),
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 16,
|
Text = device.CommonDevice.DeviceEpointName,
|
Gravity = Gravity.CenterVertical
|
};
|
deviceRowView.AddChidren(deviceName);
|
var deviceRight = new Button()
|
{
|
X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = "Item/Next.png",
|
Gravity = Gravity.CenterVertical
|
};
|
deviceRowView.AddChidren(deviceRight);
|
|
EventHandler<MouseEventArgs> showDeviceDetailHandler = (send1, e1) =>
|
{
|
if (device.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
|
{
|
//开关灯
|
var detail = new CategorySceneSelectLightSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(device, "", -1, isFromRoom);
|
}
|
else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.AirSwitch)
|
{
|
//空气开关
|
var detail = new CategorySceneSelectAirSwitchSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(device, "", -1, isFromRoom);
|
}
|
else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
|
{
|
//卷帘
|
var detail = new CategorySceneSelectCurtainSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
detail.Show(device, "", -1, -1, isFromRoom);
|
}
|
else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
|
{
|
//调光灯
|
var dimmableLightSetting = new CategorySceneSelectedDimmableLightSetting();
|
UserView.HomePage.Instance.AddChidren(dimmableLightSetting);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
dimmableLightSetting.Show(device, "", -1, -1, isFromRoom);
|
}
|
else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
|
{
|
//调光灯
|
var dimmableLightSetting = new CategorySceneSelectedDimmableLightSetting();
|
UserView.HomePage.Instance.AddChidren(dimmableLightSetting);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
dimmableLightSetting.Show(device, "", -1, -1, isFromRoom);
|
}
|
};
|
deviceRowView.MouseUpEventHandler += showDeviceDetailHandler;
|
deviceIMG.MouseUpEventHandler += showDeviceDetailHandler;
|
deviceName.MouseUpEventHandler += showDeviceDetailHandler;
|
deviceRight.MouseUpEventHandler += showDeviceDetailHandler;
|
}
|
}
|
else
|
{
|
roomRowView.Height = Application.GetRealHeight(170);
|
roomRowView.RemoveViewByTag("deviceRowViewDetail");
|
}
|
};
|
nextBtn.MouseUpEventHandler += nextHandler;
|
roomRowView.MouseUpEventHandler += nextHandler;
|
roomNameBtn.MouseUpEventHandler += nextHandler;
|
roomFL.MouseUpEventHandler += nextHandler;
|
}
|
#endregion
|
}
|
}
|
}
|