gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
@@ -51,7 +51,7 @@
        /// <summary>
        /// 添加目标后的展示列表
        /// </summary>
        public VerticalScrolViewLayout TargetListScrolView;
        public FrameLayout TargetListScrolView;
        /// <summary>
        /// The confirm button.
        /// </summary>
@@ -95,7 +95,11 @@
        /// <summary>
        /// 修改场景action
        /// </summary>
        public Action<SceneUI, Common.Room> EditorAction;
        public Action<SceneUI, Common.Room> EditorAction;
        /// <summary>
        /// 添加场景action
        /// </summary>
        public Action AddAction;
        #endregion
@@ -111,6 +115,7 @@
        /// </summary>
        public override void RemoveFromParent()
        {
            UserView.HomePage.Instance.ScrollEnabled = true;
            base.RemoveFromParent();
        }
        /// <summary>
@@ -118,17 +123,34 @@
        /// </summary>
        public void RefreshTargetListView()
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
            TargetListScrolView.RemoveAll();
            TargetListScrolView.Height = Application.GetRealHeight(173);
            var TargetListScrolBackView = new FrameLayout()
            {
                Height = Application.GetRealHeight(173),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            TargetListScrolView.AddChidren(TargetListScrolBackView);
            if (sceneTargetDevicesList.Count > 0)
            {
                foreach (var targetDevice in sceneTargetDevicesList)
                if (sceneTargetDevicesList.Count > 1)
                {
                    TargetListScrolView.Height = Application.GetRealHeight(140 * sceneTargetDevicesList.Count) + Application.GetRealHeight(200);
                    TargetListScrolBackView.Height = Application.GetRealHeight(140 * sceneTargetDevicesList.Count + 13);
                }
                for (int i = 0; i < sceneTargetDevicesList.Count; i++)
                {
                    var targetDevice = sceneTargetDevicesList[i];
                    var targetRowLayout = new RowLayout()
                    {
                        Height = Application.GetRealHeight(160),
                        LineColor = ZigbeeColor.Current.GXCBackgroundColor,
                        BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                        Y = Application.GetRealHeight(i * 140),
                        Height = Application.GetRealHeight(140),
                        LineColor = ZigbeeColor.Current.GXCClearColor,
                        BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                        SubViewWidth = Application.GetRealWidth(184)
                    };
                    TargetListScrolView.AddChidren(targetRowLayout);
                    string devImgPath = string.Empty;
@@ -137,53 +159,55 @@
                    {
                        if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null) continue;
                        devImgPath = targetDevice.DeviceUI.IconPath;
                        devNameText = targetDevice.DeviceUI.CommonDevice.DeviceEpointName;
                        devNameText = Common.LocalDevice.Current.GetDeviceEpointName(targetDevice.DeviceUI.CommonDevice);
                        var targetRow = new SceneTargetFunctionRow(23);
                        targetRowLayout.AddChidren(targetRow);
                        var targetRow = new SceneTargetFunctionRow(13);
                        targetRow.Init();
                        targetRow.SetIcon(devImgPath);
                        targetRow.SetNameText(devNameText);
                        targetRow.SetZoneText(targetDevice.DeviceUI.GetZone());
                        targetRow.SetStatuText(targetDevice.GetDeviceStatu());
                        targetRowLayout.AddChidren(targetRow);
                        if (i == sceneTargetDevicesList.Count - 1)
                        {
                            targetRow.HideLine(true);
                        }
                    }
                    else if (targetDevice.Type == 2)
                    {
                        devNameText = CommonFormResouce.GetTimeString(targetDevice.DelayTime);
                        devNameText += Language.StringByID(R.MyInternationalizationString.Later);
                        var targetRow = new SceneTargetTimeRow(23);
                        targetRowLayout.AddChidren(targetRow);
                        var targetRow = new SceneTargetTimeRow(13);
                        targetRow.Init();
                        targetRow.SetTitle(devNameText);
                        targetRowLayout.AddChidren(targetRow);
                        if (i == sceneTargetDevicesList.Count - 1)
                        {
                            targetRow.HideLine(true);
                        }
                    }
                    else if (targetDevice.Type == 1)
                    {
                        devImgPath = "Scene/SceneIcon.png";
                        devNameText = targetDevice.SceneName;
                        var targetRow = new SceneTargetFunctionRow(23);
                        targetRowLayout.AddChidren(targetRow);
                        var targetRow = new SceneTargetFunctionRow(13);
                        targetRow.Init();
                        targetRow.SetIcon(devImgPath);
                        targetRow.SetNameText(devNameText);
                        targetRow.SetZoneText(targetDevice.SceneUI.GetZone());
                        targetRowLayout.AddChidren(targetRow);
                        if (i == sceneTargetDevicesList.Count - 1)
                        {
                            targetRow.HideLine(true);
                        }
                    }
                    var editBtn = new Button()
                    {
                        BackgroundColor = ZigbeeColor.Current.GXCEditBackGroundColor,
                        TextID = R.MyInternationalizationString.Edit,
                        TextColor = ZigbeeColor.Current.GXCTextWhiteColor
                    };
                    var editBtn = new RowLayoutEditButton();
                    targetRowLayout.AddRightView(editBtn);
                    //编辑设备
                    editBtn.MouseUpEventHandler += detailMouseUpEventHandler;
                    var delBtn = new Button()
                    {
                        BackgroundColor = ZigbeeColor.Current.GXCRedColor,
                        TextID = R.MyInternationalizationString.Delete,
                        TextColor = ZigbeeColor.Current.GXCTextWhiteColor
                    };
                    var delBtn = new RowLayoutDeleteButton();
                    targetRowLayout.AddRightView(delBtn);
                    //删除设备
                    delBtn.MouseUpEventHandler += (sender, e) =>
@@ -256,17 +280,6 @@
                        }
                    }
                }
                if (sceneTargetDevicesList.Count > 1)
                {
                    var targetRowLayout = new RowLayout()
                    {
                        Height = Application.GetRealHeight(300),
                        LineColor = ZigbeeColor.Current.GXCBackgroundColor,
                        BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                    };
                    TargetListScrolView.AddChidren(targetRowLayout);
                }
            }
        }
        /// <summary>
