using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
namespace HDL_ON.UI
{
///
/// 房间列表
///
public class SmartSpeakerRoomListPage : FrameLayout
{
///
/// bodyView
///
FrameLayout bodyView;
///
/// 当前主滑动View
///
VerticalScrolViewLayout bodyScrolView;
///
/// 音箱参数
///
SpeakerInfo speakerInfo;
///
/// 房间列表和无区域功能页面
///
/// 音箱参数
public SmartSpeakerRoomListPage(SpeakerInfo speakerInfo)
{
bodyView = this;
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
this.speakerInfo = speakerInfo;
}
///
/// 加载视图
///
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.DataManagement)).LoadTopView();
int bodyY = Application.GetRealHeight(64);
bodyScrolView = new VerticalScrolViewLayout()
{
Y = bodyY,
Height = bodyView.Height - bodyY,
BackgroundColor = CSS_Color.BackgroundColor,
};
bodyView.AddChidren(bodyScrolView);
//加载房间列表
ShowRoomListView();
}
///
/// 加载房间列表
///
void ShowRoomListView()
{
bodyScrolView.RemoveAll();
var titleView = new FrameLayout()
{
BackgroundColor = CSS_Color.MainBackgroundColor,
Height = Application.GetRealWidth(53),
};
bodyScrolView.AddChidren(titleView);
//箭头图标
var btnResidenceDownIcon = new Button()
{
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
X = Application.GetRealWidth(12),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Public/DownIcon.png",
};
titleView.AddChidren(btnResidenceDownIcon);
//住宅标题
var btnHomeTitle = new Button()
{
X = btnResidenceDownIcon.Right + Application.GetRealWidth(1),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = DB_ResidenceData.Instance.CurrentRegion.homeName,
};
titleView.AddChidren(btnHomeTitle);
//var btnLine = new Button()
//{
// X = Application.GetRealWidth(16),
// Y = titleView.Height - Application.GetRealHeight(2),
// Width = Application.GetRealWidth(360),
// Height = Application.GetRealHeight(1),
// BackgroundColor = CSS_Color.DividingLineColor,
//};
//titleView.AddChidren(btnLine);
//---------------------------------------------
//未分配区域的功能
List allFunctionList = FunctionList.List.GetDeviceFunctionList();
//未分配区域的功能
List unallocatedList = new List();
//
foreach (var function in allFunctionList)
{
function.roomIds.Remove(null);
if (function.roomIds.Count == 0)
{
unallocatedList.Add(function);
}
}
//所有场景
List allSceneList = FunctionList.List.scenes;
//全局场景场景
List globalSceneList = new List();
//找出所有的全局场景
foreach (var mScene in allSceneList)
{
//roomIds大于0 代表分配到房间
mScene.roomIds.Remove(null);
if (mScene.roomIds.Count == 0)
{
globalSceneList.Add(mScene);
}
}
try
{
//房间列表
foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
{
AddRoomFunctionRowLayout(room);
}
//2020-12-16 加载未分配区域功能RowLayout
AddNoAreaFunctionRowLayout(unallocatedList, globalSceneList);
}
catch
{
Utlis.WriteLine("AddRoomFunctionRowLayout error");
}
}
///
/// 添加房间列表
///
///
void AddRoomFunctionRowLayout(Room mRoom)
{
ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null, null);
}
///
/// 添加无区域的功能
///
/// 未分配的所有功能列表
/// 全区域的场景
void AddNoAreaFunctionRowLayout(List unallocatedList, List globalSceneList)
{
ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList, globalSceneList);
}
///
/// 2020-12-17 重新调整
/// 添加房间分享或者无区域分配 个数统计状态的RowLayout
///
/// 如果房间为空,代表管理无分配区域
/// 管理无分配区域才有效
/// 全局场景
void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List unallocatedList, List globalSceneList)
{
/// 房间所有功能和者场景列表
List roomFunctionOrSceneList = new List();
var roomView = new RowLayout()
{
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
LineColor = CSS_Color.MainBackgroundColor,
};
bodyScrolView.AddChidren(roomView);
var btnRoomName = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealWidth(10),
Width = Application.GetRealWidth(330),
Height = Application.GetRealWidth(30),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
//Text = room.roomName,
};
roomView.AddChidren(btnRoomName);
var btnRight = new Button()
{
X = Application.GetRealWidth(351),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
roomView.AddChidren(btnRight);
//如果房间为空,代表管理无分配区域
if (mRoom != null)
{
//显示房间名
btnRoomName.Text = mRoom.roomName;
var mRoomFunctionList = mRoom.GetRoomFunctions(false);
var mRoomSceneList = mRoom.GetRoomScenes(true);
//遍历所有功能列表
if (mRoomFunctionList != null)
{
foreach (var fun in mRoomFunctionList)
{
roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
{
targetId = fun.deviceId,
targetName = fun.name,
isDevice = true
});
}
}
//遍历所有场景列表
if (mRoomSceneList != null)
{
foreach (var roomScene in mRoomSceneList)
{
roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
{
targetId = roomScene.userSceneId,
targetName = roomScene.name,
isDevice = false
});
}
}
//roomId = mRoom.roomId;
//添加分割线
var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
roomView.AddChidren(lineView);
}
else
{
//显示无区域功能
btnRoomName.TextID = StringId.NoAreaFunction;
//遍历所有功能列表
if (unallocatedList != null)
{
foreach (var fun in unallocatedList)
{
roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
{
targetId = fun.deviceId,
targetName = fun.name,
isDevice = true
});
}
}
//遍历所有场景列表
if (globalSceneList != null)
{
foreach (var roomScene in globalSceneList)
{
roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
{
targetId = roomScene.userSceneId,
targetName = roomScene.name,
isDevice = false
});
}
}
}
//点击调整事件
EventHandler eHandler = (sender, e) =>
{
var page = new SmartSpeakerSelectDevicesPage(speakerInfo, roomFunctionOrSceneList);
MainPage.BasePageView.AddChidren(page);
page.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
roomView.MouseUpEventHandler = eHandler;
btnRoomName.MouseUpEventHandler = eHandler;
btnRight.MouseUpEventHandler = eHandler;
}
}
}