黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.SharedContent
{
    /// <summary>
    /// 配置新共享内容的主界面
    /// </summary>
    public class AddNewSharedListRoomForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 分享按钮
        /// </summary>
        private BottomClickButton btnShard = null;
        /// <summary>
        /// 成员ID
        /// </summary>
        private string ChildAccountId = string.Empty;
        /// <summary>
        /// 选择的房间
        /// </summary>
        private Dictionary<string, Common.Room> dicSelectRoom = new Dictionary<string, Common.Room>();
        /// <summary>
        /// 当前选择的楼层ID
        /// </summary>
        private string nowSelectFloorId = string.Empty;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_ChildAccountId">成员ID</param>
        public void ShowForm(string i_ChildAccountId)
        {
            this.ChildAccountId = i_ChildAccountId;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddShared));
 
            //初始化右上角的控件
            this.InitTopRightMenuControl();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(141);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
            //房间列表
            var btnTitle = new NormalViewControl(800, 60, true);
            btnTitle.X = HdlControlResourse.XXLeft;
            btnTitle.Y = Application.GetRealHeight(52);
            btnTitle.TextID = R.MyInternationalizationString.RoomList;
            btnTitle.TextColor = UserCenterColor.Current.TextColor2;
            btnTitle.TextSize = 15;
            frameBack.AddChidren(btnTitle);
 
            this.listView = new VerticalListControl(29);
            listView.Y = frameBack.Bottom;
            listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
            listView.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listView);
 
            this.btnShard = new BottomClickButton();
            btnShard.TextID = R.MyInternationalizationString.uShared2;
            bodyFrameLayout.AddChidren(btnShard);
            btnShard.Visible = false;
            btnShard.ButtonClickEvent += (sender, e) =>
            {
                var listRoom = new List<Common.Room>();
                foreach (var room in this.dicSelectRoom.Values)
                {
                    listRoom.Add(room);
                }
                //执行分享指定区域
                this.DoSharedContentByRoom(listRoom);
            };
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化区域列表
                this.InitAreaListRow(this.nowSelectFloorId);
            });
        }
 
        /// <summary>
        /// 初始化右上角的控件
        /// </summary>
        private void InitTopRightMenuControl()
        {
            //获取楼层
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            if (dicFloor.Count == 0)
            {
                return;
            }
            var btnIconContr = new MostRightIconControl(69, 69);
            btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
            topFrameLayout.AddChidren(btnIconContr);
            btnIconContr.InitControl();
 
            var btnFloor = new NormalViewControl(300, 69, true);
            btnFloor.Gravity = Gravity.CenterVertical;
            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
            btnFloor.TextAlignment = TextAlignment.CenterRight;
            topFrameLayout.AddChidren(btnFloor);
 
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                this.nowSelectFloorId = floorId;
                btnFloor.Text = dicFloor[floorId];
                break;
            }
 
            btnIconContr.ButtonClickEvent += (sender, e) =>
            {
                //楼层菜单
                var contr = new TopRightFloorMenuControl(dicFloor.Count, 2, this.nowSelectFloorId, Language.StringByID(R.MyInternationalizationString.SelectFloor));
                foreach (var floorId in dicFloor.Keys)
                {
                    contr.AddRowMenu(floorId, () =>
                    {
                        //记录起选择的ID
                        this.nowSelectFloorId = floorId;
                        btnFloor.Text = dicFloor[this.nowSelectFloorId];
                        //初始化中部信息
                        this.InitMiddleFrame();
                    });
                }
            };
        }
 
        #endregion
 
        #region ■ 区域列表___________________________
 
        /// <summary>
        /// 初始化区域列表
        /// </summary>
        /// <param name="floorId">楼层ID</param>
        private void InitAreaListRow(string floorId)
        {
            dicSelectRoom.Clear();
            var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(floorId, false);
            HdlThreadLogic.Current.RunMain(() =>
            {
                var listDataRoom = new List<Common.Room>();
                for (int i = 0; i < listRoom.Count; i++)
                {
                    //检测能否显示该房间
                    if (this.CheckCanShowRow(listRoom[i]) == true)
                    {
                        listDataRoom.Add(listRoom[i]);
                    }
                }
                for (int i = 0; i < listDataRoom.Count; i++)
                {
                    //添加房间行
                    this.AddRoomRow(listDataRoom[i], i != listDataRoom.Count - 1);
                }
 
                //调整真实高度
                listView.AdjustRealHeight(Application.GetRealHeight(23));
                if (listView.Y + listView.Height > btnShard.Y)
                {
                    //当这个列表控件的高度已经超过了【分享按钮】时,将它的高度直接扩大到最大化
                    listView.RecoverHeight();
                    //然后再添加一个空白的控件,促使它能够向上滑动
                    var frameTemp = new FrameLayout();
                    frameTemp.Height = bodyFrameLayout.Height - btnShard.Y;
                    listView.AddChidren(frameTemp);
                }
                if (listDataRoom.Count == 0)
                {
                    //如果没有能够共享的房间
                    bodyFrameLayout.RemoveAll();
                    //无可共享的房间
                    this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotCanShardRoomMsg), "Item/NotShardPic.png", 383, 279);
                }
            });
        }
 
        /// <summary>
        /// 添加房间行
        /// </summary>
        /// <param name="room"></param>
        /// <param name="addLine"></param>
        private void AddRoomRow(Common.Room room, bool addLine)
        {
            var row = new FrameRowControl(listView.rowSpace / 2);
            row.MainKeys = room.Id;
            listView.AddChidren(row);
            //图标
            var btnIcon = row.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = "Item/RoomIconSelected.png";
            //房间名
            var btnName = row.AddLeftCaption(room.Name, 650);
            btnName.TextSize = 15;
            if (addLine == true)
            {
                //底线
                row.AddBottomLine();
            }
            row.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddNewSharedContentForm();
                form.AddForm(room, this.ChildAccountId);
            };
 
            //选择
            var btnSelect = row.AddMostRightEmptyIcon(69, 69);
            btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
            btnSelect.SelectedImagePath = "Item/ItemSelected.png";
            row.ChangedChidrenBindMode(btnSelect, ChidrenBindMode.NotBind);
            btnSelect.ButtonClickEvent += (sender, e) =>
            {
                if (btnSelect.IsSelected == true)
                {
                    btnSelect.IsSelected = false;
                    dicSelectRoom.Remove(room.Id);
                    if (dicSelectRoom.Count == 0)
                    {
                        btnShard.Visible = false;
                    }
                }
                else
                {
                    btnSelect.IsSelected = true;
                    dicSelectRoom[room.Id] = room;
                    if (btnShard.Visible == false)
                    {
                        btnShard.Visible = true;
                    }
                }
            };
        }
 
        #endregion
 
        #region ■ 分享指定区域_______________________
 
        /// <summary>
        /// 执行分享指定区域
        /// </summary>
        /// <param name="room">指定要分享的房间</param>
        public void DoSharedContentByRoom(List<Common.Room> listRoom)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                //打开进度条
                this.ShowProgressBar();
                //上传分享
                var result = HdlShardLogic.Current.UploadSharedRoom(this.ChildAccountId, listRoom);
                //关闭进度条
                this.CloseProgressBar();
 
                if (result == true)
                {
                    //不刷新界面
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        if (this.Parent != null)
                        {
                            //重新刷新界面
                            this.InitMiddleFrame();
                        }
                    });
                }
            });
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
            return 1;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测该房间能否显示
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        private bool CheckCanShowRow(Common.Room room)
        {
            if (room.ListDevice.Count == 0 && room.ListSceneId.Count == 0)
            {
                return false;
            }
            if (room.IsLove == true)
            {
                return false;
            }
            if (HdlShardLogic.Current.GetShardRoomFromMemory(room.Id) == null)
            {
                //没有这个房间
                return true;
            }
            foreach (var deviceKeys in room.ListDevice)
            {
                if (HdlDeviceCommonLogic.Current.GetDevice(deviceKeys) == null)
                {
                    //本地没有这个设备
                    continue;
                }
                if (HdlShardLogic.Current.GetShardDeviceFromMemory(deviceKeys) == null)
                {
                    //存在未分享的设备的话,此房间可以显示
                    return true;
                }
            }
            foreach (var sceneId in room.ListSceneId)
            {
                if (HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId) == null)
                {
                    //本地没有这个场景
                    continue;
                }
                if (HdlShardLogic.Current.GetShardSceneFromMemory(sceneId) == null)
                {
                    //存在未分享的场景的话,此房间可以显示
                    return true;
                }
            }
            return false;
        }
 
        #endregion
    }
}