From f6e34a69f1d1e0b0b3a6252fe20acddca7fe56e5 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期二, 17 三月 2020 15:43:44 +0800
Subject: [PATCH] 2020-03-17-1

---
 ZigbeeApp/Shared/Phone/Device/CommonForm/SceneCategoryView.cs |  311 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 202 insertions(+), 109 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/SceneCategoryView.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/SceneCategoryView.cs
index 28e2981..d8341ed 100755
--- a/ZigbeeApp/Shared/Phone/Device/CommonForm/SceneCategoryView.cs
+++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/SceneCategoryView.cs
@@ -1,5 +1,9 @@
 锘縰sing System;
+using System.Collections.Generic;
 using Shared.Common;
+using Shared.Phone.Device.Category;
+using Shared.Phone.UserCenter;
+
 namespace Shared.Phone.Device.CommonForm
 {
     public class SceneCategoryView : FrameLayout
@@ -23,7 +27,7 @@
         /// <summary>
         /// sceneImg
         /// </summary>
-        private Button sceneImg;
+        private ImageView sceneImg;
 
         /// <summary>
         /// SceneCategoryView
@@ -35,7 +39,7 @@
             X = Application.GetRealWidth(x);
             Y = Application.GetRealHeight(y);
             Width = Application.GetRealWidth(1080);
-            Height = Application.GetRealHeight(446);
+            Height = Application.GetRealHeight(397 + 46);
             BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor;
         }
 
@@ -48,7 +52,6 @@
             this.room = curRoom;
 
             InitFrame();
-            InitStatu();
         }
 
         /// <summary>
@@ -56,23 +59,30 @@
         /// </summary>
         private void InitFrame()
         {
+            RemoveAll();
             var sceneRowLayout = new RowLayout
             {
-                Y = Application.GetRealHeight(46),
-                Height = Application.GetRealHeight(446 - 46),
-                LineColor = ZigbeeColor.Current.GXCGrayBackgroundColor
+                Height = Application.GetRealHeight(440),
+                LineColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
+                Tag = scene
             };
             AddChidren(sceneRowLayout);
 
-            sceneImg = new Button()
+            sceneImg = new ImageView()
             {
                 X = Application.GetRealWidth(179),
                 Width = Application.GetRealWidth(844),
-                Height = Application.GetRealHeight(400),
-                UnSelectedImagePath = scene.IconPath,
+                Height = Application.GetRealHeight(397),
+                ImagePath = scene.IconPathType == 0 ? scene.IconPath : System.IO.Path.Combine(Config.Instance.FullPath, scene.IconPath),
                 Radius = (uint)Application.GetRealHeight(17)
             };
-            sceneRowLayout.AddChidren(sceneImg);
+            sceneRowLayout.AddChidren(sceneImg);
+            //闃村奖
+            var btnShadow = new PicViewControl(sceneImg.Width + Application.GetRealWidth(14 * 2), sceneImg.Height + Application.GetRealHeight(43), false);
+            btnShadow.X = sceneImg.X - Application.GetRealWidth(14);
+            btnShadow.UnSelectedImagePath = "Scene/SceneShadow.png";
+            sceneRowLayout.AddChidren(btnShadow);
+            btnShadow.ButtonClickEvent += this.SceneUpHandler;
 
             var leftFL = new FrameLayout
             {
@@ -80,7 +90,7 @@
                 Y = Application.GetRealHeight(58),
                 Width = Application.GetRealWidth(251),
                 Height = Application.GetRealHeight(282),
-                BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor2,
+                BackgroundColor = 0xd6333333,
                 Radius = (uint)Application.GetRealHeight(17)
             };
             sceneRowLayout.AddChidren(leftFL);
@@ -93,7 +103,7 @@
                 Height = Application.GetMinRealAverage(65),
                 UnSelectedImagePath = "Item/Collection.png",
                 SelectedImagePath = "Item/CollectionSelected.png",
-                IsSelected = Common.Room.CurrentRoom.GetLoveRoom().SceneUIFilePathList.Contains(scene.FileName),
+                IsSelected = HdlRoomLogic.Current.IsCollectInRoom(scene),
                 Tag = scene
             };
             leftFL.AddChidren(collectionBtn);
