JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using System.Net;
 
namespace Shared.SimpleControl.Phone
{
    public class WarningList : FrameLayout
    {
        //public void ShowWarningListPage ()
        //{
        //    System.Threading.Tasks.Task.Factory.StartNew (() => {
        //        RemoteInfo.Current.ReadMsgList ();
        //        Application.RunOnMainThread (() => {
        //            ShowWarningListPage1 ();
        //        });
        //    });
        //}
 
        public void ShowWarningListPage ()
        {
            RemoveAll ();
            FrameLayout bodyView = new FrameLayout () {
                BackgroundColor = SkinStyle.Current.MainColor
            };
            AddChidren (bodyView);
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            bodyView.AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                TextID = R.MyInternationalizationString.MessageAlert,
                TextSize = 19,
                TextColor = SkinStyle.Current.TextColor1,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
            };
            Button btnNullLine = new Button () {
                Y = Application.GetRealHeight (90) - 1,
                Height = 1,
                BackgroundColor = SkinStyle.Current.White20Transparent,
            };
            topView.AddChidren (btnNullLine);
 
            #endregion
            VerticalScrolViewLayout msgView = new VerticalScrolViewLayout () {
                Y = topView.Bottom,
                Height = Application.GetRealHeight (Application.DesignHeight - 90 - 90 - 36),
                BackgroundColor = SkinStyle.Current.ViewColor,
            };
            bodyView.AddChidren (msgView);
            for (int i = RemoteInfo.Current.RemoteInfoList.Count; i > 0; i--) {
                var msg = RemoteInfo.Current.RemoteInfoList [i - 1];
                var rol = new RowLayout () {
                    Height = Application.GetRealHeight (130),
                };
                msgView.AddChidren (rol);
                Button btnIcon = new Button () {
                    X = Application.GetRealWidth (15),
                    Y = Application.GetRealHeight (10),
                    Width = Application.GetMinRealAverage (105),
                    Height = Application.GetMinRealAverage (105),
                    UnSelectedImagePath = "RemoteMsg/RemoteMsg.png",
                    SelectedImagePath = "RemoteMsg/RemoteWarining.png",
                    IsSelected = msg.MsgType == "警报" ? true : false,
                    Enable = false,
                };
                rol.AddChidren (btnIcon);
 
                var btnMsg = new Button () {
                    X = btnIcon.Right,
                    Width = Application.GetRealWidth (620) - btnIcon.Right,
                    Height = Application.GetRealHeight(130 - 40),
                    //Text = "警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报警报1",
                    Text = msg.Msg,
                    TextAlignment = TextAlignment.CenterLeft,
                    IsMoreLines = true,
                    TextColor = SkinStyle.Current.TextColor1
                };
                rol.AddChidren (btnMsg);
                var msgStringBytes = System.Text.Encoding.UTF8.GetBytes (btnMsg.Text).Length;
                if (msgStringBytes > 230) {
                    btnMsg.TextSize = 10;
                } else if (msgStringBytes > 150) {
                    btnMsg.TextSize = 12;
                } else if (msgStringBytes > 60) {
                    btnMsg.TextSize = 14;
                }
 
                //var msgTime = msg.MsgTime.ToLocalTime ();
                var btnDate = new Button () {
                    Y = Application.GetRealHeight (100),
                    Width = Application.GetRealWidth (620),
                    TextAlignment = TextAlignment.CenterRight,
                    Height = Application.GetRealHeight (30),
                    Text = msg.MsgTime.ToLocalTime ().ToShortDateString () + " " + msg.MsgTime.ToLocalTime ().ToShortTimeString (),
                    TextColor = SkinStyle.Current.TextColor1
                };
                rol.AddChidren (btnDate);
 
                Button btnDel = new Button () {
                    TextID = R.MyInternationalizationString.Del,
                    BackgroundColor = SkinStyle.Current.DelColor,
                    Tag = msg
                };
                rol.AddRightView (btnDel);
                btnDel.MouseUpEventHandler += (sender, e) => {
                    RemoteInfo.Current.Del ((RemoteInfoMsg)(((Button)sender).Tag));
                    ShowWarningListPage ();
                };
            }
 
            FrameLayout bottomView = new FrameLayout () {
                Y = Application.GetRealHeight (Application.DesignHeight - 90),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            bodyView.AddChidren (bottomView);
 
            Button btnCl = new Button () {
                TextID = R.MyInternationalizationString.ClearInformation,
                TextSize = 14,
                TextColor = SkinStyle.Current.TextColor1,
            };
            bottomView.AddChidren (btnCl);
            btnCl.MouseUpEventHandler += (sender, e) => {
                Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
                                        Language.StringByID (R.MyInternationalizationString.ClearInformationTip),
                                        Language.StringByID (R.MyInternationalizationString.Cancel),
                                        Language.StringByID (R.MyInternationalizationString.Confrim));
                alert.Show ();
                alert.ResultEventHandler += (sender1, e1) => {
                    if (e1) {
                        System.Threading.Tasks.Task.Factory.StartNew (() => {
                            string jsonString = "{" +
                                              "\"RegID\":" + "\"" + UserConfig.Instance.tokenID + "\"" + "," +
                                                   "}";
                            var revertObj = MainPage.RequestHttps ($"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/ClearMessage", jsonString, true);
                        });
                        RemoteInfo.Current.CleanAll ();
                        ShowWarningListPage ();
                    }
                };
            };
        }
    }
}