JLChen
2021-11-30 efad979b6fae76fb37a4de7e94e6bac0a85cb72c
HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditFunctionPage.cs
@@ -56,14 +56,27 @@
        /// 被修改数据的功能列表,在需要保存的时候再保存数据
        /// </summary>
        List<Function> changeList = new List<Function>();
        /// <summary>
        /// 新增的房间绑定功能事件,用户确定生成房间之后,再将功能绑定到房间
        /// </summary>
        Action<List<Function>> newRoomAddFunction;
        #endregion
        /// <summary>
        /// 编辑现有房间的构造函数
        /// </summary>
        /// <param name="r"></param>
        public RoomEditFunctionPage(Room r)
        {
            bodyView = this;
            room = r;
        }
        public RoomEditFunctionPage(Room r, Action<List<Function>> action)
        {
            bodyView = this;
            room = r;
            newRoomAddFunction = action;
        }
        /// <summary>
        /// 加载界面
        /// </summary>
@@ -71,7 +84,6 @@
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.AddFunction)).LoadTopView();
            //new PublicAssmebly().LoadTopView(bodyView, Language.StringByID(StringId.AddFunction));
            #region 显示的功能类型切换区域
            showdFunctionTypeRow = new FrameLayout()
@@ -95,6 +107,10 @@
                IsBold = true
            };
            showdFunctionTypeRow.AddChidren(btnUnallocated);
            if(Language.CurrentLanguage != "Chinese")
            {
                btnUnallocated.Width = Application.GetRealWidth(130);
            }
            btnAllocated = new Button()
            {
@@ -141,13 +157,18 @@
                Y = showdFunctionTypeRow.Bottom,
                Height = Application.GetRealHeight(518 - 40 - 62),
                BackgroundColor = CSS_Color.BackgroundColor,
            };
            bodyView.AddChidren(functionListView);
            foreach (var function in DB_ResidenceData.functionList.GetAllFunction())
            foreach (var function in FunctionList.List.GetDeviceFunctionList())
            {
                function.roomIdList.Remove(null);
                if (function.roomIdList.Count > 0 )
                function.roomIds.Remove(null);
                if(MainPage.RoomNotSupportFunctionList.Contains(function.spk))
                {
                    continue;
                }
                if (function.roomIds.Count > 0 )
                {
                    allocatedList.Add(function);
                }
@@ -159,20 +180,29 @@
            LoadFunctionListRow(unallocatedList);
            var bottomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(591),
                Height = Application.GetRealHeight(76) + Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(bottomView);
            btnConfrim = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(582),
                Y = Application.GetRealHeight(603),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                Height = Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color.MainColor,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = StringId.Confirm,
                TextID = StringId.ConfirmAdd,
            };
            bodyView.AddChidren(btnConfrim);
