gxc
2019-11-22 9c607e921ca7c379799e4dd88b140265a1d5d5c5
ZigbeeApp/Shared/Phone/Device/Category/Category.cs
@@ -1616,244 +1616,14 @@
            }
            else
            {
                var sceneScrolView = new VerticalScrolViewLayout
                {
                    //Y = Application.GetRealHeight(58)
                };
                var sceneScrolView = new VerticalScrolViewLayout { };
                functionSceneBodyView.AddChidren(sceneScrolView);
                foreach (var scene in sceneList)
                {
                    var sceneFL = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(446),
                        BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
                        Tag = scene
                    };
                    sceneScrolView.AddChidren(sceneFL);
                    var sceneRowLayout = new RowLayout
                    {
                        Y = Application.GetRealHeight(46),
                        Height = Application.GetRealHeight(446 - 46),
                        LineColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
                        Radius = CommonPage.BigFormRadius
                    };
                    sceneFL.AddChidren(sceneRowLayout);
                    var sceneImg = new Button()
                    {
                        X = Application.GetRealWidth(179),
                        Width = Application.GetRealWidth(844),
                        Height = Application.GetRealHeight(400),
                        UnSelectedImagePath = scene.IconPath,
                        Radius = (uint)Application.GetRealHeight(17)
                    };
                    sceneRowLayout.AddChidren(sceneImg);
                    var leftFL = new FrameLayout
                    {
                        X = Application.GetRealWidth(CommonFormResouce.X_Left),
                        Y = Application.GetRealHeight(58),
                        Width = Application.GetRealWidth(251),
                        Height = Application.GetRealHeight(282),
                        BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor2,
                        Radius = (uint)Application.GetRealHeight(17)
                    };
                    sceneRowLayout.AddChidren(leftFL);
                    var collectionBtn = new Button
                    {
                        X = Application.GetRealWidth(23),
                        Y = Application.GetRealHeight(23),
                        Width = Application.GetMinRealAverage(65),
                        Height = Application.GetMinRealAverage(65),
                        UnSelectedImagePath = "Item/Collection.png",
                        SelectedImagePath = "Item/CollectionSelected.png",
                        IsSelected = Common.Room.CurrentRoom.GetLoveRoom().SceneUIFilePathList.Contains(scene.FileName),
                        Tag = scene
                    };
                    leftFL.AddChidren(collectionBtn);
                    var sceneNameBtn = new Button()
                    {
                        Width = Application.GetRealWidth(176),
                        Height = Application.GetRealHeight(150),
                        TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                        Text = scene.Name,
                        Gravity = Gravity.Center,
                        IsMoreLines = true
                    };
                    leftFL.AddChidren(sceneNameBtn);
                    var collection = new Button
                    {
                        Tag=scene
                    };
                    leftFL.AddChidren(collection);
                    collection.MouseUpEventHandler += (sender, e) =>
                    {
                        if (room.IsLove)
                        {
                            Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
                            sceneScrolView.RemoveViewByTag(collectionBtn.Tag);
                        }
                        else
                        {
                            collectionBtn.IsSelected = !collectionBtn.IsSelected;
                            if (collectionBtn.IsSelected)
                            {
                                Common.Room.CurrentRoom.GetLoveRoom().AddScene(scene);
                            }
                            else
                            {
                                Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
                            }
                        }
                    };
                    //定时
                    var delayBtn = new RowLayoutDeleteButton
                    {
                        TextID = R.MyInternationalizationString.Delay,
                        Tag = scene.SceneDelayTime
                    };
                    sceneRowLayout.AddLeftView(delayBtn);
                    //编辑
                    var settingBtn = new Device.CommonForm.RowLayoutEditButton()
                    {
                        TextID = R.MyInternationalizationString.Editor,
                        Tag = scene.SceneDelayTime
                    };
                    //删除
                    var deleteBtn = new Device.CommonForm.RowLayoutDeleteButton
                    {
                        Tag = scene
                    };
                    if(room.IsSharedRoom)
                    {
                    }
                    else
                    {
                        if(room.IsLove)
                        {
                            sceneRowLayout.AddRightView(deleteBtn);
                        }
                        else
                        {
                            sceneRowLayout.AddRightView(settingBtn);
                            sceneRowLayout.AddRightView(deleteBtn);
                        }
                    }
                    //调用场景
                    EventHandler<MouseEventArgs> sceneUpHandler = async (sender, e) =>
                    {
                        //1成功 0失败
                        //后面补上相关提示
                        //要先从网关读取延时是否正在执行,如果是进行倒计时,不允许在点击
                        var sceneOpenAllData = await ZigBee.Device.Scene.ControlSceneAsync(scene.Id, scene.SceneDelayTime);
                        //主网关不在线
                        if (sceneOpenAllData == null)
                        {
                            //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheMainGatewayIsNotOnLine);
                            CommonPage.Instance.FailureToServer();
                            return;
                        }
                        if (sceneOpenAllData.sceneOpenData == null)
                        {
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                            return;
                        }
                        //成功
                        if (sceneOpenAllData.sceneOpenData.Result == 1)
                        {
                        }
                        //失败
                        else
                        {
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                            return;
                        }
                    };
                    sceneImg.MouseUpEventHandler += sceneUpHandler;
                    //删除场景
                    EventHandler<MouseEventArgs> delEvent = (sender, e) =>
                    {
                        if(room.IsLove)
                        {
                            Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
                            sceneScrolView.RemoveViewByTag((sender as Button).Tag);
                        }
                        else
                        {
                            var tip = new CustomAlert { };
                            AddChidren(tip);
                            tip.Show(Language.StringByID(R.MyInternationalizationString.ConfirmDelete));
                            //var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConfirmDelete), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim));
                            //alert.Show();
                            tip.ResultEventHandler += async (e1) =>
                            {
                                if (e1)
                                {
                                    //0 移除失败 1 移除成功 2 没有该场景
                                    var removeSceneAllData = await ZigBee.Device.Scene.DeleteSceneAsync(scene.Id);
                                    if (removeSceneAllData == null || removeSceneAllData.removeSceneData == null)
                                    {
                                        //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheMainGatewayIsNotOnLine);
                                        CommonPage.Instance.FailureToServer();
                                        return;
                                    }
                                    //1成功
                                    if (removeSceneAllData.removeSceneData.Result == 1)
                                    {
                                        room.RemoveScene(scene);
                                        //RefreshBodyView();
                                        sceneScrolView.RemoveViewByTag((sender as Button).Tag);
                                    }
                                    //0 移除失败
                                    else if (removeSceneAllData.removeSceneData.Result == 0)
                                    {
                                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
                                        return;
                                    }
                                    //2 没有该场景
                                    else if (removeSceneAllData.removeSceneData.Result == 2)
                                    {
                                        room.RemoveScene(scene);
                                        //RefreshBodyView();
                                        sceneScrolView.RemoveViewByTag((sender as Button).Tag);
                                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneIsNull);
                                        return;
                                    }
                                }
                            };
                        }
                    };
                    deleteBtn.MouseUpEventHandler += delEvent;
                    //编辑场景
                    settingBtn.MouseUpEventHandler += (sender, e) =>
                    {
                        SceneUI.EditScene(scene, room);
                    };
                    //编辑延时
                    delayBtn.MouseUpEventHandler += (sender, e) =>
                    {
                        var timeSelect = new SelectTime();
                        CommonPage.Instance.AddChidren(timeSelect);
                        timeSelect.TempTime = scene.SceneDelayTime;
                        timeSelect.Init();
                        timeSelect.TimeAction = (t) =>
                        {
                            scene.SceneDelayTime = t;
                        };
                    };
                    var sceneView = new SceneCategoryView(0, 0);
                    sceneScrolView.AddChidren(sceneView);
                    sceneView.Init(scene, room);
                    GetDelayScene(sceneScrolView);
                }
            }
        }
