using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
namespace Shared.Phone.Device.Category
{
public class SelectScene : FrameLayout
{
#region ◆ 变量____________________________
///
/// bodyFrameLayout
///
private FrameLayout bodyFrameLayout;
///
/// selectedTimeAction
///
public Action selectedAction;
///
/// sceneTargetDevice
///
public SceneTargetDeviceUI sceneTargetDevice;
///
/// BeforesceneTargetDeviceUIs
///
public List beforeSceneTargetDeviceUIs=new List { };
///
/// 楼层
///
private Button floorBtn;
///
/// 选择楼层
///
private Button selectFloorBtn;
///
/// 场景功能中部背景bodyView
///
public FrameLayout functionSceneBodyView;
///
/// sceneUI
///
public SceneUI sceneUI;
#endregion
///
/// SelectScene
///
public SelectScene()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
}
///
/// Show
///
public void Show()
{
if (sceneTargetDevice == null)
{
sceneTargetDevice = new SceneTargetDeviceUI { Type = 1 };
}
AddTop();
AddBodyView();
RefreshBodyView(Config.Instance.Home.CurrentFloorId);
}
#region Add____________________________________
///
/// AddTop
///
private void AddTop()
{
var top = new TopFrameLayout();
AddChidren(top);
top.InitTopview();
top.SetTopTitle(R.MyInternationalizationString.AddScence);
top.backButton.MouseUpEventHandler += (sender, e) =>
{
RemoveFromParent();
};
floorBtn = new Button()
{
X = Application.GetRealWidth(750),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(60),
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterRight,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
};
selectFloorBtn = new Button()
{
X = Application.GetRealWidth(950),
Width = Application.GetMinRealAverage(69),
Height = Application.GetMinRealAverage(69),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Drop_Down.png"
};
if (Config.Instance.Home.FloorDics.Count > 0)
{
floorBtn.Text = Config.Instance.Home.GetCurrentFloorName;
top.topView.AddChidren(floorBtn);
top.topView.AddChidren(selectFloorBtn);
floorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler;
selectFloorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler;
}
}
///
/// 选择楼层
///
/// Sender.
/// The ${ParameterType} instance containing the event data.
private void SelectedFloor_MouseUpEventHandler(object sender, MouseEventArgs mouseEventArgs)
{
var floors = new SelectFloor();
AddChidren(floors);
floors.Init(580, 184, Direction.Right);
floors.FloorAction += (floorId) =>
{
floorBtn.Text = Config.Instance.Home.GetFloorNameById(floorId);
RefreshBodyView(floorId);
};
}
///
/// AddBodyView
///
private void AddBodyView()
{
bodyFrameLayout = new FrameLayout()
{
Y = Application.GetRealHeight(184),
Height = Application.GetRealHeight(1737),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
};
AddChidren(bodyFrameLayout);
var confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
AddChidren(confirmBtn);
confirmBtn.SetTitle(R.MyInternationalizationString.Save);
confirmBtn.MouseUpEventHandler += (sender, e) =>
{
sceneTargetDevice.ElseScenesId = sceneUI.Id ;
sceneTargetDevice.SceneUI = sceneUI;
sceneTargetDevice.SceneName = sceneUI.Name;
selectedAction?.Invoke(sceneTargetDevice);
RemoveFromParent();
};
}
#endregion
///
/// RefreshBodyView
///
private void RefreshBodyView(string floorId)
{
AddRoomView(floorId);
}
///
/// AddRoomView
///
private void AddRoomView(string floorId)
{
var roomFL = new HorizontalScrolViewLayout()
{
X = Application.GetRealWidth(CommonFormResouce.X_Left),
Height = Application.GetRealHeight(204),
Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonFormResouce.X_Left),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
};
bodyFrameLayout.AddChidren(roomFL);
//功能和场景bodyView
functionSceneBodyView = new FrameLayout()
{
Y = roomFL.Bottom,
Height = Application.GetRealHeight(910+622),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
};
bodyFrameLayout.AddChidren(functionSceneBodyView);
Button curBtn = new Button();
foreach (var room in Common.Room.CurrentRoom.GetRoomsByFloorIdAppendLoveRoom(floorId))
{
var row = new FrameLayout()
{
Width = Application.GetRealWidth(187 + 50),
Height = Application.GetRealHeight(204),
};
roomFL.AddChidren(row);
var roomBtn = new Button()
{
Width = Application.GetRealWidth(187),
Height = Application.GetRealHeight(78),
Radius = (uint)Application.GetRealHeight(78 / 2),
Gravity = Gravity.Center,
Text = room.Name,
TextColor = ZigbeeColor.Current.GXCTextGrayColor,
SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
BackgroundColor = ZigbeeColor.Current.GXCButtonUnSelectedColor3,
SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonSelectedColor,
BorderColor = ZigbeeColor.Current.GXCBorderUnSelectedColor,
BorderWidth = 1
};
row.AddChidren(roomBtn);
if (room.IsLove)
{
roomBtn.IsSelected = true;
curBtn = roomBtn;
RefreshScene(room);
}
roomBtn.MouseUpEventHandler += (sender, e) =>
{
if ((sender as Button) == curBtn)
{
return;
}
(sender as Button).IsSelected = true;
curBtn.IsSelected = false;
curBtn = sender as Button;
RefreshScene(room);
};
}
}
///
/// RefreshScene
///
///
public void RefreshScene(Common.Room room)
{
functionSceneBodyView.RemoveAll();
var sceneList = room.SceneUIList;
if (sceneList.Count == 0)
{
ShowNoSceneTip();
}
else
{
var sceneScrolView = new VerticalScrolViewLayout
{
//Y = Application.GetRealHeight(58)
};
functionSceneBodyView.AddChidren(sceneScrolView);
SelectSceneRow tempSceneRow = new SelectSceneRow();
EventHandler selectScene = (sender, e) => {
tempSceneRow.IsSelected = false;
tempSceneRow = ((sender as Button).Parent as SelectSceneRow);
((sender as Button).Parent as SelectSceneRow).IsSelected = true;
tempSceneRow.IsSelected = true;
sceneUI = (sender as Button).Tag as SceneUI;
};
for (int i = 0; i < sceneList.Count; i++)
{
var scene = sceneList[i];
if (beforeSceneTargetDeviceUIs.Find((obj) => obj.SceneUI.Id == scene.Id) != null)
{
continue;
}
var sceneFL = new FrameLayout()
{
Height = Application.GetRealHeight(127 + 23),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
Tag = scene
};
sceneScrolView.AddChidren(sceneFL);
var sceneRowLayout = new SelectSceneRow(0, 23);
sceneFL.AddChidren(sceneRowLayout);
sceneRowLayout.Init();
sceneRowLayout.SetTitle(scene.Name);
sceneRowLayout.ClickButton.Tag = scene;
if(sceneUI==null)
{
if (i == 0)
{
tempSceneRow = sceneRowLayout;
sceneUI = scene;
sceneRowLayout.IsSelected = true;
}
}
else
{
if(sceneUI.Id==scene.Id)
{
tempSceneRow = sceneRowLayout;
sceneUI = scene;
sceneRowLayout.IsSelected = true;
}
}
sceneRowLayout.ClickButton.MouseUpEventHandler += selectScene;
}
}
}
///
/// 显示没有场景
///
private void ShowNoSceneTip()
{
var noFunction = new Button()
{
Y = Application.GetRealHeight(320),
Width = Application.GetMinRealAverage(757),
Height = Application.GetMinRealAverage(435),
UnSelectedImagePath = "Item/NoFunction.png",
Gravity = Gravity.CenterHorizontal
};
functionSceneBodyView.AddChidren(noFunction);
var noScenceTip = new Button()
{
Y = noFunction.Bottom + Application.GetRealHeight(32),
Height = Application.GetRealHeight(200),
Width = Application.GetRealWidth(700),
Gravity = Gravity.CenterHorizontal,
Text = Language.StringByID(R.MyInternationalizationString.NoScene).Replace("{\\r\\n}", "\r\n"),
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
TextAlignment = TextAlignment.Center,
IsMoreLines = true
};
functionSceneBodyView.AddChidren(noScenceTip);
}
}
}