using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.SharedContent { /// /// 查看已配置共享内容的主界面 /// public class LookSharedContentForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 查看的房间对象 /// private Common.Room lookRoom = null; /// /// 成员的分享数据 /// private MemberShardInfoData memberShardInfo = null; /// /// 设备桌布控件 /// private FrameLayout frameDeviceTable = null; /// /// 设备桌布控件 /// private FrameLayout frameSceneTable = null; /// /// 删除按钮 /// private BottomClickButton btnDelete = null; /// /// 选择的场景 /// private Dictionary dicSelectScene = new Dictionary(); /// /// 选择的设备 /// private Dictionary dicSelectDevice = new Dictionary(); /// /// 当前选择的分支 1:场景 2:功能 /// private int nowSwitchIndex = 1; /// /// 当前选择的设备索引 /// private string nowDeviceIndex = string.Empty; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 查看的房间对象 /// 成员的分享数据 public void ShowForm(Common.Room i_room, MemberShardInfoData i_memberShardInfo) { this.lookRoom = i_room; this.memberShardInfo = i_memberShardInfo; //设置头部信息 base.SetTitleText(i_room.Name); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); this.dicSelectDevice = new Dictionary(); this.dicSelectScene = new Dictionary(); //初始化桌布控件 this.frameSceneTable = new FrameLayout(); frameSceneTable.Y = Application.GetRealHeight(132); frameSceneTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(132); bodyFrameLayout.AddChidren(frameSceneTable); this.frameDeviceTable = new FrameLayout(); frameDeviceTable.Y = frameSceneTable.Y; frameDeviceTable.Height = frameSceneTable.Height; bodyFrameLayout.AddChidren(frameDeviceTable); frameDeviceTable.Visible = false; //初始化分支控件 this.InitSwitchControl(); //删除按钮 this.btnDelete = new BottomClickButton(); btnDelete.BackgroundColor = 0xfff75858; btnDelete.TextID = R.MyInternationalizationString.uDelete; bodyFrameLayout.AddChidren(btnDelete); btnDelete.Visible = false; btnDelete.ButtonClickEvent += (sender, e) => { //删除分享 this.DeleteShardData(); }; //初始化场景列表 this.InitSceneList(); //初始功能列表 this.InitFunctionList(); } /// /// 初始化分支控件 /// private void InitSwitchControl() { var tabControl = new SceneFunctionSwitchControl(); tabControl.Y = Application.GetRealHeight(40); bodyFrameLayout.AddChidren(tabControl); //设置初始化值 tabControl.SetDefultIndex(nowSwitchIndex); tabControl.SelectTabEvent += (tabIndex) => { this.nowSwitchIndex = tabIndex; if (tabIndex == 1) { //显示场景列表 this.frameSceneTable.Visible = true; this.frameDeviceTable.Visible = false; } else { //显示功能列表 this.frameSceneTable.Visible = false; this.frameDeviceTable.Visible = true; } }; tabControl.InitControl(); } #endregion #region ■ 场景显示___________________________ /// /// 初始化场景列表 /// private void InitSceneList() { //清空桌布 this.frameSceneTable.RemoveAll(); var listScene = new List(); for (int i = 0; i < lookRoom.SceneUIList.Count; i++) { if (HdlShardLogic.Current.IsFileExists(lookRoom.SceneUIList[i].FileName) == true) { listScene.Add(lookRoom.SceneUIList[i]); } } if (listScene.Count == 0) { //无可取消共享的场景 this.ShowNotDataImage(frameSceneTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelShardSceneMsg), "Item/NotShardPic.png", 383, 279); return; } HdlThreadLogic.Current.RunMainInThread(() => { var listView = new VerticalFrameControl(29); listView.Y = Application.GetRealHeight(53); listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(187); frameSceneTable.AddChidren(listView); foreach (var data in listScene) { //场景图片 var frameContr = new FrameLayoutControl(); frameContr.UseClickStatu = false; frameContr.Height = Application.GetRealHeight(470); listView.AddChidrenFrame(frameContr); //场景图片 var btnPic = new ImageView(); btnPic.X = Application.GetRealWidth(179); btnPic.Width = Application.GetRealWidth(844); btnPic.Height = Application.GetRealHeight(420); btnPic.ImagePath = data.IconPath; btnPic.Radius = 17; frameContr.AddChidren(btnPic); var btnName = new NormalViewControl(251, 282, true); btnName.X = ControlCommonResourse.XXLeft; btnName.Gravity = Gravity.CenterVertical; btnName.BackgroundColor = 0xff333333; btnName.Radius = 17; btnName.Text = data.Name; btnName.TextSize = 15; btnName.TextColor = UserCenterColor.Current.White; btnName.TextAlignment = TextAlignment.Center; frameContr.AddChidren(btnName); var btnSelect = new IconViewControl(58); btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png"; btnSelect.SelectedImagePath = "Item/ItemSelected.png"; btnSelect.X = Application.GetRealWidth(887); btnSelect.Y = Application.GetRealHeight(35); frameContr.AddChidren(btnSelect, ChidrenBindMode.BindEventOnly); if (dicSelectScene.ContainsKey(data.Id) == true) { btnSelect.IsSelected = true; } frameContr.ButtonClickEvent += (sender, e) => { //选择 btnSelect.IsSelected = !btnSelect.IsSelected; if (btnSelect.IsSelected == true) { dicSelectScene[data.Id] = data; if (this.btnDelete.Visible == false) { this.btnDelete.Visible = true; } } else { dicSelectScene.Remove(data.Id); if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) { this.btnDelete.Visible = false; } } }; } }); } #endregion #region ■ 功能显示___________________________ /// /// 初始化功能列表 /// private void InitFunctionList() { //清空桌布 this.frameDeviceTable.RemoveAll(); HdlThreadLogic.Current.RunMainInThread(() => { //获取分组后的设备列表 var dicGroupDevice = this.GetAllGroupDevice(); if (dicGroupDevice.Count == 0) { //无可取消共享的设备 this.ShowNotDataImage(frameDeviceTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelDeviceMsg), "Item/NotShardPic.png", 383, 279); } else { var frameBack = new FrameLayoutControl(false); frameBack.X = ControlCommonResourse.XXLeft; frameBack.Y = Application.GetRealHeight(178); frameBack.BackgroundColor = UserCenterColor.Current.White; frameBack.Width = bodyFrameLayout.Width; frameBack.Height = Application.GetRealHeight(1650); frameBack.RadiusEx = 20; frameDeviceTable.AddChidren(frameBack); var listView = new VerticalListControl(23); listView.Y = Application.GetRealHeight(23); listView.Height = Application.GetRealHeight(1437 - 23); frameBack.AddChidren(listView); //初始化设备类型行 this.InitDeviceObjectRow(dicGroupDevice, listView); } }); } #endregion #region ■ 初始化设备类型行___________________ /// /// 初始化设备类型行 /// /// /// private void InitDeviceObjectRow(Dictionary> dicData, VerticalListControl listView) { var scrolContr = new RoomDeviceGroupMenuControl(dicData); this.frameDeviceTable.AddChidren(scrolContr); //设置初始值 scrolContr.SetDefultIndex(nowDeviceIndex); scrolContr.SelectDeviceEvent += (listdevice) => { this.nowDeviceIndex = scrolContr.nowSelectKeys; //添加设备行 this.AddDeviceRow(listdevice, listView); }; scrolContr.InitControl(); } #endregion #region ■ 添加设备行_________________________ /// /// 添加设备行 /// /// /// private void AddDeviceRow(List listDevice, VerticalListControl listView) { listView.RemoveAll(); foreach (var device in listDevice) { var frameRow = new FrameRowControl(listView.rowSpace / 2); frameRow.LeftOffset = Application.GetRealWidth(46) - ControlCommonResourse.XXLeft; frameRow.RightOffset = -ControlCommonResourse.XXLeft; listView.AddChidren(frameRow); //图标 var btnIcon = frameRow.AddLeftIcon(81); Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device); //名称 var btnView = frameRow.AddLeftCaption(string.Empty, 600); btnView.Text = Common.LocalDevice.Current.GetDeviceEpointName(device); btnView.TextSize = 15; //底线 frameRow.AddBottomLine(); //选择 var btnSelect = frameRow.AddMostRightEmptyIcon(69, 69); btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png"; btnSelect.SelectedImagePath = "Item/ItemSelected.png"; string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); if (dicSelectDevice.ContainsKey(mainKeys) == true) { btnSelect.IsSelected = true; } frameRow.ButtonClickEvent += (sender, e) => { //选择 btnSelect.IsSelected = !btnSelect.IsSelected; if (btnSelect.IsSelected == true) { dicSelectDevice[mainKeys] = device; if (this.btnDelete.Visible == false) { this.btnDelete.Visible = true; } } else { dicSelectDevice.Remove(mainKeys); if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) { this.btnDelete.Visible = false; } } }; } } #endregion #region ■ 整合设备___________________________ /// /// 获取分组后的设备 /// /// private Dictionary> GetAllGroupDevice() { //全部的设备 var listDevice = this.GetShardListDevice(); var dic = new Dictionary>(); foreach (var device in listDevice) { var typeInfo = Common.LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List() { device }); if (device.Type == DeviceType.IASZone) { //这个强制为传感器 typeInfo.BeloneTextId = R.MyInternationalizationString.uDeviceBelongId1200; typeInfo.ConcreteType = Common.DeviceConcreteType.Sensor; } if (device.Type == DeviceType.OnOffOutput) { //继电器的时候,需要特殊处理 if (device.DfunctionType == DeviceFunctionType.A开关) { typeInfo.BeloneTextId = R.MyInternationalizationString.uSwitch; } else if (device.DfunctionType == DeviceFunctionType.A插座) { typeInfo.BeloneTextId = R.MyInternationalizationString.uSocket1; } else if (device.DfunctionType == DeviceFunctionType.A灯光) { typeInfo.BeloneTextId = R.MyInternationalizationString.uLight; } else { //继电器 typeInfo.BeloneTextId = R.MyInternationalizationString.uDeviceBelongId2300; } if (dic.ContainsKey(typeInfo.BeloneTextId) == false) { dic[typeInfo.BeloneTextId] = new List(); } } else { if (dic.ContainsKey(typeInfo.BeloneTextId) == false) { dic[typeInfo.BeloneTextId] = new List(); } } dic[typeInfo.BeloneTextId].Add(device); } return dic; } #endregion #region ■ 删除分享___________________________ /// /// 删除分享 /// private void DeleteShardData() { //选择的设备 var listDevice = new List(); foreach (var device in dicSelectDevice.Values) { listDevice.Add(device); } //选择的场景 var listScene = new List(); foreach (var scene in dicSelectScene.Values) { listScene.Add(scene); } //确认删除选择的共享场景和功能? this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteShardContentMsg), () => { HdlThreadLogic.Current.RunThread(async () => { //上传文件 var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.lookRoom, listDevice, listScene); if (result == true) { HdlThreadLogic.Current.RunMain(() => { //重新初始化界面 this.InitMiddleFrame(); }); } }); }); } #endregion #region ■ 一般方法___________________________ /// /// 获取分享的设备 /// /// private List GetShardListDevice() { //获取这个房间里面的分享设备 var listDevice = new List(); foreach (var deviceFile in this.lookRoom.DeviceUIFilePathList) { if (memberShardInfo.dicAllShardKeys.ContainsKey(deviceFile) == true) { var strArry = deviceFile.Split('_'); if (strArry.Length < 3) { continue; } //从分享文件中序列化回来 var deviceData = HdlShardLogic.Current.GetShardFileContent(deviceFile); var device = ZigBee.Device.CommonDevice.CommonDeviceByByteString(strArry[1], System.Text.Encoding.UTF8.GetString(deviceData)); if (device != null) { listDevice.Add(device); } } } return listDevice; } #endregion } }