HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
ZigbeeApp/Shared/Phone/UserCenter/SharedContent/ConfigureNewSharedMainForm.cs
@@ -9,7 +9,7 @@
    /// <summary>
    /// 配置新共享内容的主界面
    /// </summary>
    public class ConfigureNewSharedMainForm : UserCenterCommonForm
    public class ConfigureNewSharedMainForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
@@ -58,288 +58,297 @@
            base.SetTitleText(this.room.Name);
            //分享
            var btnShard = new TopLayoutFinshView();
            btnShard.TextID = R.MyInternationalizationString.uShared;
            topFrameLayout.AddChidren(btnShard);
            btnShard.MouseUpEventHandler += (sender, e) =>
            {
                new System.Threading.Thread(() =>
                {
                    //确认分享
                    this.DoSaveSharedContent();
                })
                { IsBackground = true }.Start();
            };
            //var btnShard = new TopLayoutFinshView();
            //btnShard.TextID = R.MyInternationalizationString.uShared;
            //topFrameLayout.AddChidren(btnShard);
            //btnShard.MouseUpEventHandler += (sender, e) =>
            //{
            //    new System.Threading.Thread(() =>
            //    {
            //        //确认分享
            //        this.DoSaveSharedContent();
            //    })
            //    { IsBackground = true }.Start();
            //};
            //初始化中部信息
            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()
        {
            if (memberShardInfo.dicAllMemberShard.ContainsKey(this.room.FileName) == false)
            {
                memberShardInfo.dicAllMemberShard[this.room.FileName] = new HashSet<string>();
            }
            var listCheck = memberShardInfo.dicAllMemberShard[this.room.FileName];
        ///// <summary>
        ///// 初始化功能Tab列表
        ///// </summary>
        //private void InitFunctionTabList()
        //{
        //    if (memberShardInfo.dicAllMemberShard.ContainsKey(this.room.FileName) == false)
        //    {
        //        memberShardInfo.dicAllMemberShard[this.room.FileName] = new HashSet<string>();
        //    }
        //    var listCheck = memberShardInfo.dicAllMemberShard[this.room.FileName];
            foreach (var deviceUi in this.room.DeviceUIList)
            {
                var device = deviceUi.CommonDevice;
                if (device == null || listCheck.Contains(device.FilePath) == true)
                {
                    //异常,或者已经分享了的,不再显示
                    continue;
                }
                Application.RunOnMainThread(() =>
                {
                    //添加设备行
                    var deviceRow = new DeviceSelectRow(this.listDeviceView, device);
                    //不需要房间控件
                    deviceRow.RemoveRoomControl();
                });
            }
        }
        //    foreach (var deviceUi in this.room.DeviceUIList)
        //    {
        //        var device = deviceUi.CommonDevice;
        //        if (device == null || listCheck.Contains(device.FilePath) == true)
        //        {
        //            //异常,或者已经分享了的,不再显示
        //            continue;
        //        }
        //        Application.RunOnMainThread(() =>
        //        {
        //            if (this.listDeviceView != null)
        //            {
        //                //添加设备行
        //                var deviceRow = new DeviceSelectControl(device);
        //                this.listDeviceView.AddChidren(deviceRow);
        //                deviceRow.InitControl();
        //                //不需要房间控件
        //                deviceRow.RemoveRoomControl();
        //            }
        //        });
        //    }
        //}
        #endregion
        //#endregion
        #region ■ 显示场景Tab列表____________________
        //#region ■ 显示场景Tab列表____________________
        /// <summary>
        /// 初始化场景Tab列表
        /// </summary>
        private void InitSceneTabList()
        {
            if (memberShardInfo.dicAllMemberShard.ContainsKey(this.room.FileName) == false)
            {
                memberShardInfo.dicAllMemberShard[this.room.FileName] = new HashSet<string>();
            }
            var listCheck = memberShardInfo.dicAllMemberShard[this.room.FileName];
        ///// <summary>
        ///// 初始化场景Tab列表
        ///// </summary>
        //private void InitSceneTabList()
        //{
        //    if (memberShardInfo.dicAllMemberShard.ContainsKey(this.room.FileName) == false)
        //    {
        //        memberShardInfo.dicAllMemberShard[this.room.FileName] = new HashSet<string>();
        //    }
        //    var listCheck = memberShardInfo.dicAllMemberShard[this.room.FileName];
            foreach (var sceneUi in this.room.SceneUIList)
            {
                if (sceneUi == null || listCheck.Contains(sceneUi.FileName) == true)
                {
                    //异常,或者已经分享了的,不再显示
                    continue;
                }
                Application.RunOnMainThread(() =>
                {
                    //添加场景行
                    var sceneRow = new SceneSelectRow(this.listSceneView, sceneUi);
                });
            }
        }
        //    foreach (var sceneUi in this.room.SceneUIList)
        //    {
        //        if (sceneUi == null || listCheck.Contains(sceneUi.FileName) == true)
        //        {
        //            //异常,或者已经分享了的,不再显示
        //            continue;
        //        }
        //        Application.RunOnMainThread(() =>
        //        {
        //            if (this.listSceneView != null)
        //            {
        //                //添加场景行
        //                var sceneRow = new SceneSelectRow(this.listSceneView, sceneUi);
        //            }
        //        });
        //    }
        //}
        #endregion
        //#endregion
        #region ■ 获取选择的设备_____________________
        //#region ■ 获取选择的设备_____________________
        /// <summary>
        /// 获取选择的设备
        /// </summary>
        /// <param name="listCheck">重复检测</param>
        /// <returns></returns>
        private List<CommonDevice> GetSelectedDevice(HashSet<string> listCheck)
        {
            var listDevice = new List<CommonDevice>();
            for (int i = 0; i < listDeviceView.ChildrenCount; i++)
            {
                var myView = listDeviceView.GetChildren(i);
                var selectRow = (DeviceSelectRow)myView;
                if (selectRow.IsSelected == true && listCheck.Contains(selectRow.device.FilePath) == false)
                {
                    listCheck.Add(selectRow.device.FilePath);
                    listDevice.Add(selectRow.device);
                }
            }
            return listDevice;
        }
        ///// <summary>
        ///// 获取选择的设备
        ///// </summary>
        ///// <param name="listCheck">重复检测</param>
        ///// <returns></returns>
        //private List<CommonDevice> GetSelectedDevice(HashSet<string> listCheck)
        //{
        //    var listDevice = new List<CommonDevice>();
        //    for (int i = 0; i < listDeviceView.ChildrenCount; i++)
        //    {
        //        var myView = listDeviceView.GetChildren(i);
        //        var selectRow = (DeviceSelectControl)myView;
        //        if (selectRow.IsSelected == true && listCheck.Contains(selectRow.device.FilePath) == false)
        //        {
        //            listCheck.Add(selectRow.device.FilePath);
        //            listDevice.Add(selectRow.device);
        //        }
        //    }
        //    return listDevice;
        //}
        #endregion
        //#endregion
        #region ■ 获取选择的场景_____________________
        //#region ■ 获取选择的场景_____________________
        /// <summary>
        /// 获取选择的场景
        /// </summary>
        /// <param name="listCheck">重复检测</param>
        /// <returns></returns>
        private List<Common.SceneUI> GetSelectedSceneUI(HashSet<string> listCheck)
        {
            var listSceneUI = new List<Common.SceneUI>();
            for (int i = 0; i < listSceneView.ChildrenCount; i++)
            {
                var myView = listSceneView.GetChildren(i);
                var selectRow = (SceneSelectRow)myView;
                if (selectRow.IsSelected == true && listCheck.Contains(selectRow.sceneUI.Id.ToString()) == false)
                {
                    listCheck.Add(selectRow.sceneUI.Id.ToString());
                    listSceneUI.Add(selectRow.sceneUI);
                }
            }
            return listSceneUI;
        }
        ///// <summary>
        ///// 获取选择的场景
        ///// </summary>
        ///// <param name="listCheck">重复检测</param>
        ///// <returns></returns>
        //private List<Common.SceneUI> GetSelectedSceneUI(HashSet<string> listCheck)
        //{
        //    var listSceneUI = new List<Common.SceneUI>();
        //    for (int i = 0; i < listSceneView.ChildrenCount; i++)
        //    {
        //        var myView = listSceneView.GetChildren(i);
        //        var selectRow = (SceneSelectRow)myView;
        //        if (selectRow.IsSelected == true && listCheck.Contains(selectRow.sceneUI.Id.ToString()) == false)
        //        {
        //            listCheck.Add(selectRow.sceneUI.Id.ToString());
        //            listSceneUI.Add(selectRow.sceneUI);
        //        }
        //    }
        //    return listSceneUI;
        //}
        #endregion
        //#endregion
        #region ■ 确认分享___________________________
        //#region ■ 确认分享___________________________
        /// <summary>
        /// 确认分享
        /// </summary>
        private async void DoSaveSharedContent()
        {
            var listCheck = new HashSet<string>();
            //选择的设备
            var listSelectDevice = this.GetSelectedDevice(listCheck);
            //选择的场景
            var listSelectScene = this.GetSelectedSceneUI(listCheck);
            if (listSelectDevice.Count == 0 && listSelectScene.Count == 0)
            {
                //请选择目标后再执行分享操作
                string msg = Language.StringByID(R.MyInternationalizationString.uNotSelectDeviceBeforeSave);
                this.ShowErrorMsg(msg);
                return;
            }
            //执行上传分享内容
            var result = await HdlShardLogic.Current.DoUploadSharedContent(memberShardInfo, this.room, listSelectDevice, listSelectScene);
            if (result == true)
            {
                Application.RunOnMainThread(() =>
                {
                    //重新刷新界面
                    this.InitMiddleFrame();
                    //分享成功
                    string msg = Language.StringByID(R.MyInternationalizationString.uShardSuccess);
                    this.ShowTip(msg);
                });
            }
        }
        ///// <summary>
        ///// 确认分享
        ///// </summary>
        //private async void DoSaveSharedContent()
        //{
        //    var listCheck = new HashSet<string>();
        //    //选择的设备
        //    var listSelectDevice = this.GetSelectedDevice(listCheck);
        //    //选择的场景
        //    var listSelectScene = this.GetSelectedSceneUI(listCheck);
        //    if (listSelectDevice.Count == 0 && listSelectScene.Count == 0)
        //    {
        //        //请选择目标后再执行分享操作
        //        string msg = Language.StringByID(R.MyInternationalizationString.uNotSelectDeviceBeforeSave);
        //        this.ShowErrorMsg(msg);
        //        return;
        //    }
        //    //执行上传分享内容
        //    var result = await HdlShardLogic.Current.DoUploadSharedContent(memberShardInfo, this.room, listSelectDevice, listSelectScene);
        //    if (result == true)
        //    {
        //        Application.RunOnMainThread(() =>
        //        {
        //            //重新刷新界面
        //            this.InitMiddleFrame();
        //            //分享成功
        //            string msg = Language.StringByID(R.MyInternationalizationString.uShardSuccess);
        //            this.ShowMassage(msg);
        //        });
        //    }
        //}
        #endregion
        //#endregion
    }
}