using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using Shared.Common;
|
using Shared.Phone.UserCenter;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.Device.CommonForm
|
{
|
public class DeviceDetailInfo : FrameLayout
|
{
|
#region ◆ 变量____________________________
|
/// <summary>
|
/// bodyFrameLayout
|
/// </summary>
|
private FrameLayout bodyFrameLayout;
|
/// <summary>
|
/// 所属区域
|
/// </summary>
|
private string roomName;
|
/// <summary>
|
/// action
|
/// </summary>
|
public Action<DeviceUI,Common.Room> EditAction;
|
/// <summary>
|
/// curRoom
|
/// </summary>
|
private Common.Room curRoom;
|
/// <summary>
|
/// curRoom
|
/// </summary>
|
private Common.Room befRoom;
|
/// <summary>
|
/// sharedRow
|
/// </summary>
|
private DeviceInfoRow sharedRow;
|
/// <summary>
|
/// functionTypeRow
|
/// </summary>
|
private DeviceInfoRow functionTypeRow;
|
|
|
#endregion
|
|
#region ◆ 移除____________________________
|
/// <summary>
|
/// RemoveFromParent
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
#endregion
|
|
#region ◆ 构造方法_________________________
|
/// <summary>
|
/// DeviceDetailInfo
|
/// </summary>
|
public DeviceDetailInfo()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
}
|
|
#endregion
|
|
#region ◆ 显示界面_________________________
|
/// <summary>
|
/// Show
|
/// </summary>
|
/// <param name="device"></param>
|
/// <param name="room"></param>
|
public void Show(DeviceUI device, Common.Room room)
|
{
|
Init(device);
|
|
AddTop();
|
|
AddBodyView(device);
|
|
}
|
|
#endregion
|
|
#region Add____________________________________
|
|
/// <summary>
|
/// AddTop
|
/// </summary>
|
public void AddTop()
|
{
|
var top = new TopFrameLayout();
|
AddChidren(top);
|
top.InitTopview();
|
top.SetTopTitle(R.MyInternationalizationString.FunctionSetting);
|
top.backButton.MouseUpEventHandler += (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
|
}
|
/// <summary>
|
/// AddBodyView
|
/// </summary>
|
public void AddBodyView(DeviceUI device)
|
{
|
bodyFrameLayout = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(184),
|
Height = Application.GetRealHeight(1737),
|
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
|
};
|
AddChidren(bodyFrameLayout);
|
|
var deviceBG = new Button()
|
{
|
Y = Application.GetRealHeight(118),
|
Width = Application.GetMinRealAverage(207),
|
Height = Application.GetMinRealAverage(207),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
|
Radius = (uint)Application.GetMinRealAverage(207/2)
|
};
|
bodyFrameLayout.AddChidren(deviceBG);
|
|
var deviceBG2 = new Button()
|
{
|
Y = Application.GetRealHeight(130),
|
Width = Application.GetMinRealAverage(184),
|
Height = Application.GetMinRealAverage(184),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = ZigbeeColor.Current.GXCSelectedBackgroundColor,
|
Radius = (uint)Application.GetMinRealAverage(184/2)
|
};
|
bodyFrameLayout.AddChidren(deviceBG2);
|
|
var deviceIMG = new Button()
|
{
|
Y = Application.GetRealHeight(161),
|
Width = Application.GetMinRealAverage(124),
|
Height = Application.GetMinRealAverage(124),
|
UnSelectedImagePath = device.IconPath,
|
Gravity = Gravity.CenterHorizontal
|
};
|
bodyFrameLayout.AddChidren(deviceIMG);
|
|
var info = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device.CommonDevice);
|
|
var deviceTypeName = new Button()
|
{
|
Y = Application.GetRealHeight(360),
|
Width = Application.GetRealWidth(900),
|
Height = Application.GetRealHeight(80),
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextID = info.BeloneTextId,
|
Gravity = Gravity.CenterHorizontal,
|
TextSize = 15
|
};
|
bodyFrameLayout.AddChidren(deviceTypeName);
|
|
|
var infoFL = new FrameLayout
|
{
|
Y = Application.GetRealHeight(540),
|
Height = Application.GetRealHeight(1195),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
bodyFrameLayout.AddChidren(infoFL);
|
var rectCornerID = HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight;
|
infoFL.SetCornerWithSameRadius(Application.GetRealHeight(50), rectCornerID);
|
|
var tipBtn = new Button
|
{
|
X = Application.GetRealWidth(CommonFormResouce.X_Left),
|
Y = Application.GetRealHeight(81),
|
Width = Application.GetRealWidth(500),
|
Height = Application.GetRealHeight(60),
|
TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 15,
|
TextID = R.MyInternationalizationString.EditInfo
|
};
|
infoFL.AddChidren(tipBtn);
|
|
var nameRow = new DeviceInfoEditRow(170);
|
nameRow.Init();
|
nameRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.FunctionName)} : ");
|
nameRow.SetTitle(string.IsNullOrEmpty(device.CommonDevice.DeviceEpointName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.CommonDevice.DeviceEpointName);
|
infoFL.AddChidren(nameRow);
|
|
var zoneRow = new DeviceInfoRow(308);
|
zoneRow.Init();
|
zoneRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongZone)} : ");
|
zoneRow.SetTitle(roomName);
|
infoFL.AddChidren(zoneRow);
|
|
var modelRow = new DeviceInfoRow(446);
|
modelRow.Init();
|
modelRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongModel)} : ");
|
modelRow.SetTitle(string.IsNullOrEmpty(device.CommonDevice.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.CommonDevice.DeviceName);
|
modelRow.HideNext(true);
|
infoFL.AddChidren(modelRow);
|
|
if (device.CommonDevice.Type==ZigBee.Device.DeviceType.OnOffOutput)
|
{
|
functionTypeRow = new DeviceInfoRow(585);
|
functionTypeRow.Init();
|
functionTypeRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.FunctionType)} : ");
|
//functionTypeRow.SetTitle(device.CommonDevice.DfunctionType);
|
infoFL.AddChidren(functionTypeRow);
|
var dfunctionType = device.CommonDevice.DfunctionType;
|
|
//功能类型的翻译名字
|
string strT = string.Empty;
|
if (dfunctionType == DeviceFunctionType.A灯光)
|
{
|
strT = Language.StringByID(R.MyInternationalizationString.uLight);
|
}
|
else if (dfunctionType == DeviceFunctionType.A开关)
|
{
|
strT = Language.StringByID(R.MyInternationalizationString.uSwitch);
|
}
|
else if (dfunctionType == DeviceFunctionType.A插座)
|
{
|
strT = Language.StringByID(R.MyInternationalizationString.uSocket1);
|
}
|
functionTypeRow.SetTitle(strT);
|
|
functionTypeRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
var DfunctionType = device.CommonDevice.DfunctionType;
|
|
//功能类型的翻译名字
|
int nowSelectNo = 1;
|
string strType = string.Empty;
|
if (DfunctionType == DeviceFunctionType.A灯光)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uLight);
|
nowSelectNo = 1;
|
}
|
else if (DfunctionType == DeviceFunctionType.A开关)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
|
nowSelectNo = 0;
|
}
|
else if (DfunctionType == DeviceFunctionType.A插座)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
|
nowSelectNo = 2;
|
}
|
//显示列表
|
var listText = new List<string>();
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//开关
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//灯光
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//插座
|
//标题:选择功能类型
|
var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
|
|
var form = new BottomItemSelectForm();
|
form.AddForm(title, listText, nowSelectNo);
|
form.FinishSelectEvent += (selectNo) =>
|
{
|
functionTypeRow.NameText.Text = listText[selectNo];
|
nowSelectNo = selectNo;
|
//记录起当前选择的功能类型
|
if (selectNo == 0)
|
{
|
device.CommonDevice.DfunctionType = DeviceFunctionType.A开关;
|
}
|
else if (selectNo == 1)
|
{
|
device.CommonDevice.DfunctionType = DeviceFunctionType.A灯光;
|
}
|
else
|
{
|
device.CommonDevice.DfunctionType = DeviceFunctionType.A插座;
|
}
|
};
|
};
|
|
//sharedRow = new DeviceInfoRow(723);
|
//sharedRow.Init();
|
//sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
|
//sharedRow.SetTitle("2人");
|
//infoFL.AddChidren(sharedRow);
|
}
|
else
|
{
|
//sharedRow = new DeviceInfoRow(585);
|
//sharedRow.Init();
|
//sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
|
//sharedRow.SetTitle("2人");
|
//infoFL.AddChidren(sharedRow);
|
}
|
|
var confirmBtn = new CommonForm.CompleteButton(962, 907, 127);
|
confirmBtn.SetTitle(R.MyInternationalizationString.Confrim);
|
infoFL.AddChidren(confirmBtn);
|
|
#region event
|
EventHandler<MouseEventArgs> selectZoneEvent = (sender, e) =>
|
{
|
List<string> floorIds = new List<string> { };
|
List<string> floorNames = new List<string> { };
|
List<List<string>> roomNames = new List<List<string>> { };
|
List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
|
List<Common.Room> rs = new List<Common.Room> { };
|
List<string> rNames = new List<string> { };
|
if (Config.Instance.Home.FloorDics.Count>0)
|
{
|
foreach (var floor in Config.Instance.Home.FloorDics)
|
{
|
floorIds.Add(floor.Key);
|
floorNames.Add(floor.Value);
|
if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
|
{
|
roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
|
rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
|
}
|
}
|
PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
|
{
|
curRoom = rooms[index1][index2];
|
zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}");
|
}, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongZone),
|
Language.StringByID(R.MyInternationalizationString.Confrim),
|
Language.StringByID(R.MyInternationalizationString.Cancel));
|
}
|
else
|
{
|
for(int i=0;i<Common.Room.Lists.Count;i++)
|
{
|
var r = Common.Room.Lists[i];
|
if (r.IsLove)
|
{
|
continue;
|
}
|
rs.Add(r);
|
rNames.Add(r.Name);
|
}
|
PickerView.Show(rNames, (index1) =>
|
{
|
curRoom = rs[index1];
|
zoneRow.SetTitle(rs[index1].Name);
|
}, 0,Language.StringByID(R.MyInternationalizationString.BelongZone),
|
Language.StringByID(R.MyInternationalizationString.Confrim),
|
Language.StringByID(R.MyInternationalizationString.Cancel));
|
}
|
};
|
zoneRow.ClickBtn.MouseUpEventHandler += selectZoneEvent;
|
|
EventHandler<MouseEventArgs> selectDeviceIconEvent = (sender, e) =>
|
{
|
var localPic = new DeviceIconSelectedIMGByLocal();
|
UserView.HomePage.Instance.AddChidren(localPic);
|
UserView.HomePage.Instance.PageIndex += 1;
|
localPic.Show();
|
localPic.action = (unSelectedImagePath, selectedImagePath) =>
|
{
|
deviceIMG.UnSelectedImagePath = unSelectedImagePath;
|
deviceIMG.SelectedImagePath = selectedImagePath;
|
device.CommonDevice.IsCustomizeImage = true;
|
};
|
};
|
deviceIMG.MouseUpEventHandler += selectDeviceIconEvent;
|
|
confirmBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
try
|
{
|
CommonPage.Loading.Start();
|
if (device.CommonDevice == null)
|
{
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
|
return;
|
}
|
if (device.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
|
{
|
if (device.IsCustomizeImage == false)
|
{
|
if (device.CommonDevice.DfunctionType == DeviceFunctionType.A开关)
|
{
|
device.CommonDevice.IconPath = "Device/Switch.png";
|
}
|
else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A插座)
|
{
|
device.CommonDevice.IconPath = "Device/Socket1.png";
|
}
|
else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A灯光)
|
{
|
device.CommonDevice.IconPath = "Device/Light.png";
|
}
|
}
|
else
|
{
|
//改图片
|
device.CommonDevice.IconPath = deviceIMG.UnSelectedImagePath;
|
}
|
}
|
else
|
{
|
//改图片
|
device.CommonDevice.IconPath = deviceIMG.UnSelectedImagePath;
|
}
|
bool result;
|
new System.Threading.Thread(async () =>
|
{
|
result = await LocalDevice.Current.ReName(device.CommonDevice, nameRow.NameText.Text.Trim());
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
if (result)
|
{
|
//改房间
|
Shared.Common.Room.CurrentRoom.ChangedRoom(device.CommonDevice, curRoom.Id);
|
device.CommonDevice.ReSave();
|
EditAction?.Invoke(device, curRoom);
|
RemoveFromParent();
|
}
|
else
|
{
|
CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
|
}
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
catch
|
{
|
CommonPage.Loading.Hide();
|
}
|
};
|
|
#endregion
|
}
|
|
/// <summary>
|
/// Init
|
/// </summary>
|
/// <param name="device"></param>
|
public void Init(DeviceUI device)
|
{
|
roomName = device.GetZone();
|
befRoom = Common.Room.CurrentRoom.GetRoomByDevice(device.CommonDevice);
|
curRoom = Common.Room.CurrentRoom.GetRoomByDevice(device.CommonDevice);
|
}
|
#endregion
|
}
|
}
|