WJC
2020-03-12 c47c3ec2488961b3a006aaebcb03dba582f8b19b
ZigbeeApp/Shared/Phone/Device/Category/SelectFloor.cs
@@ -8,23 +8,35 @@
    {
        public Action<string> FloorAction;
        /// <summary>
        /// 是否切换为当前楼层
        /// </summary>
        public bool changeFloor = true;
        /// <summary>
        /// 当前传过来的floorid
        /// </summary>
        public string CurFloorId = string.Empty;
        public bool changeFloor;
        Dialog dialogBackground;
        /// <summary>
      /// Init
      /// </summary>
      public void Init(int x,int y,CommonForm.Direction direction=CommonForm.Direction.Left)
        {
            var dialog = new FrameLayout()
            dialogBackground = new Dialog
            {
                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
            };
            AddChidren(dialog);
            dialogBackground.Show();
            var dialog = new FrameLayout()
            {
            };
            dialogBackground.AddChidren(dialog);
            dialog.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
                RemoveView();
            };
            var bg = new Button
@@ -32,33 +44,30 @@
                X = Application.GetRealWidth(x),
                Y = Application.GetRealHeight(y),
                Width = Application.GetMinRealAverage(449),
                Height = Application.GetMinRealAverage(783),
                UnSelectedImagePath="Item/SelectFloor_Left.png"
                Height = Application.GetMinRealAverage(773),
                UnSelectedImagePath = "Floor/SelectFloor_Left_4.png"
            };
            dialog.AddChidren(bg);
            if (direction == CommonForm.Direction.Right)
            {
                bg.UnSelectedImagePath = "Item/SelectFloor_Right.png";
            }
            var backgroundFL = new FrameLayout
            {
                X = Application.GetRealWidth(x+10),
                X = Application.GetRealWidth(x),
                Y = Application.GetRealHeight(y+23),
                Width = Application.GetMinRealAverage(449-20),
                Height = Application.GetMinRealAverage(783-23-10),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                Width = Application.GetMinRealAverage(449),
                Height = Application.GetMinRealAverage(773 - 23)
            };
            dialog.AddChidren(backgroundFL);
            var tip = new Button
            {
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(350),
                Height = Application.GetRealHeight(150),
                Width = Application.GetMinRealAverage(350),
                Height = Application.GetMinRealAverage(150),
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.SelectFloor
                TextID = R.MyInternationalizationString.SelectFloor,
                TextSize = 14,
                IsBold = true
            };
            backgroundFL.AddChidren(tip);
@@ -66,12 +75,40 @@
            {
                Y = tip.Bottom,
                Width = Application.GetMinRealAverage(449),
                Height = Application.GetMinRealAverage(600)
                Height = Application.GetMinRealAverage(600),
                VerticalScrollBarEnabled = false
            };
            backgroundFL.AddChidren(floorLayout);
            if (Config.Instance.Home.FloorDics.Count > 0)
            var floorCount = Config.Instance.Home.FloorDics.Count;
            if (floorCount > 0)
            {
                string directStr = string.Empty;
                if (direction == CommonForm.Direction.Right)
                {
                    directStr = "Right";
                }
                else
                {
                    directStr = "Left";
                }
                if (floorCount > 5)
                {
                    bg.UnSelectedImagePath = $"Floor/SelectFloor_{directStr}_5.png";
                    bg.Height = Application.GetMinRealAverage(150*6+23);
                    backgroundFL.Height = Application.GetMinRealAverage(150 * 6);
                    floorLayout.Height = Application.GetMinRealAverage(150 * 5);
                }
                else
                {
                    bg.UnSelectedImagePath = $"Floor/SelectFloor_{directStr}_{floorCount}.png";
                    bg.Height = Application.GetMinRealAverage(150 * (floorCount + 1)+23);
                    backgroundFL.Height = Application.GetMinRealAverage(150 * (floorCount + 1));
                    floorLayout.Height = Application.GetMinRealAverage(150 * floorCount);
                }
                foreach (var floor in Config.Instance.Home.FloorDics)
                {
                    AddFloor(floorLayout, floor);
@@ -83,19 +120,31 @@
        /// AddFloor
        /// </summary>
        /// <param name="verticalScrolView"></param>
        private void AddFloor(VerticalScrolViewLayout verticalScrolView, KeyValuePair<string, string> floor)
        private void AddFloor(VerticalScrolViewLayout verticalScrolView, KeyValuePair<string, string> floor,bool isLast=false)
        {
            var frow = new CommonForm.LeftIconButtonRow(449, 150);
            frow.Width = Application.GetMinRealAverage(449);
            frow.Height = Application.GetMinRealAverage(150);
            frow.Tag = floor.Key;
            frow.Init("Floor/Floor.png", "Floor/FloorSelected.png", floor.Value);
            verticalScrolView.AddChidren(frow);
            if (string.IsNullOrEmpty(CurFloorId))
            {
            if (Config.Instance.Home.CurrentFloorId == floor.Key)
            {
                frow.IsSelected = true;
            }
            }
            else
            {
                if (CurFloorId == floor.Key)
                {
                    frow.IsSelected = true;
                }
            }
            frow.IconButton.MouseUpEventHandler += SelectFloor_MouseUpEvent;
            frow.TitleButton.MouseUpEventHandler += SelectFloor_MouseUpEvent;
            frow.ButtonClickEvent += SelectFloor_MouseUpEvent;
        }
        /// <summary>
@@ -105,14 +154,24 @@
        /// <param name="mouseEventArgs"></param>
        private void SelectFloor_MouseUpEvent(object sender,MouseEventArgs mouseEventArgs)
        {
            ((sender as Button).Parent as CommonForm.LeftIconButtonRow).IsSelected = true;
            (sender as CommonForm.LeftIconButtonRow).IsSelected = true;
            if(changeFloor)
            {
                Config.Instance.Home.CurrentFloorId = (sender as Button).Tag.ToString();
                Config.Instance.Home.Save();
                Config.Instance.Home.CurrentFloorId = (sender as CommonForm.LeftIconButtonRow).Tag.ToString();
                Config.Instance.Home.Save(false);
                UserCenter.HdlRoomLogic.Current.RefreshRoomListView();
            }
            RemoveView();
            FloorAction?.Invoke((sender as CommonForm.LeftIconButtonRow).Tag.ToString());
            }
            
            FloorAction?.Invoke((sender as Button).Tag.ToString());
        /// <summary>
        /// RemoveView
        /// </summary>
        private void RemoveView()
        {
            dialogBackground.Close();
            RemoveFromParent();
        }
    }