@@ -1888,6 +1658,64 @@
        }
        /// <summary>
        /// GetDelayScene
        /// </summary>
        /// <param name="scrolViewLayout"></param>
        private void GetDelayScene(VerticalScrolViewLayout scrolViewLayout)
        {
            new System.Threading.Thread(async () =>
            {
                var catDelaySceneResponseAllData = await Scene.CatDelaySceneAsync();
                if (catDelaySceneResponseAllData == null)
                {
                    return;
                }
                var catDelaySceneResponseData = catDelaySceneResponseAllData.catDelaySceneResponseData;
                if (catDelaySceneResponseData == null || catDelaySceneResponseData.DelayScenesList.Count == 0)
                {
                    return;
                }
                var delayList = catDelaySceneResponseData.DelayScenesList;
                Application.RunOnMainThread(() =>
                {
                    for (int i = 0; scrolViewLayout != null && i < scrolViewLayout.ChildrenCount; i++)
                    {
                        var sceneView = scrolViewLayout.GetChildren(i) as SceneCategoryView;
                        foreach (var delayScenesListResponseInfo in delayList)
                        {
                            if (delayScenesListResponseInfo.ScenesId == sceneView.scene.Id)
                            {
                                var times = delayScenesListResponseInfo.RemainTime;
                                sceneView.scene.RemainTime = times;
                                new System.Threading.Thread(() =>
                                {
                                    while (times > 0)
                                    {
                                        System.Threading.Thread.Sleep(1000);
                                        Application.RunOnMainThread(() =>
                                        {
                                            sceneView.SetTimeText(CommonFormResouce.GetTimeString(times));
                                        });
                                        times -= 1;
                                    }
                                    Application.RunOnMainThread(() =>
                                    {
                                        sceneView.SetTimeImage();
                                    });
                                })
                                { IsBackground = true }.Start();
                                break;
                            }
                        }
                    }
                });
            })
            { IsBackground = true }.Start();
        }
        #endregion