@@ -319,13 +332,20 @@
        /// </summary>
        private void AddBodyView()
        {
            bodyFrameLayout = new FrameLayout()
            var bodyScrolView=new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(184),
                Height = Application.GetRealHeight(1737),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            AddChidren(bodyFrameLayout);
            AddChidren(bodyScrolView);
            bodyFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(1086+127),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
            };
            bodyScrolView.AddChidren(bodyFrameLayout);
            var imgFL = new FrameLayout
            {
@@ -334,21 +354,31 @@
            };
            bodyFrameLayout.AddChidren(imgFL);
            var backGround1 = new ImageView()
            {
                Y = Application.GetRealHeight(46),
                Width = Application.GetMinRealAverage(916),
                Height = Application.GetMinRealAverage(487),
                Gravity = Gravity.CenterHorizontal,
                ImagePath = "Room/Room_Rectangle.png"
            };
            imgFL.AddChidren(backGround1);
            backGround = new ImageView()
            {
                Width = Application.GetMinRealAverage(930),
                Height = Application.GetMinRealAverage(464),
                Gravity = Gravity.Center,
                Y = Application.GetRealHeight(46),
                Width = Application.GetMinRealAverage(887),
                Height = Application.GetMinRealAverage(444),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetMinRealAverage(CommonFormResouce.BigFormRadius),
                ImagePath = "SceneIcon/3.jpg"
            };
            imgFL.AddChidren(backGround);
            backGround.SetViewShadow(true);
            var infoFL = new FrameLayout
            {
                Y = imgFL.Bottom + Application.GetRealHeight(23),
                Height = Application.GetRealHeight(418),
                Y = Application.GetRealHeight(588),
                Height = Application.GetRealHeight(429),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            bodyFrameLayout.AddChidren(infoFL);
@@ -362,7 +392,7 @@
                TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 15,
                IsBold=true
                //IsBold=true
            };
            infoFL.AddChidren(infoEdit);
@@ -382,8 +412,8 @@
            var targetFL = new FrameLayout()
            {
                Y = infoFL.Bottom + Application.GetRealHeight(23),
                Height = Application.GetRealHeight(730)
                Y = Application.GetRealHeight(1040),
                Height = Application.GetRealHeight(346)
            };
            bodyFrameLayout.AddChidren(targetFL);
@@ -432,12 +462,13 @@
            };
            addTargetFL.AddChidren(targetLine);
            TargetListScrolView = new VerticalScrolViewLayout()
            TargetListScrolView = new FrameLayout()
            {
                Y = Application.GetRealHeight(49+127),
                Height = Application.GetRealHeight(730-127-49),
                Height = Application.GetRealHeight(173)
            };
            targetFL.AddChidren(TargetListScrolView);
            bodyScrolView.AddChidren(TargetListScrolView);
            confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
            confirmBtn.TextID = R.MyInternationalizationString.Next;
