黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
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
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 LookSharedListRoomForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalFrameControl listView = null;
        /// <summary>
        /// 成员ID
        /// </summary>
        private string ChildAccountId = string.Empty;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_memberResult">成员信息</param>
        /// <param name="i_memberShardInfo">成员的共享信息</param>
        public void ShowForm(string i_ChildAccountId)
        {
            this.ChildAccountId = i_ChildAccountId;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uShared2));
 
            //添加图标
            var btnAdd = new MostRightIconControl(69, 69);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
            btnAdd.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddNewSharedListRoomForm();
                form.AddForm(this.ChildAccountId);
            };
            topFrameLayout.AddChidren(btnAdd);
            btnAdd.InitControl();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化成员的共享列表
                var result = HdlShardLogic.Current.InitMemberShardContentListAndSetToLocation(this.ChildAccountId);
                if (result == false)
                {
                    //显示重新加载的界面
                    this.ShowReLoadView();
                    return;
                }
                //初始化区域列表
                this.InitAreaListRow();
            });
        }
 
        #endregion
 
        #region ■ 区域列表___________________________
 
        /// <summary>
        /// 初始化区域列表
        /// </summary>
        private void InitAreaListRow()
        {
            var dicShardRoom = HdlShardLogic.Current.GetShardRoomFromMemory();
            if (dicShardRoom.Count == 0)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    bodyFrameLayout.RemoveAll();
                    //还没有共享区域给成员{0}可点击右上角“+”添加
                    string msg = Language.StringByID(R.MyInternationalizationString.uNotShardComtentMsg);
                    string[] Arry = msg.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
                    this.ShowNotDataImage(bodyFrameLayout, Arry, "Item/NotShardPic.png", 383, 279);
                });
            }
            else
            {
                //合并同一楼层的房间
                var dicGroup = new Dictionary<string, List<Common.Room>>();
                foreach (var room in dicShardRoom.Values)
                {
                    if (dicGroup.ContainsKey(room.FloorId) == false)
                    {
                        dicGroup[room.FloorId] = new List<Common.Room>();
                    }
                    dicGroup[room.FloorId].Add(room);
                }
                //获取分享的楼层(排序)
                var dicSortFloor = HdlShardLogic.Current.GetShardFloorFormMemory();
                dicSortFloor = HdlRoomLogic.Current.GetFloorSortList(dicSortFloor);
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    bodyFrameLayout.RemoveAll();
 
                    this.listView = new VerticalFrameControl(29);
                    listView.Height = bodyFrameLayout.Height;
                    bodyFrameLayout.AddChidren(listView);
 
                    foreach (var floorId in dicSortFloor.Keys)
                    {
                        if (dicGroup.ContainsKey(floorId) == true)
                        {
                            //添加各自楼层的房间列表
                            this.AddRoomListRow(floorId, dicSortFloor[floorId], dicGroup[floorId]);
                            dicGroup.Remove(floorId);
                        }
                    }
                    //添加各自楼层的房间列表(这里是指定楼层并不在排序记录里面的)
                    foreach (var floorId in dicGroup.Keys)
                    {
                        this.AddRoomListRow(floorId, string.Empty, dicGroup[floorId]);
                    }
                    //调整桌布高度
                    listView.AdjustTableHeight();
                });
            }
        }
 
        /// <summary>
        /// 添加房间列表行
        /// </summary>
        /// <param name="listRoom"></param>
        private void AddRoomListRow(string floorId, string floorName, List<Common.Room> listRoom)
        {
            var frameBack = new FrameListControl(29);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Height = 10;
            this.listView.AddChidren(frameBack);
 
            //楼层
            if (string.IsNullOrEmpty(floorId) == false)
            {
                var btnFloor = new NormalViewControl(800, 60, true);
                btnFloor.X = HdlControlResourse.XXLeft;
                btnFloor.Y = Application.GetRealHeight(52);
                btnFloor.TextColor = UserCenterColor.Current.TextColor2;
                btnFloor.TextSize = 15;
                frameBack.AddChidren(btnFloor);
                if (floorName != string.Empty)
                {
                    btnFloor.Text = floorName;
                }
                else if (floorId == "Other")
                {
                    //未分配区域
                    btnFloor.Text = Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
                }
                else
                {
                    btnFloor.Text = "UnKnown";
                }
            }
            //房间排序
            var listSortRoom = HdlRoomLogic.Current.SortRoom(listRoom);
            for (int i = 0; i < listSortRoom.Count; i++)
            {
                var room = listSortRoom[i];
                var frameRow = new RowLayoutControl(frameBack.rowSpace / 2);
                frameBack.AddChidren(frameRow);
                //图标
                var btnIcon = frameRow.frameTable.AddLeftIcon(81);
                btnIcon.UnSelectedImagePath = "Item/RoomIconSelected.png";
                //名称
                var btnName = frameRow.frameTable.AddLeftCaption(room.Name, 600);
                btnName.TextSize = 15;
                //右箭头
                frameRow.frameTable.AddRightArrow();
                if (i != listSortRoom.Count - 1)
                {
                    //底线
                    frameRow.frameTable.AddBottomLine();
                }
                frameRow.frameTable.ButtonClickEvent += (sender, e) =>
                {
                    var form = new LookSharedContentForm();
                    form.AddForm(room, this.ChildAccountId);
                };
 
                //删除
                var btnDelete = new NormalViewControl(Application.GetRealWidth(184), frameRow.Height, false);
                btnDelete.BackgroundColor = 0xfff75858;
                btnDelete.TextSize = 12;
                btnDelete.TextColor = UserCenterColor.Current.White;
                btnDelete.TextAlignment = TextAlignment.Center;
                btnDelete.TextID = R.MyInternationalizationString.uDelete;
                frameRow.AddRightView(btnDelete);
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //确认删除共享房间?
                    string msg = Language.StringByID(R.MyInternationalizationString.uDeleteShardRoomMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //删除共享区域
                        this.DoDeleteShardContentByRoom(room);
                    });
                };
            }
            //调整子控件Frame高度
            this.listView.AdjustChidrenFrameHeight(frameBack, Application.GetRealHeight(29));
        }
        #endregion
 
        #region ■ 删除共享区域_______________________
 
        /// <summary>
        /// 删除共享区域
        /// </summary>
        /// <param name="room">指定要删除的共享区域</param>
        public void DoDeleteShardContentByRoom(Common.Room room)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                //执行删除
                var result = HdlShardLogic.Current.DeleteSharedRoom(this.ChildAccountId, new List<Common.Room> { room });
                if (result == true)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //重新刷新界面
                        this.InitMiddleFrame();
                    });
                }
            });
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
            return 1;
        }
 
        #endregion
    }
}