wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
HDL_ON/UI/UI2/3-Intelligence/IntelligencePage.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
namespace HDL_ON.UI
{
    public partial class IntelligencePage : FrameLayout
    {
@@ -12,17 +14,21 @@
        /// 场景/自动化分页区域
        /// </summary>
        PageLayout contentPageView;
        Button btnAutomationTitle;
        #region 场景区域
        FrameLayout scenePageView;
        /// <summary>
        /// 场景内容显示区域
        /// </summary>
        FrameLayout floorChangeView;
        #region 场景底部切换显示区域
        /// <summary>
        /// 场景区域,顶部区域
        /// <summary>
        /// 楼层房间选择的下拉对象
        /// </summary>
        FrameLayout sceneTopView;
        FloorRoomSelectPopupView floorRoomSelectView = null;
        Button btnSceneTilte;
        #region 场景底部切换显示区域
        FrameLayout topView;
        /// <summary>
        /// 楼层选择下拉图标
        /// </summary>
@@ -42,7 +48,12 @@
        /// </summary>
        VerticalScrolViewLayout sceneFunctionView;
        #endregion
        #region 自动化区域
        /// <summary>
        /// 自动化内容显示区域
        /// </summary>
        FrameLayout automationPage;
        #endregion
        public IntelligencePage()
        {
            bodyView = this;
@@ -50,44 +61,68 @@
        public void LoadPage()
        {
            MainPage.CurPageIndex = 2;
            bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
            #region top
            FrameLayout topView = new FrameLayout()
            topView = new FrameLayout()
            {
                Height = Application.GetRealHeight(64),
                BackgroundColor = CSS_Color.TopViewColor,
            };
            bodyView.AddChidren(topView);
            Button btnSceneTilte = new Button()
            //不是A网关或者是成员 只允许添加场景隐藏自动化
            var HideAutoPage = DB_ResidenceData.Instance.CurrentRegion.isOtherShare;
            //判断是否需要隐藏自动化
            if (HideAutoPage)
            {
                Y = Application.GetRealHeight(30),
                Width = Application.GetRealWidth(170),
                Height = Application.GetRealHeight(25),
                TextAlignment = TextAlignment.CenterRight,
                TextSize = CSS_FontSize.HeadlineFontSize,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextID = StringId.Scenes,
                IsSelected = true
            };
            topView.AddChidren(btnSceneTilte);
            Button btnAutomationTitle = new Button()
                btnSceneTilte = new Button()
                {
                    Y = Application.GetRealHeight(30),
                    //Width = Application.GetRealWidth(170),
                    Height = Application.GetRealHeight(25),
                    TextAlignment = TextAlignment.Center,
                    TextSize = CSS_FontSize.HeadlineFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    SelectedTextColor = CSS_Color.MainColor,
                    TextID = StringId.Scenes,
                    IsSelected = true
                };
                topView.AddChidren(btnSceneTilte);
                btnAutomationTitle = new Button();
            }
            else
            {
                X = Application.GetRealWidth(209),
                Y = Application.GetRealHeight(30),
                Width = Application.GetRealWidth(170),
                Height = Application.GetRealHeight(25),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextID = StringId.Automation,
            };
            topView.AddChidren(btnAutomationTitle);
            btnAddIcon = new Button()
                btnSceneTilte = new Button()
                {
                    Y = Application.GetRealHeight(30),
                    Width = Application.GetRealWidth(170),
                    Height = Application.GetRealHeight(25),
                    TextAlignment = TextAlignment.CenterRight,
                    TextSize = CSS_FontSize.HeadlineFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    SelectedTextColor = CSS_Color.MainColor,
                    TextID = StringId.Scenes,
                    IsSelected = true
                };
                topView.AddChidren(btnSceneTilte);
                btnAutomationTitle = new Button()
                {
                    X = Application.GetRealWidth(209),
                    Y = Application.GetRealHeight(30),
                    Width = Application.GetRealWidth(170),
                    Height = Application.GetRealHeight(25),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    SelectedTextColor = CSS_Color.MainColor,
                    TextID = StringId.Automation,
                };
                topView.AddChidren(btnAutomationTitle);
            }
            var btnAddIconBg = new Button()
            {
                X = Application.GetRealWidth(337),
                Y = Application.GetRealHeight(29),
@@ -95,7 +130,20 @@
                Height = Application.GetMinRealAverage(28),
                UnSelectedImagePath = "Public/AddIcon.png",
            };
            topView.AddChidren(btnAddIcon);
            //if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
            {
                topView.AddChidren(btnAddIconBg);
            }
            btnAddIcon = new Button()
            {
                X = Application.GetRealWidth(337-20),
                Width = Application.GetMinRealAverage(28+30),
                Height = Application.GetMinRealAverage(28+29),
            };
            //if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
            {
                topView.AddChidren(btnAddIcon);
            }
            #endregion
            contentPageView = new PageLayout()
@@ -108,9 +156,15 @@
            bodyView.AddChidren(contentPageView);
            LoadScenePageView();
            //LoadFunctionPageView();
            //判断是否需要隐藏自动化
            if (!HideAutoPage)
            {
                LoadAutomationPageView();
            }
            LoadEventList();
        }
        #region 场景部分
        /// <summary>
        /// 加载场景列表界面
        /// </summary>
@@ -123,18 +177,10 @@
            /// </summary>
            floorChangeView = new FrameLayout()
            {
                Height = Application.GetRealHeight(52),
                Height = Application.GetRealHeight(53),
            };
            scenePageView.AddChidren(floorChangeView);
            #region 场景底部切换显示区域
            /// <summary>
            /// 场景区域,顶部区域
            /// </summary>
            sceneTopView = new FrameLayout()
            {
                Height = Application.GetRealHeight(53),
            };
            floorChangeView.AddChidren(sceneTopView);
            /// <summary>
            /// 楼层选择下拉图标
            /// </summary>
@@ -143,7 +189,7 @@
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(18),
               Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Public/DownIcon.png",
            };
            floorChangeView.AddChidren(btnFloorDownIcon);