@@ -188,15 +218,24 @@
            showdFunctionCount = 0;
            functionListView.RemoveAll();
            bool isFrist = true;
            foreach (var function in functions)
            {
                functionListView.AddChidren(new Button()
                if (isFrist)
                {
                    Gravity = Gravity.CenterHorizontal,
                    Width = Application.GetRealWidth(343),
                    Height = Application.GetRealWidth(1),
                    BackgroundColor = CSS_Color.DividingLineColor,
                });
                    isFrist = false;
                }
                else
                {
                    functionListView.AddChidren(new Button()
                    {
                        Gravity = Gravity.CenterHorizontal,
                        Width = Application.GetRealWidth(343),
                        Height = Application.GetRealWidth(1),
                        BackgroundColor = CSS_Color.DividingLineColor,
                    });
                }
                FrameLayout functionRow = new FrameLayout()
                {
@@ -213,71 +252,9 @@
                    Height = Application.GetMinRealAverage(28),
                };
                functionRow.AddChidren(btnFunctionIcon);
                switch (function.functionCategory)
                {
                    case FunctionCategory.Thermostat:
                        switch (function.functionType)
                        {
                            case FunctionType.AC:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/AC/AcThinIcon1.png";
                                break;
                            case FunctionType.FloorHeating:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/FloorHeating/FloorHeatingThinIcon.png";
                                break;
                        }
                        break;
                    case FunctionCategory.Curtain:
                        btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainThinIcon.png";
                        break;
                    case FunctionCategory.Light:
                        btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Light/LightThinIcon.png";
                        break;
                    case FunctionCategory.SwitchDevice:
                        switch (function.functionType)
                        {
                            case FunctionType.Socket:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Socket/SocketThinIcon.png";
                                break;
                        }
                        break;
                    case FunctionCategory.Electrical:
                        switch (function.functionType)
                        {
                            case FunctionType.Fan:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Electrical/FanThinIcon.png";
                                break;
                            case FunctionType.TV:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Electrical/TVThinIcon.png";
                                break;
                        }
                        break;
                    case FunctionCategory.Scene:
                        btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
                        break;
                    case FunctionCategory.Music:
                        btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Music/MusicThinIcon.png";
                        break;
                    case FunctionCategory.Sensor:
                        switch(function.functionType)
                        {
                            case FunctionType.PM25:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/FunctionIconPm25.png";
                                break;
                            case FunctionType.CO2:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/FunctionIconCO2.png";
                                break;
                            case FunctionType.TVOC:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/FunctionIconTVOC.png";
                                break;
                            case FunctionType.Humidity:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/FunctionIconHumidity.png";
                                break;
                            case FunctionType.Temp:
                                btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/FunctionIconTemp.png";
                                break;
                        }
                        break;
                }
                btnFunctionIcon.UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png";
                if (!btnAllocated.IsSelected)
                {
@@ -328,7 +305,7 @@
                    Height = Application.GetRealWidth(28),
                    UnSelectedImagePath = "Public/ChooseIcon.png",
                    SelectedImagePath = "Public/ChooseOnIcon.png",
                    IsSelected = function.roomIdList.Contains(room.sid)
                    IsSelected = function.roomIds.Contains(room.roomId)
                };
                functionRow.AddChidren(btnChooseIcon);
                LoadEvent_ChangeRoomFunctionList(functionRow, btnChooseIcon, function);