@@ -582,7 +613,11 @@
                    var fileName = $"SceneIcon_{tradeTime}.png";
                    //通过相机拍照裁剪
                    CropImage.TakePicture((imagePath) =>
                    {
                    {
                        if (string.IsNullOrEmpty(imagePath))
                        {
                            return;
                        }
                        if (isModify)
                        {
                            if (IconPathType != 0)
@@ -607,7 +642,11 @@
                    var fileName = $"SceneIcon_{tradeTime}.png";
                    //从相册选择图片裁剪
                    CropImage.SelectPicture((imagePath) =>
                    {
                    {
                        if (string.IsNullOrEmpty(imagePath))
                        {
                            return;
                        }
                        if (isModify)
                        {
                            if (IconPathType != 0)
@@ -639,53 +678,13 @@
            //区域
            EventHandler<MouseEventArgs> zoneHander = (sender, e) =>
            {
                List<string> floorIds = new List<string> { };
                List<string> floorNames = new List<string> { };
                List<List<string>> roomNames = new List<List<string>> { };
                List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
                List<Common.Room> rs = new List<Common.Room> { };
                List<string> rNames = new List<string> { };
                if (Config.Instance.Home.FloorDics.Count > 0)
                var zone = new SelectZone();
                zone.Init();
                zone.ZoneAction += (selectRoom) =>
                {
                    foreach (var floor in Config.Instance.Home.FloorDics)
                    {
                        if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
                        {
                            floorIds.Add(floor.Key);
                            floorNames.Add(floor.Value);
                            roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
                            rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
                        }
                    }
                    PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
                    {
                        curRoom = rooms[index1][index2];
                        zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}");
                    }, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongZone),
                   Language.StringByID(R.MyInternationalizationString.Confrim),
                   Language.StringByID(R.MyInternationalizationString.Cancel));
                }
                else
                {
                    for (int i = 0; i < Common.Room.Lists.Count; i++)
                    {
                        var r = Common.Room.Lists[i];
                        if (r.IsLove)
                        {
                            continue;
                        }
                        rs.Add(r);
                        rNames.Add(r.Name);
                    }
                    PickerView.Show(rNames, (index1) =>
                    {
                        curRoom = rs[index1];
                        zoneRow.SetTitle(rs[index1].Name);
                    }, 0, Language.StringByID(R.MyInternationalizationString.BelongZone),
                   Language.StringByID(R.MyInternationalizationString.Confrim),
                   Language.StringByID(R.MyInternationalizationString.Cancel));
                }
                    curRoom = selectRoom;
                    zoneRow.SetTitle(selectRoom.GetZoneName());
                };
            };
            zoneRow.ClickBtn.MouseUpEventHandler += zoneHander;
@@ -855,7 +854,7 @@
                }
                if (curRoom.IsSharedRoom)
                {
                    RemoveFromParent();
                    RoomCommon.ShowTipRoomIsShared();
                    return;
                }
@@ -863,12 +862,8 @@
                {
                    if (string.IsNullOrEmpty(nameRow.NameText.Text))
                    {
                        var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull), Language.StringByID(R.MyInternationalizationString.Close));
                        alert.Show();
                        alert.ResultEventHandler += (sendAlert, eAlert) =>
                        {
                            return;
                        };
                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull));
                        return;
                    }
                    else
                    {
@@ -902,13 +897,12 @@
                            if (OldIconPathType != 0)
                            {
                                Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, OldBackgroundImagePath));
                                HdlAutoBackupLogic.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, OldBackgroundImagePath));
                                HdlAutoBackupLogic.DeleteFile(OldBackgroundImagePath);
                            }
                            if (IconPathType == 1 || IconPathType == 2)
                            {
                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
                                HdlAutoBackupLogic.AddOrEditorFile(System.IO.Path.Combine(Config.Instance.FullPath, fileName));
                                HdlAutoBackupLogic.AddOrEditorFile(fileName);
                                modifySceneUI.IconPath = fileName;
                            }
                            else
@@ -937,7 +931,7 @@
                                        Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
                                        TaskList = sceneTarget.TaskList,
                                        DelayTime = 0,
                                        MemberNumber = i+1
                                        MemberNumber = i + 1
                                    };
                                    memberDataList.Add(memberData);
                                }
@@ -949,7 +943,7 @@
                                        ScenesId = 0,
                                        ElseScenesId = sceneTarget.ElseScenesId,
                                        DelayTime = 0,
                                        MemberNumber = i+1
                                        MemberNumber = i + 1
                                    };
                                    memberDataList.Add(memberData);
                                }