@@ -153,52 +199,85 @@
            btnFloor = new Button()
            {
                X = btnFloorDownIcon.Right,
                Y = Application.GetRealHeight(18),
               Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(200),
                Height = Application.GetMinRealAverage(16),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextAlignment = TextAlignment.CenterLeft,
                Text = DB_ResidenceData.residenceData.CurFoor,
                Text = DB_ResidenceData.Instance.CurFloor.roomName,
            };
            floorChangeView.AddChidren(btnFloor);
            floorChangeView.AddChidren(btnFloor);
            string nowSelectId = null;
            btnFloor.MouseUpEventHandler += (sender, e) =>
            {
                if (this.floorRoomSelectView == null)
                {
                    //先初始化
                    this.floorRoomSelectView = new FloorRoomSelectPopupView();
                }
                //显示下拉列表
                this.floorRoomSelectView.ShowSceneView(btnFloor, (selectId, listScene) =>
                {
                    nowSelectId = selectId;
                    //重新刷新场景列表
                    this.LoadSceneFunctionControlZone(listScene);
                }, nowSelectId);
            };
            #endregion
            sceneFunctionView = new VerticalScrolViewLayout() {
                Y = floorChangeView.Bottom,
            sceneFunctionView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(53),
                Height = Application.GetRealHeight(667 - 64 - 49 - 52 + 30),
            };
            scenePageView.AddChidren(sceneFunctionView);
            LoadSceneFunctionControlZone();
            LoadSceneFunctionControlZone(null);
        }
        /// <summary>
        /// 加载场景功能显示区域
        /// </summary>
        void LoadSceneFunctionControlZone()
        void LoadSceneFunctionControlZone(List<Scene> listScene)
        {
            //topView.AddChidren(btnAddIcon);
            sceneFunctionView.RemoveAll();
            var rowView = new FrameLayout();
            try
            {
                int index = 0;
                foreach (var function in DB_ResidenceData.functionList.scenes)
                //获取能够显示的场景
                if (listScene == null)
                {
                    //初始值
                    if (this.floorRoomSelectView == null)
                    {
                        //先初始化
                        this.floorRoomSelectView = new FloorRoomSelectPopupView();
                    }
                    listScene = this.floorRoomSelectView.GetCanShowListScene();
                }
                foreach (var scene in listScene)
                {
                    if (function.roomIdList.Count == 0)//如何在房间已经移除了这个功能,则收藏界面也不会再显示
                    {
                        function.collection = false;
                        continue;
                    }
                    //if (scene.roomIds.Count == 0)//如何在房间已经移除了这个功能,则收藏界面也不会再显示
                    //{
                    //    scene.collect = false;
                    //    continue;
                    //}
                    if (index % 2 == 0)
                    {
                        sceneFunctionView.AddChidren(new Button() { Height = Application.GetRealHeight(7) });
                        rowView = new FrameLayout()
                        {
                            Height = Application.GetRealWidth(122),
                        };
                        sceneFunctionView.AddChidren(rowView);
                        sceneFunctionView.AddChidren(new Button() { Height = Application.GetRealHeight(7) });
                        sceneFunctionView.AddChidren(new Button()
                        {
                            Height = Application.GetRealHeight(7 + 7),
                        });
                    }
                    var functionView_X = Application.GetRealWidth((16 + 164) * (index % 2) + 16);
@@ -207,12 +286,14 @@
                        X = functionView_X,
                        Width = Application.GetRealWidth(164),
                        Height = Application.GetRealWidth(122),
                        Tag = function.sid,
                        BackgroundImagePath = (function as Scene).ImagePath,
                        Tag = scene.sid,
                        //BackgroundImagePath = (scene as Scene).ImagePath,
                    };
                    rowView.AddChidren(functionView);
                    //2020-12-03 修改图片加载方法
                    ImageUtlis.Current.LoadLocalOrNetworkImages((scene as Scene).ImagePath, functionView);
                    LoadSceneFunctionDiv(functionView, function);
                    LoadSceneFunctionDiv(functionView, scene);
                    index++;
                }
@@ -254,7 +335,7 @@
        /// <summary>
        /// 加载场景控制卡片
        /// </summary>
        void LoadSceneFunctionDiv(FrameLayout view, Function function)
        void LoadSceneFunctionDiv(FrameLayout view, Scene scene)
        {
            try
            {
@@ -264,6 +345,19 @@
                };
                view.AddChidren(btnCoverd);
                Button btnShowDelay;
                btnShowDelay = new Button()
                {
                    X = Application.GetRealWidth(40),
                    Y = Application.GetRealWidth(4),
                    Height = Application.GetRealWidth(32),
                    Width = Application.GetRealWidth(100),
                    TextColor = CSS_Color.AuxiliaryColor1,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                };
                view.AddChidren(btnShowDelay);
                Button btnName;
                btnName = new Button()
                {
@@ -271,7 +365,7 @@
                    Y = Application.GetRealWidth(68),
                    Width = Application.GetRealWidth(150),
                    Height = Application.GetRealHeight(24),
                    Text = function.name,
                    Text = scene.name,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.MainBackgroundColor,
                    TextAlignment = TextAlignment.CenterLeft,
@@ -289,10 +383,9 @@
                    TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
                    TextAlignment = TextAlignment.CenterLeft,
                    SelectedTextColor = CSS_Color.MainBackgroundColor,
                    Text = function.GetRoomListName(),
                    Text = scene.GetRoomListName(),
                };
                view.AddChidren(btnZone);
                Button btnSettingIcon;
                btnSettingIcon = new Button()
@@ -303,7 +396,10 @@
                    Width = Application.GetRealWidth(32),
                    UnSelectedImagePath = "Public/FuncInfoSetIcon_white.png",
                };
                view.AddChidren(btnSettingIcon);
                if (scene.userId == UserInfo.Current.ID)
                {
                    view.AddChidren(btnSettingIcon);
                }
                Button btnCollection;
                btnCollection = new Button()
@@ -314,35 +410,101 @@
                    Height = Application.GetMinRealAverage(32),
                    UnSelectedImagePath = "Collection/CollectionWhiteIcon.png",
                    SelectedImagePath = "Collection/CollectionIcon.png",
                    IsSelected = function.collection,
                    IsSelected = scene.collect,
                };
                view.AddChidren(btnCollection);
                //2020-12-16 如果是成员隐藏收藏功能
                //if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
                //{
                //    view.AddChidren(btnCollection);
                //}
                btnCollection.MouseUpEventHandler = (sender, e) => {
                    function.collection = btnCollection.IsSelected = !btnCollection.IsSelected;
                    function.SaveFunctionData();
                    scene.collect = btnCollection.IsSelected = !btnCollection.IsSelected;
                    scene.CollectScene();
                };
                LoadEvent_ControlScene(btnCoverd,btnName,btnZone, function);
                LoadEvent_ControlScene(btnCoverd, btnName, btnZone, btnShowDelay, scene);
                btnSettingIcon.MouseUpEventHandler = (sender, e) => {
                    Action backAction = () => {
                        LoadSceneFunctionControlZone();
                        LoadSceneFunctionControlZone(null);
                    };
                    Action refreshAction = () => {
                        btnName.Text = function.name;
                        btnZone.Text = function.GetRoomListName();
                        view.BackgroundImagePath = (function as Scene).ImagePath;
                        btnName.Text = scene.name;
                        btnZone.Text = scene.GetRoomListName();
                        //2020-12-03 修改图片加载方法
                        ImageUtlis.Current.LoadLocalOrNetworkImages((scene as Scene).ImagePath, view);
                    };
                    var aep = new SceneEditPage(function as Scene, backAction);
                    var aep = new SceneEditPage(scene, backAction);
                    MainPage.BasePageView.AddChidren(aep);
                    aep.LoadPage(StringId.EditScene, refreshAction);
                    aep.LoadPage(refreshAction);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                //场景正在倒计时执行中
                scene.SceneCountDown(btnShowDelay);
                //if (scene.LastExecutionTime == "" || Convert.ToDouble(scene.LastExecutionTime) + Convert.ToDouble(scene.delay) < Convert.ToDouble(Utlis.GetTimestamp(false)))
                //{
                //    int time = 0;
                //    int.TryParse(Convert.ToInt32(
                //        Convert.ToDouble(scene.LastExecutionTime) + Convert.ToDouble(scene.delay) - Convert.ToDouble(Utlis.GetTimestamp(false))
                //        ).ToString(),out time);
                //    if (time > 0)
                //    {
                //        new System.Threading.Thread(() =>
                //        {
                //            //int time = Convert.ToInt32(scene.delay);
                //            if (time > 0)
                //            {
                //                while (time > 0)
                //                {
                //                    Application.RunOnMainThread(() =>
                //                    {
                //                        if (time / 60 > 1)
                //                        {
                //                            btnShowDelay.Text = (time / 60).ToString() + "min";
                //                        }
                //                        else
                //                        {
                //                            btnShowDelay.Text = (time--).ToString() + "s";
                //                        }
                //                    });
                //                    if (time / 60 > 1)
                //                    {
                //                        System.Threading.Thread.Sleep(time / 60 * 60000);
                //                    }
                //                    else
                //                    {
                //                        System.Threading.Thread.Sleep(1000);
                //                    }
                //                }
                //                Application.RunOnMainThread(() =>
                //                {
                //                    btnShowDelay.Text = "";
                //                });
                //            }
                //        })
                //        { IsBackground = true, Priority = System.Threading.ThreadPriority.BelowNormal }.Start();
                //    }
                //}
            }
            catch (Exception ex)
            {
                MainPage.Log("homepage LoadControlView error : " + ex.Message);
            }
        }
        #endregion
        #region 自动化部分
        /// <summary>
        /// 加载自动化列表界面
        /// </summary>
        void LoadAutomationPageView()
        {
            automationPage = new FrameLayout();
            contentPageView.AddChidren(automationPage);
            UI2.Intelligence.Automation.MainView.automationPage = automationPage;
            UI2.Intelligence.Automation.MainView.MainShow();
        }
        #endregion
    }