@@ -350,91 +327,117 @@
        /// </summary>
        void LoadPage_LoadChooseRoomDialog()
        {
            Dialog dialog = new Dialog();
            FrameLayout dialogBodyView = new FrameLayout()
            {
                BackgroundColor = CSS_Color.DialogTransparentColor1,
            };
            dialog.AddChidren(dialogBodyView);
            FrameLayout contentView;
            contentView = new FrameLayout()
            {
                X = Application.GetRealWidth(205),
                Y = Application.GetRealHeight(106),
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealHeight(200),
                BackgroundImagePath = "Public/ChooseRoomListbg.png",
            };
            dialogBodyView.AddChidren(contentView);
            VerticalScrolViewLayout roomListView;
            roomListView = new VerticalScrolViewLayout()
            {
                X = Application.GetRealWidth(8),
                Y = Application.GetRealHeight(15),
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealHeight(45 * 4),
            };
            contentView.AddChidren(roomListView);
            Button btnAllRoom;
            btnAllRoom = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(128),
                Height = Application.GetRealHeight(50),
                TextID = StringId.All,
                TextColor = CSS_Color.FirstLevelTitleColor,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                IsSelected = showedFunctionRoomId == "0",
                TextAlignment = TextAlignment.CenterLeft,
                Tag = "0"
            };
            roomListView.AddChidren(btnAllRoom);
            LoadEvent_ChangeShowedFunctionList(btnAllRoom, dialog, Language.StringByID(StringId.All));
            roomListView.AddChidren(new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(112),
                Height = Application.GetRealWidth(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
            foreach (var tempRoom in DB_ResidenceData.rooms)
            {
                Button btnRoom = new Button()
            Action<string, string> action = (key, value) => {
                if (lastButton != null)
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(128),
                    Height = Application.GetRealHeight(50),
                    Text = tempRoom.name,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    SelectedTextColor = CSS_Color.MainColor,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextAlignment = TextAlignment.CenterLeft,
                    IsSelected = showedFunctionRoomId == tempRoom.sid,
                    Tag = tempRoom.sid,
                };
                roomListView.AddChidren(btnRoom);
                LoadEvent_ChangeShowedFunctionList(btnRoom, dialog, tempRoom.name);
                roomListView.AddChidren(new Button()
                    lastButton.IsSelected = false;
                }
                showedFunctionRoomId = key;
                if (showedFunctionRoomId == "0")
                {
                    Gravity = Gravity.CenterHorizontal,
                    Width = Application.GetRealWidth(112),
                    Height = Application.GetRealWidth(1),
                    BackgroundColor = CSS_Color.DividingLineColor,
                });
                    LoadFunctionListRow(allocatedList);
                }
                else
                {
                    LoadFunctionListRow(allocatedList.FindAll((obj) => obj.roomIds.Contains(showedFunctionRoomId)));
                }
                btnChoosedRoom.Text = value;
            };
            Dictionary<string, string> items = new Dictionary<string, string>();
            items.Add("0",Language.StringByID(StringId.All));
            foreach(var room in SpatialInfo.CurrentSpatial.RoomList)
            {
                items.Add(room.roomId,room.roomName);
            }
            dialogBodyView.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
            };
            var chooseDialog = new ListCellDialog(items,showedFunctionRoomId,action);
            chooseDialog.ShowRightDialog();
            dialog.Show();
            //Dialog dialog = new Dialog();
            //FrameLayout dialogBodyView = new FrameLayout()
            //{
            //    BackgroundColor = CSS_Color.DialogTransparentColor1,
            //};
            //dialog.AddChidren(dialogBodyView);
            //FrameLayout contentView;
            //contentView = new FrameLayout()
            //{
            //    X = Application.GetRealWidth(205),
            //    Y = Application.GetRealHeight(106),
            //    Width = Application.GetRealWidth(160),
            //    Height = Application.GetRealHeight(200),
            //    BackgroundImagePath = "Public/ChooseRoomListbg.png",
            //};
            //dialogBodyView.AddChidren(contentView);
            //VerticalScrolViewLayout roomListView;
            //roomListView = new VerticalScrolViewLayout()
            //{
            //    X = Application.GetRealWidth(8),
            //    Y = Application.GetRealHeight(15),
            //    Width = Application.GetRealWidth(160),
            //    Height = Application.GetRealHeight(45 * 4),
            //};
            //contentView.AddChidren(roomListView);
            //Button btnAllRoom;
            //btnAllRoom = new Button()
            //{
            //    X = Application.GetRealWidth(16),
            //    Width = Application.GetRealWidth(128),
            //    Height = Application.GetRealHeight(50),
            //    TextID = StringId.All,
            //    TextColor = CSS_Color.FirstLevelTitleColor,
            //    SelectedTextColor = CSS_Color.MainColor,
            //    TextSize = CSS_FontSize.SubheadingFontSize,
            //    IsSelected = showedFunctionRoomId == "0",
            //    TextAlignment = TextAlignment.CenterLeft,
            //    Tag = "0"
            //};
            //roomListView.AddChidren(btnAllRoom);
            //LoadEvent_ChangeShowedFunctionList(btnAllRoom, dialog, Language.StringByID(StringId.All));
            //roomListView.AddChidren(new Button()
            //{
            //    Gravity = Gravity.CenterHorizontal,
            //    Width = Application.GetRealWidth(112),
            //    Height = Application.GetRealWidth(1),
            //    BackgroundColor = CSS_Color.DividingLineColor,
            //});
            //foreach (var tempRoom in SpatialInfo.CurrentSpatial.RoomList)
            //{
            //    Button btnRoom = new Button()
            //    {
            //        X = Application.GetRealWidth(16),
            //        Width = Application.GetRealWidth(128),
            //        Height = Application.GetRealHeight(50),
            //        Text = tempRoom.roomName,
            //        TextColor = CSS_Color.FirstLevelTitleColor,
            //        SelectedTextColor = CSS_Color.MainColor,
            //        TextSize = CSS_FontSize.SubheadingFontSize,
            //        TextAlignment = TextAlignment.CenterLeft,
            //        IsSelected = showedFunctionRoomId == tempRoom.roomId,
            //        Tag = tempRoom.roomId,
            //    };
            //    roomListView.AddChidren(btnRoom);
            //    LoadEvent_ChangeShowedFunctionList(btnRoom, dialog, tempRoom.roomName);
            //    roomListView.AddChidren(new Button()
            //    {
            //        Gravity = Gravity.CenterHorizontal,
            //        Width = Application.GetRealWidth(112),
            //        Height = Application.GetRealWidth(1),
            //        BackgroundColor = CSS_Color.DividingLineColor,
            //    });
            //}
            //dialogBodyView.MouseUpEventHandler = (sender, e) =>
            //{
            //    dialog.Close();
            //};
            //dialog.Show();
        }