@@ -118,19 +128,19 @@
             {
                 if (room.IsLove)
                 {
-                    Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
+                    HdlSceneLogic.Current.DeleteScene(HdlRoomLogic.Current.GetLoveRoom(), scene);
                     RemoveViewByTag(collectionBtn.Tag);
                 }
                 else
                 {
                     collectionBtn.IsSelected = !collectionBtn.IsSelected;
                     if (collectionBtn.IsSelected)
-                    {
-                        Common.Room.CurrentRoom.GetLoveRoom().AddScene(scene);
+                    {
+                        HdlSceneLogic.Current.AddScene(HdlRoomLogic.Current.GetLoveRoom(), scene);
                     }
                     else
                     {
-                        Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
+                        HdlSceneLogic.Current.DeleteScene(HdlRoomLogic.Current.GetLoveRoom(), scene);
                     }
                 }
             };
@@ -156,103 +166,194 @@
                 UnSelectedImagePath = "Scene/Delaying.png",
                 Visible=false
             };
-            sceneRowLayout.AddChidren(delayImgBtn);
-
-            //瀹氭椂
-            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);
-                }
+            sceneRowLayout.AddChidren(delayImgBtn);
+
+            sceneRowLayout.SubViewWidth = Application.GetRealWidth(199);
+            //瀹氭椂
+            var btnDelay = new NormalViewControl(Application.GetRealWidth(199), sceneRowLayout.Height, false);
+            btnDelay.BackgroundColor = ZigbeeColor.Current.GXCTextSelectedColor;
+            btnDelay.TextID = R.MyInternationalizationString.Delay;
+            btnDelay.TextColor = ZigbeeColor.Current.GXCTextWhiteColor;
+            btnDelay.TextAlignment = TextAlignment.Center;
+            btnDelay.Tag = scene.SceneDelayTime;
+            btnDelay.Radius = (uint)Application.GetRealHeight(17);
+            sceneRowLayout.AddLeftView(btnDelay);
+            //鍙樻洿鎸夐挳鐨勯珮搴�
+            btnDelay.Height = sceneImg.Height;
+
+             //缂栬緫
+             var btnEditor = new NormalViewControl(Application.GetRealWidth(199), sceneImg.Height, false);
+            btnEditor.BackgroundColor = ZigbeeColor.Current.GXCEditBackGroundColor;
+            btnEditor.TextID = R.MyInternationalizationString.Edit;
+            btnEditor.TextColor = ZigbeeColor.Current.GXCTextWhiteColor;
+            btnEditor.TextAlignment = TextAlignment.Center;
+            btnEditor.Tag = scene.SceneDelayTime;
+            btnEditor.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerTopLeft);
+
+            //鍒犻櫎
+            var btnDelete = new NormalViewControl(Application.GetRealWidth(199), sceneImg.Height, false);
+            btnDelete.Tag = scene;
+            btnDelete.BackgroundColor = ZigbeeColor.Current.GXCRedColor;
+            btnDelete.TextID = R.MyInternationalizationString.Delete;
+            btnDelete.TextColor = ZigbeeColor.Current.GXCTextWhiteColor;
+            btnDelete.TextAlignment = TextAlignment.Center;
+            btnDelete.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerTopRight | HDLUtils.RectCornerBottomRight);
+            
+            if (room.IsSharedRoom == false && room.IsLove == false)
+            {
+                //涓嶆槸鍒嗕韩,骞朵笖涓嶆槸鏀惰棌
+                sceneRowLayout.AddRightView(btnEditor);
+                sceneRowLayout.AddRightView(btnDelete);
+                //鍙樻洿鎸夐挳鐨勯珮搴�
+                btnEditor.Height = sceneImg.Height;
+                btnDelete.Height = sceneImg.Height;
             }
 
             //鍒犻櫎鍦烘櫙
