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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 信息中心页面
    /// </summary>
    public class MessageCenterPage : FrameLayout
    {
        FrameLayout bodyView;
        /// <summary>
        /// 当前
        /// </summary>
        VerticalScrolViewLayout bodyScrolView;
        /// <summary>
        /// 内容为空提示View
        /// </summary>
        EmptyTipView emptyTipView;
 
        /// <summary>
        /// menuView
        /// </summary>
        FrameLayout menuView;
        MenuButton allMenuButton;
        MenuButton shareMenuButton;
        MenuButton alarmMenuButton;
        MenuButton systemMenuButton;
        FrameLayout messageView;
 
        /// <summary>
        /// 显示的消息类型
        /// 1全部 2分享与功能 3报警类 4系统信息
        /// </summary>
        int showMesType = 1;
        /// <summary>
        /// 推送消息列表
        /// </summary>
        List<PushMessageInfo> PushMessageInfoList = new List<PushMessageInfo>();
 
 
        /// <summary>
        /// 
        /// </summary>
        public MessageCenterPage()
        {
            bodyView = this;
            BackgroundColor = CSS_Color.BackgroundColor;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.MessageCenter)).LoadTopView();
 
            AddTopMenuView();
            AddMessageView();
            MenuButtonSelect(1);
            //TestLoad();
            GetPushMessageList();
        }
 
        /// <summary>
        /// 顶部菜单选项
        /// </summary>
        void AddTopMenuView()
        {
 
            menuView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealWidth(117),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(menuView);
 
 
            #region 全部按钮
            allMenuButton = new MenuButton()
            {
                X = Application.GetRealWidth(15),
                Y = Application.GetRealWidth(16),
            };
            menuView.AddChidren(allMenuButton);
            allMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/AllOn.png";
            allMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/All.png";
            allMenuButton.TextButton.TextID = StringId.All;
            Action allAction = () =>
            {
                MenuButtonSelect(1);
            };
            allMenuButton.SelectAction = allAction;
            #endregion
 
            #region 分享与功能
            shareMenuButton = new MenuButton()
            {
                X = allMenuButton.Right,
                Y = Application.GetRealWidth(16),
            };
            menuView.AddChidren(shareMenuButton);
            shareMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/ShareOn.png";
            shareMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/Share.png";
            shareMenuButton.TextButton.TextID = StringId.SharingAndFunctionality;
            Action shateAction = () =>
            {
                MenuButtonSelect(2);
            };
            shareMenuButton.SelectAction = shateAction;
            #endregion
 
            #region 报警类
            alarmMenuButton = new MenuButton()
            {
                X = shareMenuButton.Right,
                Y = Application.GetRealWidth(16),
            };
            menuView.AddChidren(alarmMenuButton);
            alarmMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/AlarmOn.png";
            alarmMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/Alarm.png";
            alarmMenuButton.TextButton.TextID = StringId.AlarmType;
            Action alarmAction = () =>
            {
                MenuButtonSelect(3);
            };
            alarmMenuButton.SelectAction = alarmAction;
            #endregion
 
            #region 系统信息
            systemMenuButton = new MenuButton()
            {
                X = alarmMenuButton.Right,
                Y = Application.GetRealWidth(16),
            };
            menuView.AddChidren(systemMenuButton);
            systemMenuButton.ImageButton.SelectedImagePath = "Collection/MesCenter/SystemOn.png";
            systemMenuButton.ImageButton.UnSelectedImagePath = "Collection/MesCenter/System.png";
            systemMenuButton.TextButton.TextID = StringId.SystemMessage;
            Action systemAction = () =>
            {
                MenuButtonSelect(4);
            };
            systemMenuButton.SelectAction = systemAction;
            #endregion
 
        }
 
        /// <summary>
        /// 中间信息内容
        /// </summary>
        void AddMessageView()
        {
            int messageViewY = menuView.Bottom + Application.GetRealWidth(8);
            int messageViewHeight = bodyView.Height - messageViewY;
            messageView = new FrameLayout()
            {
                Y = messageViewY,
                Height = messageViewHeight,
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(messageView);
 
            bodyScrolView = new VerticalScrolViewLayout()
            {
                Height = messageViewHeight,
            };
            messageView.AddChidren(bodyScrolView);
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="selectId">1全部 2分享与功能 3报警类 4系统信息</param>
        void MenuButtonSelect(int selectId)
        {
            showMesType = selectId;
 
            if (selectId == 1)
            {
                allMenuButton.IsSelected = true;
                shareMenuButton.IsSelected = false;
                alarmMenuButton.IsSelected = false;
                systemMenuButton.IsSelected = false;
 
            }
            else if (selectId == 2)
            {
                allMenuButton.IsSelected = false;
                shareMenuButton.IsSelected = true;
                alarmMenuButton.IsSelected = false;
                systemMenuButton.IsSelected = false;
 
            }
            else if (selectId == 3)
            {
                allMenuButton.IsSelected = false;
                shareMenuButton.IsSelected = false;
                alarmMenuButton.IsSelected = true;
                systemMenuButton.IsSelected = false;
            }
            else if (selectId == 4)
            {
                allMenuButton.IsSelected = false;
                shareMenuButton.IsSelected = false;
                alarmMenuButton.IsSelected = false;
                systemMenuButton.IsSelected = true;
 
            }
        }
 
 
 
        /// <summary>
        /// 添加内容为空提示页面
        /// </summary>
        void AddEmptyTipView()
        {
            emptyTipView = new EmptyTipView()
            {
                Gravity = Gravity.Center
            };
            messageView.AddChidren(emptyTipView);
        }
 
        /// <summary>
        /// 加载报警信息RowView
        /// </summary>
        /// <param name="VerticalScrolViewMiddle"></param>
        /// <param name="pushMessageInfo"></param>
        void AddRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, PushMessageInfo pushMessageInfo)
        {
            var rowView = new RowLayout()
            {
                Height = Application.GetRealHeight(65),
                LineColor = CSS_Color.MainBackgroundColor,
            };
            VerticalScrolViewMiddle.AddChidren(rowView);
 
            //标题
            var btnTilte = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(12),
                Width = Application.GetRealWidth(320),
                Height = Application.GetRealHeight(20),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                Text = pushMessageInfo.messageTitle
            };
            rowView.AddChidren(btnTilte);
 
            //副标题
            var btnSubtitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = btnTilte.Bottom + Application.GetRealHeight(4),
                Width = Application.GetRealWidth(240),
                Height = Application.GetRealHeight(17),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = pushMessageInfo.messageContent
            };
            rowView.AddChidren(btnSubtitle);
 
            //日期
            var btnDatetime = new Button()
            {
                X = Application.GetRealWidth(259),
                Y = btnTilte.Bottom + Application.GetRealHeight(4),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(17),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = pushMessageInfo.createTime
            };
            rowView.AddChidren(btnDatetime);
 
            var lineView = new LineView(rowView.Height);
            rowView.AddChidren(lineView);
 
            //删除按钮
            var deleteBtn = new Button()
            {
                TextID = StringId.Del,
                BackgroundColor = CSS_Color.AuxiliaryColor2,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.TextFontSize,
            };
            rowView.AddRightView(deleteBtn);
            deleteBtn.MouseUpEventHandler = (sender, e) =>
            {
                rowView.RemoveFromParent();
            };
 
            //EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            //{
            //};
 
            //btnTilte.MouseUpEventHandler = eventHandler;
            //btnSubtitle.MouseUpEventHandler = eventHandler;
        }
 
        /// <summary>
        /// 加载年份标题
        /// </summary>
        /// <param name="VerticalScrolViewMiddle"></param>
        /// <param name="yearStr"></param>
        void AddYearRowView(VerticalScrolViewLayout VerticalScrolViewMiddle, string yearStr)
        {
            var bgView = new FrameLayout()
            {
                Height = Application.GetRealHeight(57),
            };
            VerticalScrolViewMiddle.AddChidren(bgView);
 
            var yearBtn = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(16),
                Width = Application.GetRealWidth(320),
                Height = Application.GetRealHeight(33),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel,
                IsBold = true,
                Text = yearStr
            };
            bgView.AddChidren(yearBtn);
        }
 
        /// <summary>
        /// 
        /// </summary>
        void GetPushMessageList()
        {
            var waitPage = new Loading();
            waitPage.Start(Language.StringByID(StringId.PleaseWait));
            bodyScrolView.RemoveAll();
            PushMessageInfoList.Clear();
 
            new Thread(() =>
            {
                try
                {
                    var result = new HttpServerRequest().PushSerivceGetPushmessagelist();
                    if (result.Code == StateCode.SUCCESS)
                    {
                        PushMessageInfoList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PushMessageInfo>>(result.Data.ToString());
                        Application.RunOnMainThread(() =>
                        {
                            if (PushMessageInfoList != null && PushMessageInfoList.Count > 0)
                            {
 
                                ParseAndDisplayPushList();
                            }
                            else
                            {
                                AddEmptyTipView();
                            }
                        });
                    }
                    else
                    {
                        IMessageCommon.Current.ShowErrorInfoAlter(result.Code);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (waitPage != null)
                        {
                            waitPage.RemoveFromParent();
                            waitPage = null;
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 解析和显示推送消息
        /// </summary>
        void ParseAndDisplayPushList()
        {
            //
            if (showMesType == 1)
            {
 
            }
        }
 
        #region 测试
        /// <summary>
        /// 
        /// </summary>
        void TestLoad()
        {
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息",
                messageContent = "门锁被打开",
                createTime = "11月30 10:50",
            });
 
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息1",
                messageContent = "门锁被打开",
                createTime = "11月30 11:50",
            });
 
            PushMessageInfoList.Add(new PushMessageInfo()
            {
                messageTitle = "报警信息2",
                messageContent = "门锁被打开",
                createTime = "11月30 12:50",
            });
 
            AddYearRowView(bodyScrolView, "2020年");
            foreach (var info in PushMessageInfoList)
            {
                AddRowView(bodyScrolView, info);
            }
 
            AddYearRowView(bodyScrolView, "2019年");
            foreach (var info in PushMessageInfoList)
            {
                AddRowView(bodyScrolView, info);
            }
        }
        #endregion
    }
 
 
    /// <summary>
    /// 推送消息类型
    /// </summary>
    [System.Serializable]
    public class PushMessageInfo
    {
        /// <summary>
        /// 记录Id
        /// </summary>
        public string id;
        /// <summary>
        /// 是否已读
        /// </summary>
        public bool isRead;
        /// <summary>
        /// 消息内容
        /// </summary>
        public string messageContent;
        /// <summary>
        /// 扩展数据
        /// </summary>
        public string messageExpand;
        /// <summary>
        /// 消息主题
        /// </summary>
        public string messageTitle;
        /// <summary>
        /// 消息类型;0:提示;1:报警;2:丰林可是对讲呼叫;3:强制下线推送
        /// </summary>
        public string messageType;
        /// <summary>
        /// 推送Token记录Id
        /// </summary>
        public string pushId;
        /// <summary>
        /// 推送类型;0:默认;1:报警;2:提示;3:新闻;4:推荐;
        /// </summary>
        public string pushType;
        /// <summary>
        /// 推送时间
        /// </summary>
        public string createTime;
 
    }
 
}