using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserCenter;
using Shared.Phone.UserView;
namespace Shared.Phone.MainPage
{
///
/// 左滑菜单的的房间列表界面
///
public class ListRoomViewFrom : EditorCommonForm
{
#region ■ 变量声明___________________________
private static ListRoomViewFrom roomManagement = null;
///
/// 左滑菜单的的房间对象
///
public static ListRoomViewFrom Instance
{
get
{
if (roomManagement == null)
{
//初始化左滑菜单
roomManagement = new ListRoomViewFrom();
CommonPage.Instance.AddLeftView(roomManagement);
}
return roomManagement;
}
}
///
/// 是否可以触发点击事件--是否可以跳转主页房间
///
public bool CanClick = true;
///
/// 是否初始化完成
///
private bool isInitFinish = false;
///
/// 当前楼层id
///
private string curFloorId = string.Empty;
///
/// 列表控件
///
private VerticalFrameControl listView = null;
///
/// 卡片控件集合
///
private Dictionary dicCardControl = new Dictionary();
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示
///
public void ShowForm()
{
//初始化头部信息
this.InitTopFrame();
//初始化中部控件
this.InitBodyFrameLayout();
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化头部信息
///
private void InitTopFrame()
{
//初始化头部控件
this.InitTopFrameLayout();
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.RoomList));
//重置返回按键的事件
var btnBack = this.GetBackButton();
btnBack.ButtonClickEvent = null;
btnBack.ButtonClickEvent += (sender, e) =>
{
//收起左菜单
CommonPage.Instance.CloseLeftMenu();
};
//获取楼层
this.curFloorId = Config.Instance.Home.CurrentFloorId;
var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
if (dicFloor.Count == 0)
{
return;
}
//楼层图标
var btnIconContr = new MostRightIconControl(69, 69);
btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
topFrameLayout.AddChidren(btnIconContr);
btnIconContr.InitControl();
//楼层名
var btnFloor = new NormalViewControl(200, 69, true);
btnFloor.Gravity = Gravity.CenterVertical;
btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(200);
btnFloor.TextAlignment = TextAlignment.CenterRight;
btnFloor.Text = HdlResidenceLogic.Current.GetFloorNameById(this.curFloorId);
topFrameLayout.AddChidren(btnFloor);
btnIconContr.ButtonClickEvent += (sender, e) =>
{
//楼层菜单
var floors = new Category.SelectFloorForm();
AddChidren(floors);
floors.changeFloor = false;
floors.CurFloorId = curFloorId;
floors.Init(599, 161, Direction.Right);
floors.FloorAction += (floorId) =>
{
this.curFloorId = floorId;
btnFloor.Text = dicFloor[floorId];
//刷新Body容器
this.RefreshBodyFrame();
};
};
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
this.listView = new VerticalFrameControl();
listView.Height = bodyFrameLayout.Height;
listView.Width = bodyFrameLayout.Width;
bodyFrameLayout.AddChidren(listView);
//刷新Body容器
this.RefreshBodyFrame();
}
#endregion
#region ■ 刷新房间列表_______________________
///
/// 刷新房间列表
///
public void RefreshListRoom()
{
//如果还没有初始化完成界面的话
if (this.isInitFinish == false)
{
this.ShowForm();
this.isInitFinish = true;
return;
}
//把头部也一起初始化了
this.topFrameLayout.RemoveAll();
//初始化头部信息
this.InitTopFrame();
//刷新Body容器
this.RefreshBodyFrame();
}
///
/// 刷新Body容器
///
private void RefreshBodyFrame()
{
//先清空
this.listView.frameTable.RemoveAll();
this.listView.frameTable.Height = Application.GetRealHeight(100);
this.dicCardControl.Clear();
var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(curFloorId);
//追加我的喜爱
listRoom.Insert(0, HdlRoomLogic.Current.GetLoveRoom());
//X轴
int XX = this.GetPictrueRealSize(43);
//Y轴
int YY = this.GetPictrueRealSize(58);
//房间计数
int roomCount = 0;
foreach (var room in listRoom)
{
roomCount++;
//初始化卡片控件
var contr = new Controls.ListRoomCardControl();
contr.X = XX;
contr.Y = YY;
listView.frameTable.AddChidren(contr);
contr.InitControl(room);
//加缓存
this.dicCardControl[room.Id] = contr;
//每两个重置X轴
XX = roomCount % 2 == 0 ? this.GetPictrueRealSize(43) : contr.Right + this.GetPictrueRealSize(3);
//每两个累加Y轴
if (roomCount >= 2 && roomCount % 2 == 0)
{
YY = contr.Bottom + this.GetPictrueRealSize(14);
}
contr.ButtonClickEvent += (sender, e) =>
{
if (CanClick == false)
{
return;
}
string oldFloorId = Config.Instance.Home.CurrentFloorId;
CommonPage.Instance.CloseLeftMenu();
HdlThreadLogic.Current.RunThread(() =>
{
//等待控件向左移动结束
System.Threading.Thread.Sleep(300);
HdlThreadLogic.Current.RunMain(() =>
{
//点击的是收藏房间的话,不变更当前楼层id
if (room.FloorId != string.Empty)
{
Config.Instance.Home.CurrentFloorId = room.FloorId;
if (oldFloorId != room.FloorId)
{
//楼层都切换的话,刷新整个主页
UserPage.Instance.ReFreshControl();
return;
}
}
//如果只是切换当前楼层的其他房间,则只滑动主页的滑动控件
HomeMainPageForm.Instance?.SetRoomPageViewSelect(room);
});
});
};
}
//成员是没有未分配这个东西出来的
if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
{
//初始化未分配卡片
this.InitRoomCardControl(XX, YY);
}
//调整桌布高度
this.listView.AdjustTableHeight();
}
///
/// 初始化未分配卡片
///
private void InitRoomCardControl(int XX, int YY)
{
//桌布控件
var frameBack = new FrameLayoutStatuControl();
frameBack.X = XX;
frameBack.Y = YY;
frameBack.Width = this.GetPictrueRealSize(495);
frameBack.Height = this.GetPictrueRealSize(354);
listView.frameTable.AddChidren(frameBack);
//底部阴影效果
var btnShadow = new NormalViewControl(frameBack.Width, frameBack.Height, false);
btnShadow.UnSelectedImagePath = "Room/RoomCardView.png";
frameBack.AddChidren(btnShadow, ChidrenBindMode.NotBind);
//背景控件
var picBackGroud = new NormalViewControl(this.GetPictrueRealSize(467), this.GetPictrueRealSize(311), false);
picBackGroud.Gravity = Gravity.CenterHorizontal;
picBackGroud.Radius = (uint)this.GetPictrueRealSize(29);
picBackGroud.BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor3;
frameBack.AddChidren(picBackGroud, ChidrenBindMode.BindEvent);
//未分配图标
var btnIcon = new PicViewControl(92, 72);
btnIcon.X = this.GetPictrueRealSize(129);
btnIcon.Y = this.GetPictrueRealSize(141);
btnIcon.UnSelectedImagePath = "Room/NoNameRoom.png";
frameBack.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
//未分配
var btnName = new NormalViewControl(141, 84, true);
btnName.X = this.GetPictrueRealSize(244);
btnName.Y = this.GetPictrueRealSize(131);
btnName.IsBold = true;
btnName.TextColor = UserCenterColor.Current.White;
btnName.TextID = R.MyInternationalizationString.Unallocated;
frameBack.AddChidren(btnName, ChidrenBindMode.BindEvent);
frameBack.ButtonClickEvent += (sender, e) =>
{
if (this.CanClick == false)
{
return;
}
//未分配
var unalloctedRoom = new UnallocatedRoomForm();
this.AddChidren(unalloctedRoom);
unalloctedRoom.ShowForm();
};
}
#endregion
#region ■ 刷新指定房间_______________________
///
/// 刷新指定房间
///
///
public void RefreshRoomInfo(Room room)
{
if (this.dicCardControl.ContainsKey(room.Id) == true)
{
//刷新卡片信息
this.dicCardControl[room.Id].RefreshControl();
}
}
#endregion
}
}