using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using Shared.Common;
|
using Shared.Phone.Device.CommonForm;
|
using Shared.Phone.Device.Room;
|
using static ZigBee.Device.Scene;
|
|
namespace Shared.Phone.Device.Category
|
{
|
public class CategoryAddScene : FrameLayout
|
{
|
#region ◆ 变量____________________________
|
/// <summary>
|
/// bodyFrameLayout
|
/// </summary>
|
private FrameLayout bodyFrameLayout;
|
/// <summary>
|
/// floorIds
|
/// </summary>
|
List<string> floorIds = new List<string> { };
|
/// <summary>
|
/// floorNames
|
/// </summary>
|
List<string> floorNames = new List<string> { };
|
/// <summary>
|
/// roomNames
|
/// </summary>
|
List<List<string>> roomNames = new List<List<string>> { };
|
/// <summary>
|
/// roomNames
|
/// </summary>
|
List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
|
/// <summary>
|
/// ImagePath
|
/// </summary>
|
private string ImagePath="SceneIcon/1.png";
|
/// <summary>
|
/// curRoom
|
/// </summary>
|
private Common.Room curRoom;
|
/// <summary>
|
/// sceneTargetDevicesList
|
/// </summary>
|
private List<SceneTargetDeviceUI> sceneTargetDevicesList = new List<SceneTargetDeviceUI> { };
|
|
/// <summary>
|
/// 添加目标后的展示列表
|
/// </summary>
|
public VerticalScrolViewLayout TargetListScrolView;
|
/// <summary>
|
/// 添加的执行目标的行高
|
/// </summary>
|
private readonly int TargetListScrolView_RowHeight = 170;
|
/// <summary>
|
/// The confirm button.
|
/// </summary>
|
private CommonForm.CompleteButton confirmBtn;
|
/// <summary>
|
/// 确定按钮最开始的坐标
|
/// </summary>
|
private readonly int ConfirmButton_Y = CommonPage.AppRealHeight - 300;
|
|
#endregion
|
|
/// <summary>
|
/// CategoryAddScene
|
/// </summary>
|
public CategoryAddScene()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
|
Tag = "categoryAddScene";
|
}
|
/// <summary>
|
/// RemoveFromParent
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
Category.instance?.RefreshBodyView();
|
base.RemoveFromParent();
|
}
|
/// <summary>
|
///刷新添加目标后的展示列表
|
/// </summary>
|
public void RefreshTargetListView()
|
{
|
TargetListScrolView.RemoveAll();
|
|
if (sceneTargetDevicesList.Count > 0)
|
{
|
foreach (var targetDevice in sceneTargetDevicesList)
|
{
|
string devImgPath = string.Empty;
|
string devNameText = string.Empty;
|
if (targetDevice.Type == 0)
|
{
|
if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null) continue;
|
devImgPath = targetDevice.DeviceUI.IconPath;
|
devNameText = targetDevice.DeviceUI.CommonDevice.DeviceEpointName;
|
}
|
else if (targetDevice.Type == 1)
|
{
|
devImgPath = "Item/Timer.png";
|
devNameText = $"{targetDevice.DelayTime} {Language.StringByID(R.MyInternationalizationString.Second)}";
|
}
|
else if (targetDevice.Type == 2)
|
{
|
devImgPath = "Item/Scene.png";
|
devNameText = targetDevice.SceneName;
|
}
|
var targetRowLayout = new RowLayout()
|
{
|
Height = Application.GetRealHeight(160),
|
LineColor = ZigbeeColor.Current.GXCLineColor,
|
BackgroundColor=ZigbeeColor.Current.GXCBackgroundColor
|
};
|
TargetListScrolView.AddChidren(targetRowLayout);
|
|
var targetFL = new FrameLayout()
|
{
|
|
};
|
targetRowLayout.AddChidren(targetFL);
|
|
var devIMG = new Button()
|
{
|
X = Application.GetRealWidth(CommonPage.XLeft),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = devImgPath,
|
Gravity = Gravity.CenterVertical
|
};
|
targetRowLayout.AddChidren(devIMG);
|
var devName = new Button()
|
{
|
X = devIMG.Right,
|
Width = Application.GetRealWidth(500),
|
Height = Application.GetRealHeight(100),
|
Gravity = Gravity.CenterVertical,
|
Text = devNameText,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextAlignment = TextAlignment.CenterLeft
|
};
|
targetRowLayout.AddChidren(devName);
|
var devTimer = new Button()
|
{
|
X = targetRowLayout.Width - Application.GetRealWidth(150),
|
Width = Application.GetMinRealAverage(110),
|
Height = Application.GetMinRealAverage(110),
|
UnSelectedImagePath = "Item/Timer.png",
|
Gravity = Gravity.CenterVertical
|
};
|
/////******暂时先不加延时,安卓控件有问题*******////
|
//targetRowLayout.AddChidren(devTimer);
|
var devRight = new Button()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCRedColor,
|
TextID = R.MyInternationalizationString.Delete,
|
TextColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
targetRowLayout.AddRightView(devRight);
|
//删除设备
|
devRight.MouseUpEventHandler += (sender, e) =>
|
{
|
sceneTargetDevicesList.Remove(targetDevice);
|
RefreshTargetListView();
|
};
|
|
//设备详细设置界面
|
void detailMouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
//设备
|
if (targetDevice.Type == 0)
|
{
|
if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null)
|
{
|
return;
|
}
|
if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
|
{
|
//开关灯
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectLightSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.AirSwitch)
|
{
|
//空气开关
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectAirSwitchSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
|
{
|
//卷帘
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectCurtainSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1, taskList[0].Data2);
|
}
|
else if (targetDevice.DeviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
|
{
|
//调光灯
|
var taskList = targetDevice.TaskList;
|
if (taskList.Count == 0)
|
{
|
return;
|
}
|
var detail = new CategorySceneSelectedDimmableLightSetting();
|
UserView.HomePage.Instance.AddChidren(detail);
|
UserView.HomePage.Instance.PageIndex += 1;
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
if (taskList[0].TaskType == 1)
|
{
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].Data1, taskList[0].Data2);
|
}
|
else if (taskList[0].TaskType == 3)
|
{
|
detail.Show(targetDevice.DeviceUI, targetDevice.SceneTargetDeviceUIID, taskList[0].TaskType, taskList[0].Data1);
|
|
}
|
|
|
}
|
|
}
|
//时间间隔
|
else if (targetDevice.Type == 1)
|
{
|
var delayTimeView = new SelectDelayTime();
|
UserView.HomePage.Instance.AddChidren(delayTimeView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
delayTimeView.sceneTargetDevice = targetDevice;
|
delayTimeView.Show();
|
delayTimeView.selectedTimeAction = (second) =>
|
{
|
var targetDeviceUI = sceneTargetDevicesList.Find((obj) => obj.SceneTargetDeviceUIID == second.SceneTargetDeviceUIID);
|
if (targetDeviceUI != null)
|
{
|
targetDeviceUI.DelayTime = second.DelayTime;
|
}
|
RefreshTargetListView();
|
};
|
}
|
//场景
|
else if (targetDevice.Type == 2)
|
{
|
var sceneView = new CategorySceneSelectedScene();
|
UserView.HomePage.Instance.AddChidren(sceneView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
sceneView.Show(sceneTargetDevicesList, 1, targetDevice.SceneTargetDeviceUIID);
|
}
|
}
|
devIMG.MouseUpEventHandler += detailMouseUpEventHandler;
|
devName.MouseUpEventHandler += detailMouseUpEventHandler;
|
targetRowLayout.MouseUpEventHandler += detailMouseUpEventHandler;
|
targetFL.MouseUpEventHandler += detailMouseUpEventHandler;
|
}
|
}
|
}
|
/// <summary>
|
/// Show this instance.
|
/// </summary>
|
public void Show()
|
{
|
Init();
|
|
AddTop();
|
|
AddBodyView();
|
|
}
|
|
#region Add____________________________________
|
|
/// <summary>
|
/// Init
|
/// </summary>
|
private void Init()
|
{
|
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));
|
}
|
}
|
}
|
|
/// <summary>
|
/// AddTop
|
/// </summary>
|
private void AddTop()
|
{
|
var top = new TopFrameLayout();
|
AddChidren(top);
|
top.InitTopview();
|
top.SetTopTitle(R.MyInternationalizationString.AddScence);
|
top.backButton.MouseUpEventHandler += (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
}
|
|
/// <summary>
|
/// AddBodyView
|
/// </summary>
|
private void AddBodyView()
|
{
|
bodyFrameLayout = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(184),
|
Height = Application.GetRealHeight(1737),
|
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
|
};
|
AddChidren(bodyFrameLayout);
|
|
var imgFL = new FrameLayout
|
{
|
Height = Application.GetRealHeight(556),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
bodyFrameLayout.AddChidren(imgFL);
|
|
var backGround = new Button()
|
{
|
Width = Application.GetRealWidth(930),
|
Height = Application.GetRealHeight(464),
|
Gravity = Gravity.Center,
|
Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
|
//UnSelectedImagePath = ImagePath
|
UnSelectedImagePath = "SceneIcon/3.png"
|
};
|
imgFL.AddChidren(backGround);
|
|
var infoFL = new FrameLayout
|
{
|
Y = imgFL.Bottom + Application.GetRealHeight(23),
|
Height = Application.GetRealHeight(418),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
bodyFrameLayout.AddChidren(infoFL);
|
|
var infoEdit = new Button
|
{
|
X = Application.GetRealWidth(CommonFormResouce.X_Left),
|
Height = Application.GetRealHeight(130),
|
Width = Application.GetRealWidth(700),
|
TextID = R.MyInternationalizationString.EditInfo,
|
TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 14
|
};
|
infoFL.AddChidren(infoEdit);
|
|
|
var nameRow = new DeviceInfoEditRow(130);
|
nameRow.Init();
|
nameRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.SceneName)}:");
|
nameRow.SetPlaceHoldText(R.MyInternationalizationString.PleaseInputSceneName);
|
infoFL.AddChidren(nameRow);
|
|
var zoneRow = new DeviceInfoRow(257);
|
zoneRow.Init();
|
zoneRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongZone)}:");
|
//zoneRow.SetTitle(curRoom.Name);
|
infoFL.AddChidren(zoneRow);
|
zoneRow.HideLine(false);
|
|
var targetFL = new FrameLayout()
|
{
|
Y = infoFL.Bottom + Application.GetRealHeight(23),
|
Height = Application.GetRealHeight(730)
|
};
|
bodyFrameLayout.AddChidren(targetFL);
|
|
var targetBG = new FrameLayout
|
{
|
Height = Application.GetRealHeight(334),
|
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
targetFL.AddChidren(targetBG);
|
|
var addTargetFL = new FrameLayout
|
{
|
Y=Application.GetRealHeight(46),
|
Height = Application.GetRealHeight(127),
|
};
|
targetFL.AddChidren(addTargetFL);
|
|
var target = new Button()
|
{
|
X = Application.GetRealWidth(CommonFormResouce.X_Left),
|
Height = Application.GetRealHeight(127) - 1,
|
Width = Application.GetRealWidth(600),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
|
TextID = R.MyInternationalizationString.AddScentTargetAction,
|
Gravity = Gravity.CenterVertical
|
};
|
addTargetFL.AddChidren(target);
|
|
var targetAdd = new Button
|
{
|
X = Application.GetRealWidth(950),
|
Y = Application.GetRealHeight(46),
|
Width = Application.GetMinRealAverage(72),
|
Height = Application.GetMinRealAverage(72),
|
Gravity=Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Add.png",
|
};
|
addTargetFL.AddChidren(targetAdd);
|
var targetLine = new Button()
|
{
|
Y = target.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCGrayLineColor2
|
};
|
addTargetFL.AddChidren(targetLine);
|
|
//添加目标后的展示列表
|
TargetListScrolView = new VerticalScrolViewLayout()
|
{
|
Y = targetLine.Bottom,
|
Height = Application.GetRealHeight(730-127),
|
//BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
|
};
|
targetFL.AddChidren(TargetListScrolView);
|
|
confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
|
AddChidren(confirmBtn);
|
|
RefreshTargetListView();
|
|
#region event
|
|
//选择背景图
|
EventHandler<MouseEventArgs> backGroundIMGHander = (sender, e) =>
|
{
|
if (curRoom == null)
|
{
|
RoomCommon.ShowTipNoRoom();
|
return;
|
}
|
if (curRoom.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
|
var localPic = new CategorySceneSelectImgByLocal();
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
localPic.Show();
|
localPic.action = () =>
|
{
|
backGround.UnSelectedImagePath = ImagePath;
|
};
|
|
};
|
backGround.MouseUpEventHandler += backGroundIMGHander;
|
|
|
//区域
|
EventHandler<MouseEventArgs> zoneHander = (sender, e) =>
|
{
|
PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
|
{
|
curRoom = rooms[index1][index2];
|
zoneRow.NameText.Text = $"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}";
|
}, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongFloor), Language.StringByID(R.MyInternationalizationString.Confrim), Language.StringByID(R.MyInternationalizationString.Cancel));
|
};
|
zoneRow.NextBtn.MouseUpEventHandler += zoneHander;
|
zoneRow.TipBtn.MouseUpEventHandler += zoneHander;
|
zoneRow.NameText.MouseUpEventHandler += zoneHander;
|
zoneRow.MouseUpEventHandler += zoneHander;
|
|
//执行目标-添加执行设备
|
EventHandler<MouseEventArgs> targetAddHander = (sender, e) =>
|
{
|
|
if (curRoom == null)
|
{
|
RoomCommon.ShowTipNoRoom();
|
return;
|
}
|
if (curRoom.IsSharedRoom)
|
{
|
RoomCommon.ShowTipRoomIsShared();
|
return;
|
}
|
|
int selectRow_Height = 150;
|
int selectRow_Width = 1034;
|
var selectFL = new FrameLayout()
|
{
|
BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
|
};
|
AddChidren(selectFL);
|
|
var itemFL = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(1276),
|
Height = Application.GetRealHeight(450),
|
Width = Application.GetRealWidth(selectRow_Width),
|
Gravity=Gravity.CenterHorizontal,
|
Radius = (uint)Application.GetRealHeight(17),
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
|
};
|
selectFL.AddChidren(itemFL);
|
|
var selectedFunctionBtn = new Button()
|
{
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.Function,
|
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
|
};
|
itemFL.AddChidren(selectedFunctionBtn);
|
var selectedFunctionLine = new Button()
|
{
|
Y = selectedFunctionBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor
|
};
|
itemFL.AddChidren(selectedFunctionLine);
|
|
var selectedSceneBtn = new Button()
|
{
|
Y = selectedFunctionLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.Scence,
|
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
|
};
|
itemFL.AddChidren(selectedSceneBtn);
|
var selectedSceneLine = new Button()
|
{
|
Y = selectedSceneBtn.Bottom,
|
Height = 1,
|
BackgroundColor = ZigbeeColor.Current.GXCLineColor,
|
};
|
itemFL.AddChidren(selectedSceneLine);
|
|
var selectedTimerBtn = new Button()
|
{
|
Y = selectedSceneLine.Bottom,
|
Height = Application.GetRealHeight(selectRow_Height) - 1,
|
TextID = R.MyInternationalizationString.Delay,
|
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
|
};
|
itemFL.AddChidren(selectedTimerBtn);
|
|
|
var cancelBtn = new Button()
|
{
|
Y = Application.GetRealHeight(1742),
|
Height = Application.GetRealHeight(selectRow_Height),
|
Width = Application.GetRealWidth(selectRow_Width),
|
Gravity=Gravity.CenterHorizontal,
|
TextID = R.MyInternationalizationString.Cancel,
|
TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
|
BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
Radius = (uint)Application.GetRealHeight(17)
|
};
|
selectFL.AddChidren(cancelBtn);
|
|
//添加功能
|
selectedFunctionBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var deviceTypeList = new CategorySceneSelectDevice();
|
UserView.HomePage.Instance.AddChidren(deviceTypeList);
|
UserView.HomePage.Instance.PageIndex += 1;
|
deviceTypeList.Show(sceneTargetDevicesList);
|
};
|
//添加场景
|
selectedSceneBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var sceneView = new CategorySceneSelectedScene();
|
UserView.HomePage.Instance.AddChidren(sceneView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
//if (Modify)
|
//{
|
// sceneView.Show(sceneTargetDevicesList, -1, "", false, ModifySceneUI.Id);
|
//}
|
//else
|
//{
|
// sceneView.Show(sceneTargetDevicesList);
|
//}
|
};
|
//添加时间间隔
|
selectedTimerBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
var delayTimeView = new SelectDelayTime();
|
UserView.HomePage.Instance.AddChidren(delayTimeView);
|
UserView.HomePage.Instance.PageIndex += 1;
|
delayTimeView.Show();
|
delayTimeView.selectedTimeAction = (second) =>
|
{
|
sceneTargetDevicesList.Add(second);
|
RefreshTargetListView();
|
};
|
};
|
|
cancelBtn.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
selectFL.MouseUpEventHandler += (send, ee) =>
|
{
|
selectFL.RemoveFromParent();
|
};
|
};
|
targetAdd.MouseUpEventHandler += targetAddHander;
|
targetFL.MouseUpEventHandler += targetAddHander;
|
target.MouseUpEventHandler += targetAddHander;
|
addTargetFL.MouseUpEventHandler += targetAddHander;
|
//确定添加目标
|
confirmBtn.MouseUpEventHandler += async (sender, e) =>
|
{
|
if (curRoom == null)
|
{
|
RoomCommon.ShowTipNoRoom();
|
return;
|
}
|
if (curRoom.IsSharedRoom)
|
{
|
RemoveFromParent();
|
return;
|
}
|
|
//新增
|
if (string.IsNullOrEmpty(nameRow.NameText.Text))
|
{
|
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull), Language.StringByID(R.MyInternationalizationString.Close));
|
alert.Show();
|
alert.ResultEventHandler += (sendAlert, eAlert) =>
|
{
|
return;
|
};
|
}
|
else
|
{
|
try
|
{
|
if (Shared.Common.Room.AllRoomSceneUIList.Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
|
{
|
Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
return;
|
}
|
CommonPage.Loading.Start();
|
var memberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData>();
|
//累加延时
|
int AddedDelayTime = 0;
|
for (int i = 0; i < sceneTargetDevicesList.Count; i++)
|
{
|
var sceneTarget = sceneTargetDevicesList[i];
|
SceneTargetDeviceUI beforeSceneTarget = null;
|
if (i - 1 >= 0)
|
{
|
beforeSceneTarget = sceneTargetDevicesList[i - 1];
|
}
|
if (sceneTarget.Type == 0)
|
{
|
if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
|
{
|
continue;
|
}
|
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if (i - 1 >= 0)
|
{
|
for (int k = i - 1; k >= 0; k--)
|
{
|
if (sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
|
Type = 0,
|
ScenesId = 0,
|
Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
|
TaskList = sceneTarget.TaskList,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
else if (sceneTarget.Type == 2)
|
{
|
if (beforeSceneTarget != null && beforeSceneTarget.Type == 1)
|
{
|
if (i - 1 >= 0)
|
{
|
for (int k = i - 1; k >= 0; k--)
|
{
|
if (sceneTargetDevicesList[k] == null || sceneTargetDevicesList[k].Type != 1)
|
{
|
break;
|
}
|
AddedDelayTime += sceneTargetDevicesList[k].DelayTime;
|
}
|
}
|
}
|
var memberData = new ZigBee.Device.Scene.AddSceneMemberData
|
{
|
Type = 1,
|
ScenesId = 0,
|
ElseScenesId = sceneTarget.ElseScenesId,
|
DelayTime = AddedDelayTime
|
};
|
memberDataList.Add(memberData);
|
}
|
}
|
|
var result = await curRoom.AddScene(nameRow.NameText.Text, backGround.UnSelectedImagePath, memberDataList);
|
if (result == 1)
|
{
|
RemoveFromParent();
|
}
|
else if (result == 0)
|
{
|
//失败
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.AddSceneFail);
|
}
|
else if (result == -1)
|
{
|
//已存在
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"分类添加场景出错{ex.Message}");
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
|
}
|
};
|
#endregion
|
}
|
|
#endregion
|
|
|
}
|
}
|