wxr
2021-05-12 9acd3887f1f8db40d59f991b1726a61aa7c7637c
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
 
    /// <summary>
    /// 房间列表
    /// </summary>
    public class SmartSpeakerRoomListPage : FrameLayout
    {
        /// <summary>
        /// bodyView
        /// </summary>
        FrameLayout bodyView;
       
        /// <summary>
        /// 当前主滑动View
        /// </summary>
        VerticalScrolViewLayout bodyScrolView;
        /// <summary>
        /// 音箱参数
        /// </summary>
        SpeakerInfo speakerInfo;
 
        /// <summary>
        /// 房间列表和无区域功能页面
        /// </summary>
        /// <param name="speakerInfo">音箱参数</param>
        public SmartSpeakerRoomListPage(SpeakerInfo speakerInfo)
        {
            bodyView = this;
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            this.speakerInfo = speakerInfo;
        }
 
        /// <summary>
        /// 加载视图
        /// </summary>
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.DataManagement)).LoadTopView();
 
            int bodyY = Application.GetRealHeight(64);
            bodyScrolView = new VerticalScrolViewLayout()
            {
                Y = bodyY,
                Height = bodyView.Height - bodyY,
                BackgroundColor = CSS_Color.BackgroundColor,
 
            };
            bodyView.AddChidren(bodyScrolView);
 
            //加载房间列表
            ShowRoomListView();
        }
 
        /// <summary>
        /// 加载房间列表
        /// </summary>
        void ShowRoomListView()
        {
            bodyScrolView.RemoveAll();
 
            var titleView = new FrameLayout()
            {
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Height = Application.GetRealWidth(53),
            };
            bodyScrolView.AddChidren(titleView);
            //箭头图标
            var btnResidenceDownIcon = new Button()
            {
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                X = Application.GetRealWidth(12),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Public/DownIcon.png",
            };
            titleView.AddChidren(btnResidenceDownIcon);
            //住宅标题
            var btnHomeTitle = new Button()
            {
                X = btnResidenceDownIcon.Right + Application.GetRealWidth(1),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = DB_ResidenceData.Instance.CurrentRegion.Name,
            };
            titleView.AddChidren(btnHomeTitle);
 
            //var btnLine = new Button()
            //{
            //    X = Application.GetRealWidth(16),
            //    Y = titleView.Height - Application.GetRealHeight(2),
            //    Width = Application.GetRealWidth(360),
            //    Height = Application.GetRealHeight(1),
            //    BackgroundColor = CSS_Color.DividingLineColor,
            //};
            //titleView.AddChidren(btnLine);
 
            //---------------------------------------------
            //未分配区域的功能
            List<Function> allFunctionList = FunctionList.List.GetDeviceFunctionList();
            //未分配区域的功能
            List<Function> unallocatedList = new List<Function>();
            //
            foreach (var function in allFunctionList)
            {
                function.roomIds.Remove(null);
                if (function.roomIds.Count == 0)
                {
                    unallocatedList.Add(function);
                }
            }
 
            //所有场景
            List<Scene> allSceneList = FunctionList.List.scenes;
            //全局场景场景
            List<Scene> globalSceneList = new List<Scene>();
            //找出所有的全局场景
            foreach (var mScene in allSceneList)
            {
 
                //roomIds大于0 代表分配到房间
                mScene.roomIds.Remove(null);
                if (mScene.roomIds.Count == 0)
                {
                    globalSceneList.Add(mScene);
                }
            }
 
 
            try
            {
                //房间列表
                foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
                {
                    AddRoomFunctionRowLayout(room);
                }
                //2020-12-16 加载未分配区域功能RowLayout
                AddNoAreaFunctionRowLayout(unallocatedList, globalSceneList);
            }
            catch
            {
                Utlis.WriteLine("AddRoomFunctionRowLayout error");
            }
        }
 
 
        /// <summary>
        /// 添加房间列表
        /// </summary>
        /// <param name="mRoom"></param>
        void AddRoomFunctionRowLayout(Room mRoom)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null, null);
        }
 
        /// <summary>
        /// 添加无区域的功能
        /// </summary>
        /// <param name="unallocatedList">未分配的所有功能列表</param>
        /// <param name="globalSceneList">全区域的场景</param>
        void AddNoAreaFunctionRowLayout(List<Function> unallocatedList, List<Scene> globalSceneList)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList, globalSceneList);
        }
 
        /// <summary>
        /// 2020-12-17 重新调整
        /// 添加房间分享或者无区域分配 个数统计状态的RowLayout
        /// </summary>
        /// <param name="room">如果房间为空,代表管理无分配区域</param>
        /// <param name="unallocatedList">管理无分配区域才有效</param>
        /// <param name="globalSceneList">全局场景</param>
        void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List<Function> unallocatedList, List<Scene> globalSceneList)
        {
            /// 房间所有功能和者场景列表
            List<SpeakerTargetInfo> roomFunctionOrSceneList = new List<SpeakerTargetInfo>();
 
            var roomView = new RowLayout()
            {
                Height = Application.GetRealWidth(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                LineColor = CSS_Color.MainBackgroundColor,
            };
            bodyScrolView.AddChidren(roomView);
 
            var btnRoomName = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealWidth(10),
                Width = Application.GetRealWidth(330),
                Height = Application.GetRealWidth(30),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                //Text = room.roomName,
            };
            roomView.AddChidren(btnRoomName);
 
            var btnRight = new Button()
            {
                X = Application.GetRealWidth(351),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            roomView.AddChidren(btnRight);
 
            //如果房间为空,代表管理无分配区域
            if (mRoom != null)
            {
                //显示房间名
                btnRoomName.Text = mRoom.roomName;
                var mRoomFunctionList = mRoom.GetRoomFunctions(false);
                var mRoomSceneList = mRoom.GetRoomScenes(true);
                //遍历所有功能列表
                if (mRoomFunctionList != null)
                {
                    foreach (var fun in mRoomFunctionList)
                    {
                        roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
                        {
                            targetId = fun.deviceId,
                            targetName = fun.name,
                            isDevice = true
                        });
                    }
                }
 
                //遍历所有场景列表
                if (mRoomSceneList != null)
                {
                    foreach (var roomScene in mRoomSceneList)
                    {
                        roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
                        {
                            targetId = roomScene.userSceneId,
                            targetName = roomScene.name,
                            isDevice = false
                        });
                    }
                }
 
                //roomId = mRoom.roomId;
                //添加分割线
                var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
                roomView.AddChidren(lineView);
            }
            else
            {
                //显示无区域功能
                btnRoomName.TextID = StringId.NoAreaFunction;
 
                //遍历所有功能列表
                if (unallocatedList != null)
                {
                    foreach (var fun in unallocatedList)
                    {
                        roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
                        {
                            targetId = fun.deviceId,
                            targetName = fun.name,
                            isDevice = true
                        });
                    }
                }
 
                //遍历所有场景列表
                if (globalSceneList != null)
                {
                    foreach (var roomScene in globalSceneList)
                    {
                        roomFunctionOrSceneList.Add(new SpeakerTargetInfo()
                        {
                            targetId = roomScene.userSceneId,
                            targetName = roomScene.name,
                            isDevice = false
                        });
                    }
                }
            }
 
          
            //点击调整事件
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                var page = new SmartSpeakerSelectDevicesPage(speakerInfo, roomFunctionOrSceneList);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            roomView.MouseUpEventHandler = eHandler;
            btnRoomName.MouseUpEventHandler = eHandler;
            btnRight.MouseUpEventHandler = eHandler;
          
        }
 
    }
 
 
 
}