using System;
using Shared.Common;
namespace Shared.Phone.Device.Room
{
public class RoomManagement : FrameLayout
{
public Action action;
///
/// 房间管理
///
public void Show()
{
RoomPage();
}
public override void RemoveFromParent()
{
//更新界面
action();
base.RemoveFromParent();
}
///
/// 房间管理界面
///
void RoomPage()
{
RemoveAll();
#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,
TextID=R.MyInternationalizationString.RoomList,
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();
};
var addRoomItemBtn = new Device.CommonForm.SelectedStatuButton()
{
Width = Application.GetMinRealAverage(100),
Height = Application.GetMinRealAverage(100),
UnSelectedImagePath = "Item/Add.png",
SelectedImagePath="Item/AddSelected.png",
X = Application.GetRealWidth(1080 - 150),
Gravity = Gravity.CenterVertical
};
topView.AddChidren(addRoomItemBtn);
//Action action = RoomPage;
addRoomItemBtn.MouseUpEventHandler += (sender, e) =>
{
//AddOrUpdateRoom(action);
var addRoom = new AddRoom();
Shared.Phone.UserView.HomePage.Instance.AddChidren(addRoom);
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
addRoom.action = () =>
{
Show();
};
AddRoom.OldBackgroundImagePath = string.Empty;
addRoom.Show("");
};
#endregion
var middleHomePage = new FrameLayout()
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
Y = topView.Bottom,
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
this.AddChidren(middleHomePage);
var RoomBodyView = new VerticalScrolViewLayout()
{
Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
middleHomePage.AddChidren(RoomBodyView);
foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList)
{
var room = Shared.Common.Room.GetRoomByFilePath(roomFilePath);
if (room == null)
{
continue;
}
var roomFL = new FrameLayout()
{
Height = Application.GetRealHeight(570),
Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonPage.XLeft * 2),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
Gravity = Gravity.CenterHorizontal,
Radius = CommonPage.BigFormRadius,
};
RoomBodyView.AddChidren(roomFL);
var roomRowView = new RowLayout()
{
Y = Application.GetRealHeight(20),
Height = Application.GetMinRealAverage(550),
Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonPage.XLeft * 2),
BackgroundColor =ZigbeeColor.Current.GXCBackgroundColor,
LineColor= ZigbeeColor.Current.GXCBackgroundColor,
Radius = CommonPage.BigFormRadius,
Gravity = Gravity.CenterHorizontal
};
roomFL.AddChidren(roomRowView);
var backGroundBtn = new Button()
{
UnSelectedImagePath = room.BackgroundImage,
Radius = CommonPage.BigFormRadius,
Height = Application.GetMinRealAverage(550),
Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonPage.XLeft * 2),
};
roomRowView.AddChidren(backGroundBtn);
var hardBlackBG = new FrameLayout()
{
Radius = CommonPage.BigFormRadius,
BackgroundColor = ZigbeeColor.Current.GXCBlack70Color
};
roomRowView.AddChidren(hardBlackBG);
var btnRoomName = new Button()
{
Width = Application.GetRealWidth(500),
Height=Application.GetRealHeight(200),
Text = room.Name,
TextAlignment = TextAlignment.Center,
TextSize=25,
TextColor=ZigbeeColor.Current.GXCTextWhiteColor,
Gravity=Gravity.Center
};
roomRowView.AddChidren(btnRoomName);
var btnEditRoom = new Device.CommonForm.SelectedStatuButton()
{
X = roomRowView.Width- Application.GetRealWidth(100+30),
Y=backGroundBtn.Y,
Width = Application.GetMinRealAverage(110),
Height=Application.GetMinRealAverage(110),
UnSelectedImagePath = "Room/More.png",
SelectedImagePath="Room/MoreSelected.png",
};
roomRowView.AddChidren(btnEditRoom);
var delBtn = new Shared.Phone.Device.CommonForm.RowLayoutDeleteButton();
//第一个是房间喜爱,不允许滑动删除 分享过来的也不允许删除
if (!room.IsLove || !room.IsSharedRoom){
roomRowView.AddRightView(delBtn);
}
//删除住宅
delBtn.MouseUpEventHandler += (sender, e) =>
{
var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConfirmDeleteThisRoom), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
alert.Show();
alert.ResultEventHandler += (send, ee) =>
{
if(ee)
{
Shared.Common.Room.CurrentRoom.Remove(roomFilePath);
Show();
}
};
};
btnEditRoom.MouseUpEventHandler += (sender, e) =>
{
//AddOrUpdateRoom(action, roomFilePath);
var addRoom = new AddRoom();
Shared.Phone.UserView.HomePage.Instance.AddChidren(addRoom);
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
addRoom.action = () =>
{
Show();
};
AddRoom.OldBackgroundImagePath = string.Empty;
addRoom.Show(roomFilePath);
};
roomRowView.MouseUpEventHandler += (sender, e) =>
{
//var userRoom = new RoomAddDevice();
//this.AddChidren(userRoom);
//userRoom.Show(roomFilePath);
};
}
}
}
}