using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
using System.Collections.Generic;
using HDL_ON.DAL;
namespace HDL_ON.UI
{
///
/// 使用权限页面
///
public partial class MemberPermissionPage : FrameLayout
{
MemberPermissionPage bodyView;
Button btnDelMember;
VerticalScrolViewLayout roomListView;
ResidenceMemberInfo memberInfo;
Action backAction;
public MemberPermissionPage(ResidenceMemberInfo mInfo,Action action)
{
bodyView = this;
memberInfo = mInfo;
backAction = action;
}
public void LoadPage()
{
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
new TopViewDiv(bodyView, Language.StringByID(StringId.PermissionToUse)).LoadTopView();
FrameLayout headPortraitView = new FrameLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(66),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(headPortraitView);
ImageView userHeadImageView = new ImageView()
{
X = Application.GetRealWidth(16),
Gravity = Gravity.CenterVertical,
Width = Application.GetRealWidth(42),
Height = Application.GetRealWidth(42),
Radius = (uint)Application.GetRealWidth(21),
ImagePath = memberInfo.headImagePagePath
};
headPortraitView.AddChidren(userHeadImageView);
Button btnMemberName = new Button()
{
X = Application.GetRealWidth(70),
Width = Application.GetRealWidth(300),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
Text = memberInfo.nickName + "(" + memberInfo.Account + ")",
};
headPortraitView.AddChidren(btnMemberName);
#region RoomList
roomListView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(138),
Height = Application.GetRealHeight(471),
//BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(roomListView);
#endregion
btnDelMember = new Button()
{
Y = Application.GetRealHeight(617),
//Height = MainPage.Increase ? Application.GetRealHeight(70) : Application.GetRealHeight(50),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.WarningColor,
TextID = StringId.RemoveTheMember,
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(btnDelMember);
LoadEventList();
GetShareDataByAccount();
}
///
/// 加载房间列表,统计分享的数据
///
void ShowRoomListView()
{
roomListView.RemoveAll();
var titleView = new FrameLayout()
{
BackgroundColor = CSS_Color.MainBackgroundColor,
Height = Application.GetRealWidth(44),
};
roomListView.AddChidren(titleView);
var btnTitle = new Button()
{
X = Application.GetRealWidth(16),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.UseArea,
};
titleView.AddChidren(btnTitle);
var btnLine = new Button()
{
X = Application.GetRealWidth(16),
Y = btnTitle.Bottom,
Width = Application.GetRealWidth(360),
Height = Application.GetRealHeight(1),
BackgroundColor = CSS_Color.DividingLineColor,
};
roomListView.AddChidren(btnLine);
//---------------------------------------------
//var roomListView = new VerticalScrolViewLayout()
//{
// Y = btnLine.Bottom,
// Height = Application.GetRealHeight(440),
//};
//contentView.AddChidren(roomListView);
//List funss = new List();
//if (memberInfo.CurResidenceShareDate.Count > 0)
//{
// foreach (var sd in memberInfo.CurResidenceShareDate)
// {
// funss.Add(Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(sd.ShareDataBytes)));
// }
//}
foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
{
var roomView = new FrameLayout()
{
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
roomListView.AddChidren(roomView);
var btnRoomName = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealWidth(4),
Width = Application.GetRealWidth(330),
Height = Application.GetRealWidth(24),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
Text = room.roomName,
};
roomView.AddChidren(btnRoomName);
//计算已经加入房间的设备数量
int addCount = 0;
foreach (var sd in memberInfo.CurResidenceShareDate)
{
if (room.GetRoomFunctions(false).Find((obj) => obj.deviceId == sd.shareTypeId) != null)
{
addCount++;
}
}
//移除当前住宅已经不存在的功能
for (int i = 0; i < memberInfo.CurResidenceShareDate.Count;)
{
var sd = memberInfo.CurResidenceShareDate[i];
if (FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.deviceId == sd.shareTypeId) == null)
{
//new DAL.Server.HttpServerRequest().DeleteShareData(sd);
memberInfo.CurResidenceShareDate.Remove(sd);
}
else
{
i++;
}
}
var btnFunctionCount = new Button()
{
X = Application.GetRealWidth(16),
Y = btnRoomName.Bottom,
Width = Application.GetRealWidth(330),
Height = Application.GetRealWidth(18),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
};
roomView.AddChidren(btnFunctionCount);
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);
EventHandler eHandler = (sender, e) =>
{
Action refreshFunctionCount = (newCount) => {
btnFunctionCount.Text = newCount + "/" + room.GetRoomFunctions(false).Count.ToString();
};
var mmp = new MemberFunctionPermissionPage(memberInfo, room, refreshFunctionCount);
MainPage.BasePageView.AddChidren(mmp);
mmp.LoadPage(StringId.PermissionToUse);
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
roomView.MouseUpEventHandler = eHandler;
btnRoomName.MouseUpEventHandler = eHandler;
btnRight.MouseUpEventHandler = eHandler;
btnFunctionCount.MouseUpEventHandler = eHandler;
if (SpatialInfo.CurrentSpatial.RoomList.IndexOf(room) < SpatialInfo.CurrentSpatial.RoomList.Count - 2)
{
var btnRoomLine = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealWidth(49),
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(1),
BackgroundColor = CSS_Color.DividingLineColor,
};
roomView.AddChidren(btnRoomLine);
}
}
//if (DB_ResidenceData.rooms.Count > 10)
//{
// roomListView.ScrollEnabled = true;
//}
//else
//{
// roomListView.ScrollEnabled = false;
// roomListView.AddChidren(new Button()
// {
// Height = Application.GetRealWidth(441),
// BackgroundColor = CSS_Color.BackgroundColor,
// });
//}
}
}
}