using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.SharedContent
{
///
/// 配置新共享内容的主界面
///
public class AddNewSharedListRoomForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 列表控件
///
private VerticalListControl listView = null;
///
/// 分享按钮
///
private BottomClickButton btnShard = null;
///
/// 成员ID
///
private string ChildAccountId = string.Empty;
///
/// 选择的房间
///
private Dictionary dicSelectRoom = new Dictionary();
///
/// 当前选择的楼层ID
///
private string nowSelectFloorId = string.Empty;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 成员ID
public void ShowForm(string i_ChildAccountId)
{
this.ChildAccountId = i_ChildAccountId;
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddShared));
//初始化右上角的控件
this.InitTopRightMenuControl();
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
var frameBack = new FrameLayout();
frameBack.Height = Application.GetRealHeight(141);
frameBack.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack);
//房间列表
var btnTitle = new NormalViewControl(800, 60, true);
btnTitle.X = HdlControlResourse.XXLeft;
btnTitle.Y = Application.GetRealHeight(52);
btnTitle.TextID = R.MyInternationalizationString.RoomList;
btnTitle.TextColor = UserCenterColor.Current.TextColor2;
btnTitle.TextSize = 15;
frameBack.AddChidren(btnTitle);
this.listView = new VerticalListControl(29);
listView.Y = frameBack.Bottom;
listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
listView.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(listView);
this.btnShard = new BottomClickButton();
btnShard.TextID = R.MyInternationalizationString.uShared2;
bodyFrameLayout.AddChidren(btnShard);
btnShard.Visible = false;
btnShard.ButtonClickEvent += (sender, e) =>
{
var listRoom = new List();
foreach (var room in this.dicSelectRoom.Values)
{
listRoom.Add(room);
}
//执行分享指定区域
this.DoSharedContentByRoom(listRoom);
};
HdlThreadLogic.Current.RunThread(() =>
{
//初始化区域列表
this.InitAreaListRow(this.nowSelectFloorId);
});
}
///
/// 初始化右上角的控件
///
private void InitTopRightMenuControl()
{
//获取楼层
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(300, 69, true);
btnFloor.Gravity = Gravity.CenterVertical;
btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
btnFloor.TextAlignment = TextAlignment.CenterRight;
topFrameLayout.AddChidren(btnFloor);
foreach (var floorId in dicFloor.Keys)
{
//第一个楼层
this.nowSelectFloorId = floorId;
btnFloor.Text = dicFloor[floorId];
break;
}
btnIconContr.ButtonClickEvent += (sender, e) =>
{
//楼层菜单
var contr = new TopRightFloorMenuControl(dicFloor.Count, 2, this.nowSelectFloorId, Language.StringByID(R.MyInternationalizationString.SelectFloor));
foreach (var floorId in dicFloor.Keys)
{
contr.AddRowMenu(floorId, () =>
{
//记录起选择的ID
this.nowSelectFloorId = floorId;
btnFloor.Text = dicFloor[this.nowSelectFloorId];
//初始化中部信息
this.InitMiddleFrame();
});
}
};
}
#endregion
#region ■ 区域列表___________________________
///
/// 初始化区域列表
///
/// 楼层ID
private void InitAreaListRow(string floorId)
{
dicSelectRoom.Clear();
var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(floorId, false);
HdlThreadLogic.Current.RunMain(() =>
{
var listDataRoom = new List();
for (int i = 0; i < listRoom.Count; i++)
{
//检测能否显示该房间
if (this.CheckCanShowRow(listRoom[i]) == true)
{
listDataRoom.Add(listRoom[i]);
}
}
for (int i = 0; i < listDataRoom.Count; i++)
{
//添加房间行
this.AddRoomRow(listDataRoom[i], i != listDataRoom.Count - 1);
}
//调整真实高度
listView.AdjustRealHeight(Application.GetRealHeight(23));
if (listView.Y + listView.Height > btnShard.Y)
{
//当这个列表控件的高度已经超过了【分享按钮】时,将它的高度直接扩大到最大化
listView.RecoverHeight();
//然后再添加一个空白的控件,促使它能够向上滑动
var frameTemp = new FrameLayout();
frameTemp.Height = bodyFrameLayout.Height - btnShard.Y;
listView.AddChidren(frameTemp);
}
if (listDataRoom.Count == 0)
{
//如果没有能够共享的房间
bodyFrameLayout.RemoveAll();
//无可共享的房间
this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotCanShardRoomMsg), "Item/NotShardPic.png", 383, 279);
}
});
}
///
/// 添加房间行
///
///
///
private void AddRoomRow(Common.Room room, bool addLine)
{
var row = new FrameRowControl(listView.rowSpace / 2);
row.MainKeys = room.Id;
listView.AddChidren(row);
//图标
var btnIcon = row.AddLeftIcon(81);
btnIcon.UnSelectedImagePath = "Item/RoomIconSelected.png";
//房间名
var btnName = row.AddLeftCaption(room.Name, 650);
btnName.TextSize = 15;
if (addLine == true)
{
//底线
row.AddBottomLine();
}
row.ButtonClickEvent += (sender, e) =>
{
var form = new AddNewSharedContentForm();
form.AddForm(room, this.ChildAccountId);
};
//选择
var btnSelect = row.AddMostRightEmptyIcon(69, 69);
btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
btnSelect.SelectedImagePath = "Item/ItemSelected.png";
row.ChangedChidrenBindMode(btnSelect, ChidrenBindMode.NotBind);
btnSelect.ButtonClickEvent += (sender, e) =>
{
if (btnSelect.IsSelected == true)
{
btnSelect.IsSelected = false;
dicSelectRoom.Remove(room.Id);
if (dicSelectRoom.Count == 0)
{
btnShard.Visible = false;
}
}
else
{
btnSelect.IsSelected = true;
dicSelectRoom[room.Id] = room;
if (btnShard.Visible == false)
{
btnShard.Visible = true;
}
}
};
}
#endregion
#region ■ 分享指定区域_______________________
///
/// 执行分享指定区域
///
/// 指定要分享的房间
public void DoSharedContentByRoom(List listRoom)
{
HdlThreadLogic.Current.RunThread(() =>
{
//打开进度条
this.ShowProgressBar();
//上传分享
var result = HdlShardLogic.Current.UploadSharedRoom(this.ChildAccountId, listRoom);
//关闭进度条
this.CloseProgressBar();
if (result == true)
{
//不刷新界面
HdlThreadLogic.Current.RunMain(() =>
{
if (this.Parent != null)
{
//重新刷新界面
this.InitMiddleFrame();
}
});
}
});
}
#endregion
#region ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
///
public override int FormActionAgainEvent()
{
//重新刷新界面
this.InitMiddleFrame();
return 1;
}
#endregion
#region ■ 一般方法___________________________
///
/// 检测该房间能否显示
///
///
///
private bool CheckCanShowRow(Common.Room room)
{
if (room.ListDevice.Count == 0 && room.ListSceneId.Count == 0)
{
return false;
}
if (room.IsLove == true)
{
return false;
}
if (HdlShardLogic.Current.GetShardRoomFromMemory(room.Id) == null)
{
//没有这个房间
return true;
}
foreach (var deviceKeys in room.ListDevice)
{
if (HdlDeviceCommonLogic.Current.GetDevice(deviceKeys) == null)
{
//本地没有这个设备
continue;
}
if (HdlShardLogic.Current.GetShardDeviceFromMemory(deviceKeys) == null)
{
//存在未分享的设备的话,此房间可以显示
return true;
}
}
foreach (var sceneId in room.ListSceneId)
{
if (HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId) == null)
{
//本地没有这个场景
continue;
}
if (HdlShardLogic.Current.GetShardSceneFromMemory(sceneId) == null)
{
//存在未分享的场景的话,此房间可以显示
return true;
}
}
return false;
}
#endregion
}
}