@@ -352,7 +514,65 @@
        void LoadEventList()
        {
            LoadEvent_SkipAddScenePage();
            LoadEvent_ShowedChange();
        }
        #region 顶部导航栏事件
        /// <summary>
        /// 显示界面切换
        /// </summary>
        void LoadEvent_ShowedChange()
        {
            contentPageView.PageChange = (sender, e) =>
            {
                if (contentPageView.PageIndex == 0)
                {
                    btnSceneTilte.IsSelected = true;
                    btnSceneTilte.TextSize = CSS_FontSize.HeadlineFontSize;
                    btnSceneTilte.IsBold = true;
                    btnAutomationTitle.IsSelected = false;
                    btnAutomationTitle.TextSize = CSS_FontSize.TextFontSize;
                    btnAutomationTitle.IsBold = false;
                }
                else
                {
                    btnAutomationTitle.IsSelected = true;
                    btnAutomationTitle.TextSize = CSS_FontSize.HeadlineFontSize;
                    btnAutomationTitle.IsBold = true;
                    btnSceneTilte.IsSelected = false;
                    btnSceneTilte.TextSize = CSS_FontSize.TextFontSize;
                    btnSceneTilte.IsBold = false;
                }
            };
            btnSceneTilte.MouseUpEventHandler = (sender, e) =>
            {
                if (btnSceneTilte.IsSelected)
                {
                    return;
                }
                btnSceneTilte.IsSelected = true;
                btnSceneTilte.TextSize = CSS_FontSize.HeadlineFontSize;
                btnAutomationTitle.IsSelected = false;
                btnAutomationTitle.TextSize = CSS_FontSize.TextFontSize;
                contentPageView.PageIndex = 0;
            };
            //逻辑点击事件
            btnAutomationTitle.MouseUpEventHandler = (sender, e) => {
                if (btnAutomationTitle.IsSelected)
                {
                    return;
                }
                btnAutomationTitle.IsSelected = true;
                btnAutomationTitle.TextSize = CSS_FontSize.HeadlineFontSize;
                btnSceneTilte.IsSelected = false;
                btnSceneTilte.TextSize = CSS_FontSize.TextFontSize;
                contentPageView.PageIndex = 1;
            };
        }
        #endregion
        /// <summary>
        /// 跳转至添加场景的界面
        /// </summary>