@@ -960,7 +954,7 @@
                                        Type = 2,
                                        ScenesId = 0,
                                        DelayTime = sceneTarget.DelayTime,
                                        MemberNumber = i+1
                                        MemberNumber = i + 1
                                    };
                                    memberDataList.Add(memberData);
                                }
@@ -1001,8 +995,8 @@
                                    var removeDevice = new ZigBee.Device.Scene.RemoveSceneDeviceListInfo
                                    {
                                        Type = 2,
                                        DelayTime=sceneTarget.DelayTime,
                                        MemberNumber=sceneTarget.DelayTimeSerialNumber
                                        DelayTime = sceneTarget.DelayTime,
                                        MemberNumber = sceneTarget.DelayTimeSerialNumber
                                    };
                                    removeSceneDeviceListInfoList.Add(removeDevice);
                                }
@@ -1021,15 +1015,16 @@
                                    modifyRoom.Save();
                                    curRoom.Save();
                                }
                                EditorAction?.Invoke(modifySceneUI, curRoom);
                                RemoveFromParent();
                            }
                            else if (result == 0)
                            {
                                Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
                            }
                            else if (result == -1)
                            {
                                Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
                                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneHadExist));
                            }
                        }
                        catch (Exception ex)
@@ -1047,12 +1042,8 @@
                    //新增
                    if (string.IsNullOrEmpty(nameRow.NameText.Text))
                    {
                        var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull), Language.StringByID(R.MyInternationalizationString.Close));
                        alert.Show();
                        alert.ResultEventHandler += (sendAlert, eAlert) =>
                        {
                            return;
                        };
                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull));
                        return;
                    }
                    else
                    {
@@ -1064,17 +1055,18 @@
                            if (IconPathType == 1 || IconPathType == 2)
                            {
                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
                                HdlAutoBackupLogic.AddOrEditorFile(fileName);
                                imgPath = fileName;
                            }
                            else
                            {
                                imgPath = backGround.ImagePath;
                            }
                            if (Common.Room.CurrentRoom.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
                            {
                                Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
                                return;
                            }
                            //if (Common.Room.CurrentRoom.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
                            //{
                            //    CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneHadExist));
                            //    return;
                            //}
                            CommonPage.Loading.Start();
                            var memberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData>();
                            for (int i = 0; i < sceneTargetDevicesList.Count; i++)
@@ -1124,18 +1116,19 @@
                                }
                            }
                            var result = await curRoom.AddScene(nameRow.NameText.Text, imgPath, memberDataList);
                            var result = await curRoom.AddScene(nameRow.NameText.Text, imgPath, memberDataList, IconPathType);
                            if (result == 1)
                            {
                                AddAction?.Invoke();
                                RemoveFromParent();
                            }
                            else if (result == 0)
                            {
                                CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.AddSceneFail);
                                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.AddSceneFail));
                            }
                            else if (result == -1)
                            {
                                CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
                                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneHadExist));
                            }
                        }
                        catch (Exception ex)
@@ -1251,7 +1244,7 @@
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice)
            };
            titleFL.AddChidren(deviceName);
@@ -1407,7 +1400,7 @@
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice)
            };
            titleFL.AddChidren(deviceName);
@@ -1460,7 +1453,7 @@
                dialog.RemoveFromParent();
            };
            open.SeekBar.ProgressChanged += (sender, e) =>
            open.SeekBar.OnProgressChangedEvent += (sender, e) =>
            {
                open.IsSelected = true;
                shut.IsSelected = false;
@@ -1478,7 +1471,7 @@
                {
                    open.IsSelected = true;
                    shut.IsSelected = false;
                    open.SetProgress(sceneTarget.TaskList[0].Data2);
                    open.SetSeekBarProgress(sceneTarget.TaskList[0].Data2);
                }
            }
@@ -1573,7 +1566,7 @@
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice)
            };
            titleFL.AddChidren(deviceName);
@@ -1626,7 +1619,7 @@
                dialog.RemoveFromParent();
            };
            open.SeekBar.ProgressChanged += (sender, e) =>
            open.SeekBar.OnProgressChangedEvent += (sender, e) =>
            {
                open.IsSelected = true;
                shut.IsSelected = false;
@@ -1644,7 +1637,7 @@
                {
                    open.IsSelected = true;
                    shut.IsSelected = false;
                    open.SetProgress(sceneTarget.TaskList[0].Data1);
                    open.SetSeekBarProgress(sceneTarget.TaskList[0].Data1);
                }
            }
@@ -1746,7 +1739,7 @@
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
                Text = Common.LocalDevice.Current.GetDeviceEpointName(device.CommonDevice)
            };
            titleFL.AddChidren(deviceName);