HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedMainForm.cs
@@ -9,7 +9,7 @@
    /// <summary>
    /// 查看已配置共享内容的主界面
    /// </summary>
    public class SearchConfigureSharedMainForm : UserCenterCommonForm
    public class SearchConfigureSharedMainForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
@@ -57,313 +57,320 @@
            base.SetTitleText(i_room.Name);
            //初始化中部信息
            this.InitMiddleFrame();
            //this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            bodyFrameLayout.RemoveAll();
        ///// <summary>
        ///// 初始化中部信息
        ///// </summary>
        //private void InitMiddleFrame()
        //{
        //    //清空bodyFrame
        //    this.ClearBodyFrame();
            //初始化Tab控件
            var frame = this.InitTabControl();
        //    //初始化Tab控件
        //    var frame = this.InitTabControl();
            this.listDeviceView = new VerticalScrolViewLayout();
            listDeviceView.Y = frame.Bottom;
            listDeviceView.Height = bodyFrameLayout.Height - frame.Bottom;
            listDeviceView.Visible = this.TabSelectIndex == 1;
            bodyFrameLayout.AddChidren(listDeviceView);
        //    this.listDeviceView = new VerticalScrolViewLayout();
        //    listDeviceView.Y = frame.Bottom;
        //    listDeviceView.Height = bodyFrameLayout.Height - frame.Bottom;
        //    listDeviceView.Visible = this.TabSelectIndex == 1;
        //    bodyFrameLayout.AddChidren(listDeviceView);
            this.listSceneView = new VerticalScrolViewLayout();
            listSceneView.Y = frame.Bottom;
            listSceneView.Height = bodyFrameLayout.Height - frame.Bottom;
            listSceneView.Visible = this.TabSelectIndex == 2;
            bodyFrameLayout.AddChidren(listSceneView);
        //    this.listSceneView = new VerticalScrolViewLayout();
        //    listSceneView.Y = frame.Bottom;
        //    listSceneView.Height = bodyFrameLayout.Height - frame.Bottom;
        //    listSceneView.Visible = this.TabSelectIndex == 2;
        //    bodyFrameLayout.AddChidren(listSceneView);
            new System.Threading.Thread(() =>
            {
                //初始化功能Tab列表
                this.InitFunctionTabList();
                //初始化场景Tab列表
                this.InitSceneTabList();
            })
            { IsBackground = true }.Start();
        }
        //    new System.Threading.Thread(() =>
        //    {
        //        //初始化功能Tab列表
        //        this.InitFunctionTabList();
        //        //初始化场景Tab列表
        //        this.InitSceneTabList();
        //    })
        //    { IsBackground = true }.Start();
        //}
        #endregion
        #region ■ 初始化Tab控件______________________
        //#region ■ 初始化Tab控件______________________
        /// <summary>
        /// 初始化Tab控件
        /// </summary>
        /// <returns></returns>
        private FrameLayout InitTabControl()
        {
            //Tab切换控件
            var frameSwich = new FrameLayout();
            frameSwich.Height = Application.GetRealHeight(150);
            frameSwich.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
            bodyFrameLayout.AddChidren(frameSwich);
        ///// <summary>
        ///// 初始化Tab控件
        ///// </summary>
        ///// <returns></returns>
        //private FrameLayout InitTabControl()
        //{
        //    //Tab切换控件
        //    var frameSwich = new FrameLayout();
        //    frameSwich.Height = Application.GetRealHeight(150);
        //    frameSwich.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
        //    bodyFrameLayout.AddChidren(frameSwich);
            //功能
            var btnFunction = new ViewNormalControl(frameSwich.Width / 2, Application.GetRealHeight(100));
            btnFunction.Gravity = Gravity.CenterVertical;
            btnFunction.TextID = R.MyInternationalizationString.Function;
            btnFunction.TextAlignment = TextAlignment.Center;
            btnFunction.TextColor = UserCenterColor.Current.SelectTextColor;
            btnFunction.TextAlignment = TextAlignment.Center;
            frameSwich.AddChidren(btnFunction);
        //    //功能
        //    var btnFunction = new NormalViewControl(frameSwich.Width / 2, Application.GetRealHeight(100));
        //    btnFunction.Gravity = Gravity.CenterVertical;
        //    btnFunction.TextID = R.MyInternationalizationString.Function;
        //    btnFunction.TextAlignment = TextAlignment.Center;
        //    btnFunction.TextColor = UserCenterColor.Current.SelectTextColor;
        //    btnFunction.TextAlignment = TextAlignment.Center;
        //    frameSwich.AddChidren(btnFunction);
            //场景
            var btnScene = new ViewNormalControl(frameSwich.Width / 2, Application.GetRealHeight(100));
            btnScene.Gravity = Gravity.CenterVertical;
            btnScene.X = frameSwich.Width / 2;
            btnScene.TextID = R.MyInternationalizationString.uScence;
            btnScene.TextAlignment = TextAlignment.Center;
            frameSwich.AddChidren(btnScene);
        //    //场景
        //    var btnScene = new NormalViewControl(frameSwich.Width / 2, Application.GetRealHeight(100));
        //    btnScene.Gravity = Gravity.CenterVertical;
        //    btnScene.X = frameSwich.Width / 2;
        //    btnScene.TextID = R.MyInternationalizationString.uScence;
        //    btnScene.TextAlignment = TextAlignment.Center;
        //    frameSwich.AddChidren(btnScene);
            //线
            var btnLine = new ProgressLine();
            btnLine.Gravity = Gravity.BottomLeft;
            frameSwich.AddChidren(btnLine);
            btnLine.SetValue(50, true);
        //    //线
        //    var btnLine = new ProgressLine();
        //    btnLine.Gravity = Gravity.BottomLeft;
        //    frameSwich.AddChidren(btnLine);
        //    btnLine.SetValue(50, true);
            if (this.TabSelectIndex == 2)
            {
                btnScene.TextColor = UserCenterColor.Current.SelectTextColor;
                btnFunction.TextColor = Common.ZigbeeColor.Current.TextColor;
                btnLine.SetValue(50, false);
            }
        //    if (this.TabSelectIndex == 2)
        //    {
        //        btnScene.TextColor = UserCenterColor.Current.SelectTextColor;
        //        btnFunction.TextColor = Common.ZigbeeColor.Current.TextColor;
        //        btnLine.SetValue(50, false);
        //    }
            //功能Tab
            btnFunction.MouseUpEventHandler += (sender, e) =>
            {
                if (this.TabSelectIndex == 1)
                {
                    return;
                }
                btnScene.TextColor = Common.ZigbeeColor.Current.TextColor;
                btnFunction.TextColor = UserCenterColor.Current.SelectTextColor;
                btnLine.SetValue(50);
                this.TabSelectIndex = 1;
        //    //功能Tab
        //    btnFunction.MouseUpEventHandler += (sender, e) =>
        //    {
        //        if (this.TabSelectIndex == 1)
        //        {
        //            return;
        //        }
        //        btnScene.TextColor = Common.ZigbeeColor.Current.TextColor;
        //        btnFunction.TextColor = UserCenterColor.Current.SelectTextColor;
        //        btnLine.SetValue(50);
        //        this.TabSelectIndex = 1;
                //隐藏场景列表控件,显示设备列表控件
                this.listSceneView.Visible = false;
                this.listDeviceView.Visible = true;
            };
        //        //隐藏场景列表控件,显示设备列表控件
        //        this.listSceneView.Visible = false;
        //        this.listDeviceView.Visible = true;
        //    };
            //场景Tab
            btnScene.MouseUpEventHandler += (sender, e) =>
            {
                if (this.TabSelectIndex == 2)
                {
                    return;
                }
                btnScene.TextColor = UserCenterColor.Current.SelectTextColor;
                btnFunction.TextColor = Common.ZigbeeColor.Current.TextColor;
                btnLine.SetValue(50, false);
                this.TabSelectIndex = 2;
        //    //场景Tab
        //    btnScene.MouseUpEventHandler += (sender, e) =>
        //    {
        //        if (this.TabSelectIndex == 2)
        //        {
        //            return;
        //        }
        //        btnScene.TextColor = UserCenterColor.Current.SelectTextColor;
        //        btnFunction.TextColor = Common.ZigbeeColor.Current.TextColor;
        //        btnLine.SetValue(50, false);
        //        this.TabSelectIndex = 2;
                //隐藏设备列表控件,显示场景列表控件
                this.listDeviceView.Visible = false;
                this.listSceneView.Visible = true;
            };
        //        //隐藏设备列表控件,显示场景列表控件
        //        this.listDeviceView.Visible = false;
        //        this.listSceneView.Visible = true;
        //    };
            return frameSwich;
        }
        //    return frameSwich;
        //}
        #endregion
        //#endregion
        #region ■ 显示功能Tab列表____________________
        //#region ■ 显示功能Tab列表____________________
        /// <summary>
        /// 初始化功能Tab列表
        /// </summary>
        private void InitFunctionTabList()
        {
            //获取分享的设备
            var listDevice = this.GetShardListDevice();
        ///// <summary>
        ///// 初始化功能Tab列表
        ///// </summary>
        //private void InitFunctionTabList()
        //{
        //    //获取分享的设备
        //    var listDevice = this.GetShardListDevice();
            foreach (var device in listDevice)
            {
                Application.RunOnMainThread(() =>
                {
                    //添加设备的明细行
                    this.AddDeviceDetailRow(device);
                });
            }
        }
        //    foreach (var device in listDevice)
        //    {
        //        Application.RunOnMainThread(() =>
        //        {
        //            if (this.Parent != null)
        //            {
        //                //添加设备的明细行
        //                this.AddDeviceDetailRow(device);
        //            }
        //        });
        //    }
        //}
        /// <summary>
        /// 添加设备的明细行
        /// </summary>
        /// <param name="device">设备对象</param>
        private void AddDeviceDetailRow(CommonDevice device)
        {
            var row = new StatuRowLayout(listDeviceView);
        ///// <summary>
        ///// 添加设备的明细行
        ///// </summary>
        ///// <param name="device">设备对象</param>
        //private void AddDeviceDetailRow(CommonDevice device)
        //{
        //    var row = new StatuRowLayout(listDeviceView);
            //图片
            var btnIcon = new RowLeftIconView();
            Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
            row.AddChidren(btnIcon, ChidrenBindMode.NotBind);
        //    //图片
        //    var btnIcon = new RowLeftIconView();
        //    Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
        //    row.AddChidren(btnIcon, ChidrenBindMode.NotBind);
            //设备类型的翻译名字
            var btnName = new RowCenterView();
            btnName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
            row.AddChidren(btnName, ChidrenBindMode.NotBind);
        //    //设备类型的翻译名字
        //    var btnName = new RowCenterView();
        //    btnName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
        //    row.AddChidren(btnName, ChidrenBindMode.NotBind);
            //移除
            var btnDelete = new RowDeleteButton();
            btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
            row.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            {
                //确定移除选中的设备?
                string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveSelectDeviceMsg);
                this.ShowConfirmMsg(msg, "DeleteShardDevice", row, device);
            };
        }
        //    //移除
        //    var btnDelete = new RowDeleteButton();
        //    btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
        //    row.AddRightView(btnDelete);
        //    btnDelete.MouseUpEventHandler += (sender, e) =>
        //    {
        //        //确定移除选中的设备?
        //        string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveSelectDeviceMsg);
        //        this.ShowConfirmMsg(msg, "DeleteShardDevice", row, device);
        //    };
        //}
        /// <summary>
        /// 删除共享设备
        /// </summary>
        /// <param name="row"></param>
        /// <param name="device"></param>
        public async void DeleteShardDevice(StatuRowLayout row, CommonDevice device)
        {
            var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.room, new List<CommonDevice>() { device }, new List<Common.SceneUI>());
            if (result == true)
            {
                Application.RunOnMainThread(() =>
                {
                    row.RemoveFromParent();
                    if (this.listDeviceView.ChildrenCount == 0 && this.listSceneView.ChildrenCount == 0)
                    {
                        //什么都没有了,则关闭界面
                        this.CloseForm();
                    }
                });
            }
        }
        ///// <summary>
        ///// 删除共享设备
        ///// </summary>
        ///// <param name="row"></param>
        ///// <param name="device"></param>
        //public async void DeleteShardDevice(StatuRowLayout row, CommonDevice device)
        //{
        //    var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.room, new List<CommonDevice>() { device }, new List<Common.SceneUI>());
        //    if (result == true)
        //    {
        //        Application.RunOnMainThread(() =>
        //        {
        //            row?.RemoveFromParent();
        //            if (this.listDeviceView != null && this.listDeviceView.ChildrenCount == 0 && this.listSceneView.ChildrenCount == 0)
        //            {
        //                //什么都没有了,则关闭界面
        //                this.CloseForm();
        //            }
        //        });
        //    }
        //}
        #endregion
        //#endregion
        #region ■ 显示场景Tab列表____________________
        //#region ■ 显示场景Tab列表____________________
        /// <summary>
        /// 初始化场景Tab列表
        /// </summary>
        private void InitSceneTabList()
        {
            foreach (var sceneUi in this.room.SceneUIList)
            {
                if (sceneUi == null || memberShardInfo.dicAllMemberShard[this.room.FileName].Contains(sceneUi.FileName) == false)
                {
                    //异常,或者不存在,则不显示
                    continue;
                }
                Application.RunOnMainThread(() =>
                {
                    //添加场景行
                    this.AddSceneDetailRow(sceneUi);
                });
            }
        }
        ///// <summary>
        ///// 初始化场景Tab列表
        ///// </summary>
        //private void InitSceneTabList()
        //{
        //    foreach (var sceneUi in this.room.SceneUIList)
        //    {
        //        if (sceneUi == null || memberShardInfo.dicAllMemberShard[this.room.FileName].Contains(sceneUi.FileName) == false)
        //        {
        //            //异常,或者不存在,则不显示
        //            continue;
        //        }
        //        Application.RunOnMainThread(() =>
        //        {
        //            if (this.Parent != null)
        //            {
        //                //添加场景行
        //                this.AddSceneDetailRow(sceneUi);
        //            }
        //        });
        //    }
        //}
        /// <summary>
        /// 添加场景的明细行
        /// </summary>
        /// <param name="sceneUI">场景对象</param>
        private void AddSceneDetailRow(Common.SceneUI sceneUI)
        {
            var sceneRow = new SceneViewRow(this.listSceneView, sceneUI);
        ///// <summary>
        ///// 添加场景的明细行
        ///// </summary>
        ///// <param name="sceneUI">场景对象</param>
        //private void AddSceneDetailRow(Common.SceneUI sceneUI)
        //{
        //    var sceneRow = new SceneViewRow(this.listSceneView, sceneUI);
            //移除
            var btnDelete = new RowDeleteButton();
            btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
            sceneRow.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            {
                //确定移除选中的场景?
                string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveSelectSceneMsg);
                this.ShowConfirmMsg(msg, "DeleteShardScene", sceneRow, sceneUI);
            };
        }
        //    //移除
        //    var btnDelete = new RowDeleteButton();
        //    btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
        //    sceneRow.AddRightView(btnDelete);
        //    btnDelete.MouseUpEventHandler += (sender, e) =>
        //    {
        //        //确定移除选中的场景?
        //        string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveSelectSceneMsg);
        //        this.ShowConfirmMsg(msg, "DeleteShardScene", sceneRow, sceneUI);
        //    };
        //}
        /// <summary>
        /// 删除共享场景
        /// </summary>
        /// <param name="row"></param>
        /// <param name="sceneUI"></param>
        public async void DeleteShardScene(SceneViewRow row, Common.SceneUI sceneUI)
        {
            var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.room, new List<CommonDevice>(), new List<Common.SceneUI>() { sceneUI });
            if (result == true)
            {
                Application.RunOnMainThread(() =>
                {
                    row.RemoveFromParent();
                    if (this.listDeviceView.ChildrenCount == 0 && this.listSceneView.ChildrenCount == 0)
                    {
                        //什么都没有了,则关闭界面
                        this.CloseForm();
                    }
                });
            }
        }
        ///// <summary>
        ///// 删除共享场景
        ///// </summary>
        ///// <param name="row"></param>
        ///// <param name="sceneUI"></param>
        //public async void DeleteShardScene(SceneViewRow row, Common.SceneUI sceneUI)
        //{
        //    var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.room, new List<CommonDevice>(), new List<Common.SceneUI>() { sceneUI });
        //    if (result == true)
        //    {
        //        Application.RunOnMainThread(() =>
        //        {
        //            row?.RemoveFromParent();
        //            if (this.listDeviceView != null && this.listDeviceView.ChildrenCount == 0 && this.listSceneView.ChildrenCount == 0)
        //            {
        //                //什么都没有了,则关闭界面
        //                this.CloseForm();
        //            }
        //        });
        //    }
        //}
        #endregion
        //#endregion
        #region ■ 获取可以分享的设备_________________
        //#region ■ 获取可以分享的设备_________________
        /// <summary>
        /// 获取分享的设备
        /// </summary>
        /// <returns></returns>
        private List<CommonDevice> GetShardListDevice()
        {
            //获取这个房间里面的分享设备的路径
            var listDeviceFile = new List<string>();
            foreach (var ui in this.room.DeviceUIList)
            {
                if (ui.CommonDevice != null && memberShardInfo.dicAllMemberShard[this.room.FileName].Contains(ui.CommonDevice.FilePath) == true)
                {
                    listDeviceFile.Add(ui.CommonDevice.FilePath);
                }
            }
        ///// <summary>
        ///// 获取分享的设备
        ///// </summary>
        ///// <returns></returns>
        //private List<CommonDevice> GetShardListDevice()
        //{
        //    //获取这个房间里面的分享设备的路径
        //    var listDeviceFile = new List<string>();
        //    foreach (var ui in this.room.DeviceUIList)
        //    {
        //        if (ui.CommonDevice != null && memberShardInfo.dicAllMemberShard[this.room.FileName].Contains(ui.CommonDevice.FilePath) == true)
        //        {
        //            listDeviceFile.Add(ui.CommonDevice.FilePath);
        //        }
        //    }
            var listFile = HdlShardLogic.Current.GetLocalAllShardFile();
            var listDevice = new List<CommonDevice>();
            foreach (string file in listFile)
            {
                //如果不是设备文件,或者这个房间里面没有这个设备
                if (file.StartsWith(Common.LocalDevice.deviceFirstName) == false || listDeviceFile.Contains(file) == false)
                {
                    continue;
                }
                var strArry = file.Split('_');
                if (strArry.Length < 3)
                {
                    continue;
                }
                //从分享文件中序列化回来
                var deviceData = HdlShardLogic.Current.GetShardFileContent(file);
                var device = ZigBee.Device.CommonDevice.CommonDeviceByByteString(strArry[1], System.Text.Encoding.UTF8.GetString(deviceData));
                if (device != null)
                {
                    listDevice.Add(device);
                }
            }
            return listDevice;
        }
        //    var listFile = HdlShardLogic.Current.GetLocalAllShardFile();
        //    var listDevice = new List<CommonDevice>();
        //    foreach (string file in listFile)
        //    {
        //        //如果不是设备文件,或者这个房间里面没有这个设备
        //        if (file.StartsWith(Common.LocalDevice.deviceFirstName) == false || listDeviceFile.Contains(file) == false)
        //        {
        //            continue;
        //        }
        //        var strArry = file.Split('_');
        //        if (strArry.Length < 3)
        //        {
        //            continue;
        //        }
        //        //从分享文件中序列化回来
        //        var deviceData = HdlShardLogic.Current.GetShardFileContent(file);
        //        var device = ZigBee.Device.CommonDevice.CommonDeviceByByteString(strArry[1], System.Text.Encoding.UTF8.GetString(deviceData));
        //        if (device != null)
        //        {
        //            listDevice.Add(device);
        //        }
        //    }
        //    return listDevice;
        //}
        #endregion
        //#endregion
        #region ■ 一般方法___________________________
        //#region ■ 一般方法___________________________
        #endregion
        //#endregion
    }
}