HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserCenter;
using Shared.Phone.UserView;
 
namespace Shared.Phone.MainPage
{
    /// <summary>
    /// 左滑菜单的的房间列表界面
    /// </summary>
    public class ListRoomViewFrom : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        private static ListRoomViewFrom roomManagement = null;
        /// <summary>
        /// 左滑菜单的的房间对象
        /// </summary>
        public static ListRoomViewFrom Instance
        {
            get
            {
                if (roomManagement == null)
                {
                    //初始化左滑菜单
                    roomManagement = new ListRoomViewFrom();
                    CommonPage.Instance.AddLeftView(roomManagement);
                }
                return roomManagement;
            }
        }
 
        /// <summary>
        /// 是否可以触发点击事件--是否可以跳转主页房间
        /// </summary>
        public bool CanClick = true;
        /// <summary>
        /// 是否初始化完成
        /// </summary>
        private bool isInitFinish = false;
        /// <summary>
        /// 当前楼层id
        /// </summary>
        private string curFloorId = string.Empty;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalFrameControl listView = null;
        /// <summary>
        /// 卡片控件集合
        /// </summary>
        private Dictionary<string, Controls.ListRoomCardControl> dicCardControl = new Dictionary<string, Controls.ListRoomCardControl>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示
        /// </summary>
        public void ShowForm()
        {
            //初始化头部信息
            this.InitTopFrame();
            //初始化中部控件
            this.InitBodyFrameLayout();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化头部信息
        /// </summary>
        private void InitTopFrame()
        {
            //初始化头部控件
            this.InitTopFrameLayout();
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.RoomList));
 
            //重置返回按键的事件
            var btnBack = this.GetBackButton();
            btnBack.ButtonClickEvent = null;
            btnBack.ButtonClickEvent += (sender, e) =>
            {
                //收起左菜单
                CommonPage.Instance.CloseLeftMenu();
            };
 
            //获取楼层
            this.curFloorId = Config.Instance.Home.CurrentFloorId;
 
            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(200, 69, true);
            btnFloor.Gravity = Gravity.CenterVertical;
            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(200);
            btnFloor.TextAlignment = TextAlignment.CenterRight;
            btnFloor.Text = HdlResidenceLogic.Current.GetFloorNameById(this.curFloorId);
            topFrameLayout.AddChidren(btnFloor);
 