-            EventHandler<MouseEventArgs> delEvent = (sender, e) =>
-            {
-                if (room.IsLove)
-                {
-                    Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteScene(scene);
-                    RemoveViewByTag((sender as Button).Tag);
-                }
-                else
-                {
-                    var tip = new CustomAlert { };
-                    AddChidren(tip);
-                    tip.Show(Language.StringByID(R.MyInternationalizationString.ConfirmDelete));
+            btnDelete.ButtonClickEvent += (sender, e) =>
+            {
+                var alert = new ShowMsgControl(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.ConfirmDelete));
+                alert.Show();
+                alert.ConfirmClickEvent += async () =>
+                {
+                    //0 绉婚櫎澶辫触 1 绉婚櫎鎴愬姛 2 娌℃湁璇ュ満鏅�
+                    var removeSceneAllData = await ZigBee.Device.Scene.DeleteSceneAsync(scene.Id);
+                    if (removeSceneAllData == null || removeSceneAllData.removeSceneData == null)
+                    {
+                        CommonPage.Instance.FailureToServer();
+                        return;
+                    }
+                    //1鎴愬姛
+                    if (removeSceneAllData.removeSceneData.Result == 1)
+                    {
+                        HdlSceneLogic.Current.RemoveScene(scene);
+                        //RefreshBodyView();
+                        RemoveFromParent();
+                    }
+                    //0 绉婚櫎澶辫触
+                    else if (removeSceneAllData.removeSceneData.Result == 0)
+                    {
+                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
+                        return;
+                    }
+                    //2 娌℃湁璇ュ満鏅�
+                    else if (removeSceneAllData.removeSceneData.Result == 2)
+                    {
+                        HdlSceneLogic.Current.RemoveScene(scene);
+                        //RefreshBodyView();
+                        RemoveFromParent();
+                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneIsNull));
+                        return;
+                    }
+                };
+            };
 
