using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Common;
namespace Shared.Phone.Device.Room
{
public class AddDeviceList : FrameLayout
{
public AddDeviceList()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
Tag = "categoryAddScene";
}
public override void RemoveFromParent()
{
base.RemoveFromParent();
}
///
/// Show the specified room.
///
/// Room.
public async void Show(Shared.Common.Room room)
{
#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()
{
TextAlignment = TextAlignment.Center,
Text = room.Name,
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
CommonPage.Loading.Start();
//设备类型去重分类
var dList = new List();
var devices = new List { };
devices = LocalDevice.Current.listAllDevice;
foreach (var device in devices)
{
if (dList.Contains(device.Type))
{
continue;
}
dList.Add(device.Type);
}
CommonPage.Loading.Hide();
if (devices == null || devices.Count == 0)
{
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConnectGWFail), Language.StringByID(R.MyInternationalizationString.Confrim));
alert.Show();
alert.ResultEventHandler += (sender, e) =>
{
RemoveFromParent();
};
return;
}
#region midFL
var midFL = new VerticalScrolViewLayout()
{
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
Y = topView.Bottom,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
this.AddChidren(midFL);
var r = new R.MyInternationalizationString();
foreach (var deviceType in dList)
{
var deviceItemFL = new FrameLayout()
{
Height = Application.GetRealHeight(170)
};
midFL.AddChidren(deviceItemFL);
var deviceIMG = new Button()
{
X = Application.GetRealWidth(50),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = DeviceUI.GetDeviceTypeUnSelectedImagePath(deviceType),
SelectedImagePath = DeviceUI.GetDeviceTypeSelectedImagePath(deviceType),
Gravity = Gravity.CenterVertical
};
deviceItemFL.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 = DeviceUI.GetDeviceTypeName(deviceType),
Gravity = Gravity.CenterVertical
};
deviceItemFL.AddChidren(deviceName);
var deviceRight = new Device.CommonForm.SelectedStatuButton()
{
X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
Width = Application.GetMinRealAverage(110),
Height = Application.GetMinRealAverage(110),
UnSelectedImagePath = "Item/Next.png",
SelectedImagePath = "Item/NextSelected.png",
Gravity = Gravity.CenterVertical
};
deviceItemFL.AddChidren(deviceRight);
var line = new Button()
{
Y = Application.GetRealHeight(170) - 1,
Height = 1,
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
Tag = deviceType
};
deviceItemFL.AddChidren(line);
//设备详细类列表
EventHandler deviceHandler = (sender, e) =>
{
var sameTypeList = new Room.AddDevicesSameTypeList();
UserView.HomePage.Instance.AddChidren(sameTypeList);
UserView.HomePage.Instance.PageIndex += 1;
sameTypeList.Show(deviceType, room);
};
deviceRight.MouseUpEventHandler += deviceHandler;
deviceIMG.MouseUpEventHandler += deviceHandler;
deviceName.MouseUpEventHandler += deviceHandler;
}
#endregion
}
}
}