CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2022-11-01 dc14dbad8e3a55b57cadddba40c3f437e5e80fc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using System;
using System.Collections.Generic;
//using EZMonitor;
 
namespace Shared.SimpleControl.Phone
{
    /// <summary>
    /// 用户场景界面
    /// </summary>
    public class UserScenePage : FrameLayout
    {
        public static readonly VerticalScrolViewLayout VerticalScrolView_InUserMiddleView = new VerticalScrolViewLayout ();
        Button beforeClickButton = new Button ();
        FrameLayout LongPressFrameLayout = new FrameLayout ();
 
        /// <summary>
        ///构造函数
        /// </summary>
        public UserScenePage (UserDeviceToScene mView)
        {
            mUserDeviceToScene = mView;
            BackgroundColor = SkinStyle.Current.MainColor;
        }
 
        UserDeviceToScene mUserDeviceToScene;
        public override void RemoveFromParent ()
        {
            mUserDeviceToScene.InitView (UserConfig.Instance.SceneOfGloba);
            base.RemoveFromParent ();
        
        }
 
        public void ShowUserScene (Room room)
        {
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            AddChidren (topView);
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID (R.MyInternationalizationString.Scenes),
                TextSize = 19,
                TextColor = SkinStyle.Current.TextColor1,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
            };
            #endregion 
 
            #region bodyView
            FrameLayout bodyView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = LayoutParams.MatchParent,
                Y = topView.Bottom,
                BackgroundColor = SkinStyle.Current.ViewColor
            };
            AddChidren (bodyView);
 