@@ -360,13 +580,34 @@
        {
            btnAddIcon.MouseUpEventHandler = (sender, e) =>
            {
                Action action = () => {
                    LoadSceneFunctionControlZone();
                };
                var aep = new NewSceneMenuListPage(action);
                MainPage.BasePageView.AddChidren(aep);
                aep.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                if (!btnAutomationTitle.IsSelected)
                {
                    //如果是成员
                    if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
                    {
                        //如果没有场景权限
                        if (!DB_ResidenceData.Instance.CurrentRegion.isAllowCreateScene)
                        {
                            //提示没有场景的创建权限
                            Utlis.ShowTip(Language.StringByID(StringId.PermissionDenied));
                            return;
                        }
                    }
                    Action action = () =>
                    {
                        LoadSceneFunctionControlZone(null);
                    };
                    var aep = new NewSceneMenuListPage(action);
                    MainPage.BasePageView.AddChidren(aep);
                    aep.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                }
                else
                {
                    //跳转到逻辑界面
                    UI2.Intelligence.Automation.MainView.SkipAddLogicPage();
                }
            };
        }
@@ -374,19 +615,30 @@
        /// <summary>
        /// 加载场景控制事件
        /// </summary>
        void LoadEvent_ControlScene(Button btnCoverd, Button btnName, Button btnZone, Function function)
        void LoadEvent_ControlScene(Button btnCoverd, Button btnName, Button btnZone,Button btnShowDelay, Scene scene)
        {
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                string msg = function.name + Language.StringByID(StringId.AlreadyOpened);
                //场景正在倒计时执行中,不允许再点击
                if (scene.LastExecutionTime == "" || Convert.ToDouble(scene.LastExecutionTime) + Convert.ToDouble(scene.delay) < Convert.ToDouble(Utlis.GetTimestamp(false)))
                {
                    scene.LastExecutionTime = Utlis.GetTimestamp(false);
                }
                else
                {
                    return;
                }
                string msg = scene.name + Language.StringByID(StringId.AlreadyOpened);
                new PublicAssmebly().TipMsgAutoClose(msg, true);
                Control.Send(function);
                Control.Ins.ControlScene(scene);
                scene.SceneCountDown(btnShowDelay);
            };
            btnCoverd.MouseUpEventHandler = eventHandler;
            btnName.MouseUpEventHandler = eventHandler;
            btnZone.MouseUpEventHandler = eventHandler;
        }
    }
}