using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using ZigBee.Device; namespace Shared.Phone.UserCenter.SharedContent { /// /// 查看已共享内容的房间列表界面★ /// public class LookSharedListRoomForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 列表控件 /// private VerticalFrameControl listView = null; /// /// 成员信息 /// private MemberInfoRes memberResult = null; /// /// 成员的分享数据 /// private MemberShardInfoData memberShardInfo = null; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 成员信息 /// 成员的共享信息 public void ShowForm(MemberInfoRes i_memberResult, MemberShardInfoData i_memberShardInfo) { this.memberResult = i_memberResult; this.memberShardInfo = i_memberShardInfo; this.memberShardInfo.SubAccountDistributedMark = this.memberResult.SubAccountDistributedMark; //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uShared2)); //添加图标 var btnAdd = new MostRightIconControl(69, 69); btnAdd.UnSelectedImagePath = "Item/Add.png"; btnAdd.ButtonClickEvent += (sender, e) => { var form = new AddNewSharedListRoomForm(); form.AddForm(this.memberResult, this.memberShardInfo); }; topFrameLayout.AddChidren(btnAdd); btnAdd.InitControl(); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); HdlThreadLogic.Current.RunThread(() => { //获取成员的共享列表 var result = HdlShardLogic.Current.GetMemberShardContentListAndSetToLocation(memberShardInfo); if (result == false) { //显示重新加载的界面 this.ShowReLoadView(); return; } //初始化区域列表 this.InitAreaListRow(); }); } #endregion #region ■ 区域列表___________________________ /// /// 初始化区域列表 /// private void InitAreaListRow() { if (memberShardInfo.dicShardRoom.Count == 0) { HdlThreadLogic.Current.RunMain(() => { bodyFrameLayout.RemoveAll(); //还没有共享区域给成员{0}可点击右上角“+”添加 string msg = Language.StringByID(R.MyInternationalizationString.uNotShardComtentMsg); string[] Arry = msg.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries); this.ShowNotDataImage(bodyFrameLayout, Arry, "Item/NotShardPic.png", 383, 279); }); } else { //合并同一楼层的房间 var dicGroup = new Dictionary>(); foreach (var room in memberShardInfo.dicShardRoom.Values) { if (dicGroup.ContainsKey(room.FloorId) == false) { dicGroup[room.FloorId] = new List(); } dicGroup[room.FloorId].Add(room); } HdlThreadLogic.Current.RunMain(() => { bodyFrameLayout.RemoveAll(); this.listView = new VerticalFrameControl(29); listView.Height = bodyFrameLayout.Height; bodyFrameLayout.AddChidren(listView); //排序楼层 var dicSort = HdlRoomLogic.Current.GetFloorSortList(); foreach (var floorId in dicSort.Keys) { if (dicGroup.ContainsKey(floorId) == true) { //添加各自楼层的房间列表 this.AddRoomListRow(floorId, dicGroup[floorId]); dicGroup.Remove(floorId); } } //添加各自楼层的房间列表(这里是指定楼层并不在排序记录里面的) foreach (var floorId in dicGroup.Keys) { this.AddRoomListRow(floorId, dicGroup[floorId]); } //调整桌布高度 listView.AdjustTableHeight(); }); } } /// /// 添加房间列表行 /// /// private void AddRoomListRow(string floorId, List listRoom) { var frameBack = new FrameListControl(29); frameBack.BackgroundColor = UserCenterColor.Current.White; frameBack.Height = 10; this.listView.AddChidren(frameBack); //楼层 if (string.IsNullOrEmpty(floorId) == false) { var btnFloor = new NormalViewControl(800, 60, true); btnFloor.X = ControlCommonResourse.XXLeft; btnFloor.Y = Application.GetRealHeight(52); btnFloor.TextColor = UserCenterColor.Current.TextColor2; btnFloor.TextSize = 15; frameBack.AddChidren(btnFloor); if (memberShardInfo.dicShardFloor.ContainsKey(floorId) == true) { btnFloor.Text = memberShardInfo.dicShardFloor[floorId]; } else if (floorId == "Other") { //未分配区域 btnFloor.Text = Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); } else { btnFloor.Text = "UnKnown"; } } //房间排序 var listSortRoom = HdlRoomLogic.Current.GetFloorSortRoom(floorId, false); var listSort = new HashSet(); foreach (var room in listSortRoom) { //收集现有的排序ID listSort.Add(room.Id); } var dicRoom = new Dictionary(); foreach (var room in listRoom) { //保存需要显示出来的房间 dicRoom[room.Id] = room; if (listSort.Contains(room.Id) == false) { //不再排序记录内,则在尾部追加 listSort.Add(room.Id); } } foreach(var roomId in listSort) { if (dicRoom.ContainsKey(roomId) == false) { continue; } var room = dicRoom[roomId]; dicRoom.Remove(roomId); var frameRow = new RowLayoutControl(frameBack.rowSpace / 2); frameBack.AddChidren(frameRow); //图标 var btnIcon = frameRow.frameTable.AddLeftIcon(81); btnIcon.UnSelectedImagePath = "Item/RoomIconSelected.png"; //名称 var btnName = frameRow.frameTable.AddLeftCaption(room.Name, 600); btnName.TextSize = 15; //右箭头 frameRow.frameTable.AddRightArrow(); if (dicRoom.Count != 0) { //底线 frameRow.frameTable.AddBottomLine(); } frameRow.frameTable.ButtonClickEvent += (sender, e) => { var form = new LookSharedContentForm(); form.AddForm(room, memberShardInfo); }; //删除 var btnDelete = new NormalViewControl(Application.GetRealWidth(184), frameRow.Height, false); btnDelete.BackgroundColor = 0xfff75858; btnDelete.TextSize = 12; btnDelete.TextColor = UserCenterColor.Current.White; btnDelete.TextAlignment = TextAlignment.Center; btnDelete.TextID = R.MyInternationalizationString.uDelete; frameRow.AddRightView(btnDelete); btnDelete.ButtonClickEvent += (sender, e) => { //确认删除共享房间? string msg = Language.StringByID(R.MyInternationalizationString.uDeleteShardRoomMsg); this.ShowMassage(ShowMsgType.Confirm, msg, () => { //删除共享区域 this.DoDeleteShardContentByRoom(room); }); }; } //调整子控件Frame高度 this.listView.AdjustChidrenFrameHeight(frameBack, Application.GetRealHeight(29)); } #endregion #region ■ 删除共享区域_______________________ /// /// 删除共享区域 /// /// 指定要删除的共享区域 public void DoDeleteShardContentByRoom(Common.Room room) { //获取全部设备 var listDevice = new List(); foreach (var deviceKeys in room.ListDevice) { string deviceFile = HdlShardLogic.Current.GetShardDeviceFileName(deviceKeys); if (deviceFile == string.Empty) { continue; } var byteData = HdlShardLogic.Current.GetShardFileContent(deviceFile); if (byteData == null) { continue; } var device = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(byteData)); listDevice.Add(device); } //获取全部场景 var listScene = new List(); foreach (var sceneId in room.ListSceneId) { var byteData = HdlShardLogic.Current.GetShardFileContent($"Scene_{sceneId}.json"); if (byteData == null) { continue; } var sceneUi = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(byteData)); listScene.Add(sceneUi); } HdlThreadLogic.Current.RunThread(() => { //执行删除 var result = HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, room, listDevice, listScene); if (result == true) { HdlThreadLogic.Current.RunMain(() => { //重新刷新界面 this.InitMiddleFrame(); }); } }); } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// public override int FormActionAgainEvent() { //重新刷新界面 this.InitMiddleFrame(); return 1; } #endregion } }