            VerticalScrolViewLayout scenesBodyView = new VerticalScrolViewLayout () {
                Width = LayoutParams.MatchParent,
                Height = LayoutParams.MatchParent,
            };
            bodyView.AddChidren (scenesBodyView);
 
 
            FrameLayout scenesRowView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (254),
            };
 
            //显示每个房间有多少个场景
            if (room != null) {
                //所有场景
                var sceneFileList = room.SceneFilePathList;
                List<string> sceneFilePaths = new List<string> ();//存路径
                sceneFilePaths = sceneFileList;
                sceneFilePaths.Add ("");
 
                for (int index = 0; index < sceneFilePaths.Count; index++) {
                    var sceneFilePath = sceneFilePaths [index];
                    var scene = Scene.GetSceneByFilePath (sceneFilePath);
                    // 当场景不存在时,可以NEW 一个场景,不然值一直是空的
 
                    if (scene == null) {
                        scene = new Scene ();
                    }
 
                    if (index % 2 == 0) {
                        scenesRowView = new FrameLayout () {
                            Height = Application.GetRealHeight (250),
                        };
                        scenesBodyView.AddChidren (scenesRowView);
                    }
 
                    var sceneView = new FrameLayout () {
                        Width = Application.GetRealWidth (320),
                        BackgroundImagePath = scene.BackgroundImagePath,
                    };
                    scenesRowView.AddChidren (sceneView);
 
                    if (index % 2 == 1) {
                        sceneView.X = Application.GetRealWidth (320);
                    }
 
                    if (index == sceneFilePaths.Count - 1) {
                        sceneView.BackgroundImagePath = "Item/SceneAdd.png";
                        sceneView.MouseUpEventHandler += (sender, e) => {
                            Action ShowUserSceneForFileName = () => {
                                ShowUserScene (Room.GetRoomByFilePath ( room.RoomFilePath));
                            };
                            new ScenePhoneMethod ().AddOrUpdataSceneBaseMassage (room.RoomFilePath,null, null, ShowUserSceneForFileName);
                        };
                    } else {
                        Button btnSceneName = new Button () {
                            Height = Application.GetRealHeight (40),
                            Y = Application.GetRealHeight (210),
                            BackgroundColor = SkinStyle.Current.Black50Transparent,
                        };
                        sceneView.AddChidren (btnSceneName);
 
                        var btnBGC = new Button () {
                            UnSelectedImagePath = "Item/Transparent.png",
                            SelectedImagePath = "Item/SceneSettingBackground.png",
                            TextAlignment = TextAlignment.BottomCenter,
                            Text = scene.Name,
                            TextColor = SkinStyle.Current.TextColor1,
                            TextSize = 15,
                        };
                        sceneView.AddChidren (btnBGC);
 
                        var btnSetSceneIcon = new Button () {
                            UnSelectedImagePath = "Item/More2.png",
                            SelectedImagePath = "Item/Transparent.png",
                            Height = Application.GetRealHeight (50),
                            Width = Application.GetRealWidth (60),
                            X = Application.GetRealWidth(240),
                            Y = Application.GetRealHeight(10),
                        };
 
 
                        sceneView.AddChidren (btnSetSceneIcon);
                        //btnBGC.MouseLongEventHandler += (sender, e) => {
                        btnSetSceneIcon.MouseUpEventHandler += (sender, e) => {
                            if (string.IsNullOrEmpty (scene.Name))
                                return;
                            btnSetSceneIcon.IsSelected = true;
                            LongPressFrameLayout = new FrameLayout () {
                                BackgroundColor = SkinStyle.Current.SceneTransparentBackColor,
                            };
                            LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
                                LongPressFrameLayout.RemoveFromParent ();
                                btnSetSceneIcon.IsSelected = false;
                            };
                            sceneView.AddChidren (LongPressFrameLayout);
 
                            var btnEditor = new Button () {
                                Width = Application.GetRealWidth (70),
                                Height = Application.GetRealHeight (76),
                                UnSelectedImagePath = "Item/UserSceneEditIcon.png",
                                X = Application.GetRealWidth (220),
                                Y = Application.GetRealHeight (13),
                            };
                            LongPressFrameLayout.AddChidren (btnEditor);
                            btnEditor.MouseUpEventHandler += (sender1, e1) => {
                                var userAddSceneDeviceView = new UserAddSceneDevice ( room.RoomFilePath, sceneFilePath);
                                UserMiddle.DevicePageView.AddChidren (userAddSceneDeviceView);
                                userAddSceneDeviceView.ShowScene ((newSceneFilePath) => {
                                    sceneFilePath = newSceneFilePath;
                                    scene = Scene.GetSceneByFilePath (sceneFilePath);
                                    sceneView.BackgroundImagePath = scene.BackgroundImagePath;
                                ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath));
                                    UserDeviceToScene.hasModify = true;
                                });
                                UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
                                LongPressFrameLayout.RemoveFromParent ();
                            };
 
                            var btnDel = new Button () {
                                Width = Application.GetRealWidth (70),
                                Height = Application.GetRealHeight (76),
                                UnSelectedImagePath = "Item/UserSceneDelIcon.png",
                                X = Application.GetRealWidth (40),
                                Y = Application.GetRealHeight (20),
                            };
                            LongPressFrameLayout.AddChidren (btnDel);
 
                            btnDel.MouseUpEventHandler += (senderDel, eDel) => {
                                Alert alert = new Alert ("", $"Are you sure to delete the scenario: {scene.Name}?", Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
                                alert.ResultEventHandler += (sender2, e2) => {
                                    if (e2) {
                                        IO.FileUtils.DeleteFile (sceneFilePath);
                                        room.SceneFilePathList.Remove (sceneFilePath);
                                        room.SceneFilePathList.Remove ("");
                                        room.Save (room.RoomFilePath);
                                        ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath));
                                        UserDeviceToScene.hasModify = true;
                                    }
                                };
                                alert.Show ();
 
 
                                
                                //if (CommonList.MonitorScenePathList.Count > 0) {
                                //    foreach (var monitorData in CommonList.MonitorScenePathList) {
                                //        if (sceneFilePath == monitorData.FileName) {
                                //            CommonList.MonitorScenePathList.Remove (monitorData);
                                //            CommonList.Save ();
                                //        }
                                //    }
                                //}
                            };
                        };
 
                        btnBGC.MouseUpEventHandler += (sender, e) => {
                            LongPressFrameLayout.RemoveFromParent ();
                            beforeClickButton.IsSelected = false;
                            beforeClickButton = btnBGC;
                            btnBGC.IsSelected = true;
                            new ScenePhoneMethod ().ControlScene (sceneFilePath);                        
                        };
                    }
                }
                sceneFileList.Remove ("");
            }
            #endregion
        }
    }
}