-                    tip.ResultEventHandler += async (e1) =>
+            //缂栬緫鍦烘櫙
+            btnEditor.ButtonClickEvent += async (sender, e) =>
+            {
+                try
+                {
+                    var targetList = new List<SceneTargetDeviceUI> { };
+                    CommonPage.Loading.Start();
+                    //浠庣綉鍏充腑鍙嶅簭鍒楀寲鍑哄搴旂殑鎴块棿璁惧
+                    var sceneDeviceList = await ZigBee.Device.Scene.GetSceneDeviceListAsync(scene.Id);
+                    if (sceneDeviceList == null)
                     {
-                        if (e1)
+                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheMainGatewayIsNotOnLine));
+                        return;
+                    }
+                   
+                    if (sceneDeviceList.getSceneDeviceListInfo != null)
+                    {
+                        var deviceList = sceneDeviceList.getSceneDeviceListInfo.DeviceList;
+                        var allDevice = HdlRoomLogic.Current.GetAllRoomListDevice();
+                        var allScene = HdlSceneLogic.Current.GetAllRoomSceneList();
+
+                        if (deviceList != null && allDevice.Count != 0)
                         {
-                            //0 绉婚櫎澶辫触 1 绉婚櫎鎴愬姛 2 娌℃湁璇ュ満鏅�
-                            var removeSceneAllData = await ZigBee.Device.Scene.DeleteSceneAsync(scene.Id);
-                            if (removeSceneAllData == null || removeSceneAllData.removeSceneData == null)
+                            foreach (var sceneDev in deviceList)
                             {
-                                CommonPage.Instance.FailureToServer();
-                                return;
+                                if (sceneDev.Type == 0)
+                                {
+                                    var dev = allDevice.Find((obj) => obj.DeviceEpoint == sceneDev.Epoint && obj.DeviceAddr == sceneDev.DeviceAddr);
+                                    if (dev != null)
+                                    {
+                                        var sceneTargetDevice = new SceneTargetDeviceUI
+                                        {
+                                            Type = 0,
+                                            DeviceUI = dev,
+                                            TaskList = sceneDev.TaskList,
+                                            DelayTimeSerialNumber = deviceList.IndexOf(sceneDev) + 1
+                                        };
+
+                                        targetList.Add(sceneTargetDevice);
+                                    }
+                                }
+                                else if (sceneDev.Type == 1)
+                                {
+                                    var localScene = allScene.Find((obj) => obj.Id == sceneDev.ElseScenesId);
+                                    if (localScene != null)
+                                    {
+                                        var sceneTargetDeviceScene = new SceneTargetDeviceUI
+                                        {
+                                            Type = 1,
+                                            ElseScenesId = sceneDev.ElseScenesId,
+                                            SceneName = localScene.Name,
+                                            SceneUI = localScene,
+                                            DelayTimeSerialNumber = deviceList.IndexOf(sceneDev) + 1
+                                        };
+                                        targetList.Add(sceneTargetDeviceScene);
+                                    }
+                                }
+                                else
+                                {
+                                    var sceneTargetDeviceScene = new SceneTargetDeviceUI
+                                    {
+                                        Type = 2,
+                                        DelayTime = sceneDev.DelayTime,
+                                        DelayTimeSerialNumber = deviceList.IndexOf(sceneDev) + 1
+                                    };
+                                    targetList.Add(sceneTargetDeviceScene);
+                                }
                             }
-                            //1鎴愬姛
-                            if (removeSceneAllData.removeSceneData.Result == 1)
-                            {
-                                room.RemoveScene(scene);
-                                //RefreshBodyView();
-                                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();
-                                RemoveViewByTag((sender as Button).Tag);
-                                CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneIsNull);
-                                return;
-                            }
+                        }
+                    }
+                    else
+                    {
+                        CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.FailedPleaseTryAgain));
+                    }
+
+                    var sceneView = new CategoryAddScene();
+                    Phone.UserView.HomePage.Instance.AddChidren(sceneView);
+                    Phone.UserView.HomePage.Instance.PageIndex += 1;
+                    sceneView.isModify = true;
+                    sceneView.modifyRoom = room;
+                    sceneView.modifySceneUI = scene;
+                    sceneView.modifySceneTargetDevicesList = targetList;
+                    sceneView.Show();
+                    sceneView.EditorAction = (s, r) =>
+                    {
+                        if (r.Id != room.Id)
+                        {
+                            RemoveFromParent();
+                        }
+                        else
+                        {
+                            Init(s, r);
                         }
                     };
                 }
-            };
-            deleteBtn.MouseUpEventHandler += delEvent;
-            //缂栬緫鍦烘櫙
-            settingBtn.MouseUpEventHandler += (sender, e) =>
-            {
-                SceneUI.EditScene(scene, room);
+                catch (Exception ex)
+                {
+                    System.Console.WriteLine($"缂栬緫鍦烘櫙鍑洪敊---{ex.Message}");
+                }
+                finally
+                {
+                    CommonPage.Loading.Hide();
+                }
             };
             //缂栬緫寤舵椂
-            delayBtn.MouseUpEventHandler += (sender, e) =>
+            btnDelay.ButtonClickEvent += (sender, e) =>
             {
                 if (scene.RemainTime > 0)
                 {
@@ -269,14 +370,6 @@
                     delayTimeBtn.Text = CommonFormResouce.GetTimeString(t);
                 };
             };
-        }
-
-        /// <summary>
-        /// InitStatu
-        /// </summary>
-        private void InitStatu()
-        {
-            sceneImg.MouseUpEventHandler += SceneUpHandler;
         }
 
         /// <summary>
@@ -311,7 +404,7 @@
                 {
                     return;
                 }
-                CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ControlSceneFail);
+                CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.ControlSceneFail));
             }
 
             scene.RemainTime = scene.SceneDelayTime;

--
Gitblit v1.8.0