            btnIconContr.ButtonClickEvent += (sender, e) =>
            {
                //楼层菜单
                var floors = new Category.SelectFloorForm();
                AddChidren(floors);
                floors.changeFloor = false;
                floors.CurFloorId = curFloorId;
                floors.Init(599, 161, Direction.Right);
                floors.FloorAction += (floorId) =>
                {
                    this.curFloorId = floorId;
                    btnFloor.Text = dicFloor[floorId];
                    //刷新Body容器
                    this.RefreshBodyFrame();
                };
            };
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            this.listView = new VerticalFrameControl();
            listView.Height = bodyFrameLayout.Height;
            listView.Width = bodyFrameLayout.Width;
            bodyFrameLayout.AddChidren(listView);
            //刷新Body容器
            this.RefreshBodyFrame();
        }
 
        #endregion
 
        #region ■ 刷新房间列表_______________________
 
        /// <summary>
        /// 刷新房间列表
        /// </summary>
        public void RefreshListRoom()
        {
            //如果还没有初始化完成界面的话
            if (this.isInitFinish == false)
            {
                this.ShowForm();
                this.isInitFinish = true;
                return;
            }
            //把头部也一起初始化了
            this.topFrameLayout.RemoveAll();
            //初始化头部信息
            this.InitTopFrame();
 
            //刷新Body容器
            this.RefreshBodyFrame();
        }
 
        /// <summary>
        /// 刷新Body容器
        /// </summary>
        private void RefreshBodyFrame()
        {
            //先清空
            this.listView.frameTable.RemoveAll();
            this.listView.frameTable.Height = Application.GetRealHeight(100);
            this.dicCardControl.Clear();
 
            var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(curFloorId);
            //追加我的喜爱
            listRoom.Insert(0, HdlRoomLogic.Current.GetLoveRoom());
 
            //X轴
            int XX = this.GetPictrueRealSize(43);
            //Y轴
            int YY = this.GetPictrueRealSize(58);
            //房间计数
            int roomCount = 0;
            foreach (var room in listRoom)
            {
                roomCount++;
                //初始化卡片控件
                var contr = new Controls.ListRoomCardControl();
                contr.X = XX;
                contr.Y = YY;
                listView.frameTable.AddChidren(contr);
                contr.InitControl(room);
                //加缓存
                this.dicCardControl[room.Id] = contr;
                //每两个重置X轴
                XX = roomCount % 2 == 0 ? this.GetPictrueRealSize(43) : contr.Right + this.GetPictrueRealSize(3);
                //每两个累加Y轴
                if (roomCount >= 2 && roomCount % 2 == 0)
                {
                    YY = contr.Bottom + this.GetPictrueRealSize(14);
                }
                contr.ButtonClickEvent += (sender, e) =>
                {
                    if (CanClick == false)
                    {
                        return;
                    }
                    string oldFloorId = Config.Instance.Home.CurrentFloorId;
                    CommonPage.Instance.CloseLeftMenu();
 
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        //等待控件向左移动结束
                        System.Threading.Thread.Sleep(300);
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            //点击的是收藏房间的话,不变更当前楼层id
                            if (room.FloorId != string.Empty)
                            {
                                Config.Instance.Home.CurrentFloorId = room.FloorId;
                                if (oldFloorId != room.FloorId)
                                {
                                    //楼层都切换的话,刷新整个主页
                                    UserPage.Instance.ReFreshControl();
                                    return;
                                }
                            }
                            //如果只是切换当前楼层的其他房间,则只滑动主页的滑动控件
                            HomeMainPageForm.Instance?.SetRoomPageViewSelect(room);
                        });
                    });
                };
            }
            //成员是没有未分配这个东西出来的
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //初始化未分配卡片
                this.InitRoomCardControl(XX, YY);
            }
            //调整桌布高度
            this.listView.AdjustTableHeight();
        }
 
        /// <summary>
        /// 初始化未分配卡片
        /// </summary>
        private void InitRoomCardControl(int XX, int YY)
        {
            //桌布控件
            var frameBack = new FrameLayoutStatuControl();
            frameBack.X = XX;
            frameBack.Y = YY;
            frameBack.Width = this.GetPictrueRealSize(495);
            frameBack.Height = this.GetPictrueRealSize(354);
            listView.frameTable.AddChidren(frameBack);
 
            //底部阴影效果
            var btnShadow = new NormalViewControl(frameBack.Width, frameBack.Height, false);
            btnShadow.UnSelectedImagePath = "Room/RoomCardView.png";
            frameBack.AddChidren(btnShadow, ChidrenBindMode.NotBind);
 
            //背景控件
            var picBackGroud = new NormalViewControl(this.GetPictrueRealSize(467), this.GetPictrueRealSize(311), false);
            picBackGroud.Gravity = Gravity.CenterHorizontal;
            picBackGroud.Radius = (uint)this.GetPictrueRealSize(29);
            picBackGroud.BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor3;
            frameBack.AddChidren(picBackGroud, ChidrenBindMode.BindEvent);
 
            //未分配图标
            var btnIcon = new PicViewControl(92, 72);
            btnIcon.X = this.GetPictrueRealSize(129);
            btnIcon.Y = this.GetPictrueRealSize(141);
            btnIcon.UnSelectedImagePath = "Room/NoNameRoom.png";
            frameBack.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
 
            //未分配
            var btnName = new NormalViewControl(141, 84, true);
            btnName.X = this.GetPictrueRealSize(244);
            btnName.Y = this.GetPictrueRealSize(131);
            btnName.IsBold = true;
            btnName.TextColor = UserCenterColor.Current.White;
            btnName.TextID = R.MyInternationalizationString.Unallocated;
            frameBack.AddChidren(btnName, ChidrenBindMode.BindEvent);
            frameBack.ButtonClickEvent += (sender, e) =>
            {
                if (this.CanClick == false)
                {
                    return;
                }
                //未分配
                var unalloctedRoom = new UnallocatedRoomForm();
                this.AddChidren(unalloctedRoom);
                unalloctedRoom.ShowForm();
            };
        }
 
        #endregion
 
        #region ■ 刷新指定房间_______________________
 
        /// <summary>
        /// 刷新指定房间
        /// </summary>
        /// <param name="room"></param>
        public void RefreshRoomInfo(Room room)
        {
            if (this.dicCardControl.ContainsKey(room.Id) == true)
            {
                //刷新卡片信息
                this.dicCardControl[room.Id].RefreshControl();
            }
        }
 
        #endregion
    }
}