黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
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
using System;
using System.Collections.Generic;
using Shared.Common;
 
namespace Shared.Phone.Device.Account
{
    public class PhoneZone : FrameLayout
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// 选择的区号
        /// </summary>
        public Action<string> ActionSelectedZone;
        /// <summary>
        /// *****升级分布式后,Account 仅包含手机号,不再包含00区号。密码不再需要MD5加密。language为APP语
        /// 下来选择手机区号 默认中国大陆为86
        ///发送国际 / 港澳台消息时,接收号码格式为00 + 国际区号 + 号码,如“008615899998888”   调用API时,Company字段请传入整型值:4。 。
        ///国内  调用API时,Company字段请传入整型值:0。
        /// </summary>
        public List<Common.ResponseEntity.AreaCodeOBJ> areaCodeList = new List<Common.ResponseEntity.AreaCodeOBJ>();
        /// <summary>
        /// 选择区号视图
        /// </summary>
        private FrameLayout phoneZoneSelectedShowView;
        /// <summary>
        /// 区号视图
        /// </summary>
        private VerticalScrolViewLayout phoneZoneListView;
        /// <summary>
        /// tempClickZoneCodeBtn
        /// </summary>
        Button tempClickZoneCodeBtn = new Button();
        /// <summary>
        /// tempClickZoneNameBtn
        /// </summary>
        Button tempClickZoneNameBtn = new Button();
        /// <summary>
        /// tempClickZoneItemFL
        /// </summary>
        FrameLayout tempClickZoneItemFL = new FrameLayout();
        #endregion
        /// <summary>
        /// PhoneZone
        /// </summary>
        public PhoneZone()
        {
 
        }
        /// <summary>
        /// Show
        /// </summary>
        public void Show()
        {
            Init();
        }
        /// <summary>
        /// Init
        /// </summary>
        private void Init()
        {
            CommonPage.Loading.Start();
            ShowZoneList();
            new System.Threading.Thread(async () =>
            {
                var zoneList = await GetZoneListAsync();
                if (zoneList == null)
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Hide();
 
                    });
                }
                else
                {
                    Application.RunOnMainThread(() =>
                    {
                        foreach (var areaCode in zoneList)
                        {
                            AddZone(areaCode, phoneZoneListView);
                        }
                        CommonPage.Loading.Hide();
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// GetZoneListAsync
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task<List<Common.ResponseEntity.AreaCodeOBJ>> GetZoneListAsync()
        {
            try
            {
                var requestOBJ = new SendDataToServer.GetAreaCodeOBJ()
                {
                    RequestVersion = CommonPage.RequestVersion
                };
                var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestOBJ);
                var revertOBJ = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/GetAreaCode", System.Text.Encoding.UTF8.GetBytes(requestJson));
                if (revertOBJ == null)
                {
                    return null;
                }
                if (revertOBJ.StateCode.ToUpper() == "SUCCESS")
                {
 
                    var responseData = revertOBJ.ResponseData;
                    return Newtonsoft.Json.JsonConvert.DeserializeObject<List<Common.ResponseEntity.AreaCodeOBJ>>(responseData.ToString());
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// ShowZoneList
        /// </summary>
        private void ShowZoneList()
        {
            //ZoneListView
            var phoneZoneDialog = new FrameLayout()
            {
                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
            };
            AddChidren(phoneZoneDialog);
 
            phoneZoneSelectedShowView = new FrameLayout()
            {
                Height = Application.GetRealHeight(1342),
                Width = Application.GetRealWidth(850),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                Radius = (uint)Application.GetRealHeight(30),
                Gravity = Gravity.Center
            };
            phoneZoneDialog.AddChidren(phoneZoneSelectedShowView);
 
            var phoneZoneTitle = new Button()
            {
                X = Application.GetRealWidth(CommonPage.XLeft),
                Y = Application.GetRealHeight(69),
                Height = Application.GetRealHeight(60),
                Width = Application.GetRealWidth(250),
                TextID = R.MyInternationalizationString.PleaseSelectAreaCode,
                TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor,
                TextAlignment = TextAlignment.CenterLeft
            };
            phoneZoneSelectedShowView.AddChidren(phoneZoneTitle);
 
            var searchBorder = new FrameLayout()
            {
                X = phoneZoneTitle.Right + Application.GetRealWidth(CommonPage.XLeft),
                Y = Application.GetRealHeight(46),
                Height = Application.GetRealHeight(104),
                Width = Application.GetRealWidth(400),
                BorderWidth = 1,
                BorderColor = ZigbeeColor.Current.GXCBorderColor,
                Radius = (uint)Application.GetRealHeight(46 / 2)
            };
            phoneZoneSelectedShowView.AddChidren(searchBorder);
 
            var phoneZoneSearch = new EditText()
            {
                X = phoneZoneTitle.Right + Application.GetRealWidth(CommonPage.XLeft + 10),
                Y = Application.GetRealHeight(46),
                Height = Application.GetRealHeight(104),
                Width = Application.GetRealWidth(400),
                PlaceholderText = Language.StringByID(R.MyInternationalizationString.Search),
                PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextColor = ZigbeeColor.Current.GXCTextDeepBlackColor
            };
            phoneZoneSelectedShowView.AddChidren(phoneZoneSearch);
 
            phoneZoneListView = new VerticalScrolViewLayout()
            {
                Y = phoneZoneSearch.Bottom + Application.GetRealHeight(10),
                Height = Application.GetRealHeight(986),
            };
            phoneZoneSelectedShowView.AddChidren(phoneZoneListView);
 
            var okBtn = new CommonForm.CompleteButton(1166, 668, 127);
            phoneZoneSelectedShowView.AddChidren(okBtn);
            okBtn.MouseUpEventHandler += (sender, e) =>
            {
                ActionSelectedZone?.Invoke(CommonPage.PhoneZoneStr);
                ActionSelectedZone = null;
                RemoveFromParent();
            };
            phoneZoneSelectedShowView.AddChidren(okBtn);
            var cancleBtn = new Button()
            {
                Y = Application.GetRealHeight(1719),
                Height = Application.GetMinRealAverage(86),
                Width = Application.GetMinRealAverage(86),
                UnSelectedImagePath = "Account/Cancle.png",
                Gravity = Gravity.CenterHorizontal
            };
            phoneZoneDialog.AddChidren(cancleBtn);
 
            cancleBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
        }
        /// <summary>
        /// AddZone
        /// </summary>
        /// <param name="areaCode"></param>
        /// <param name="phoneZoneSelectedListView"></param>
        private void AddZone(Common.ResponseEntity.AreaCodeOBJ areaCode, VerticalScrolViewLayout phoneZoneSelectedListView)
        {
            var zoneItemLName = areaCode.Name;
            var zoneItemLCode = areaCode.Code;
            var zoneItemFL = new FrameLayout()
            {
                Width = phoneZoneSelectedListView.Width,
                Height = Application.GetRealHeight(110),
            };
            phoneZoneSelectedListView.AddChidren(zoneItemFL);
 
            var zoneItemNameBtn = new Button()
            {
                X = Application.GetRealWidth(58),
                Width = zoneItemFL.Width - Application.GetRealWidth(300),
                Height = Application.GetRealHeight(110) - 1,
                Text = zoneItemLName,
                TextColor = ZigbeeColor.Current.GXCTextColor,
                SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
            };
            zoneItemFL.AddChidren(zoneItemNameBtn);
 
            var zoneCode = new Button()
            {
                X = Application.GetRealWidth(58) + zoneItemNameBtn.Right,
                Width = Application.GetRealWidth(150),
                Height = Application.GetRealHeight(80),
                Gravity = Gravity.CenterVertical,
                Text = $"+{zoneItemLCode}",
                TextAlignment = TextAlignment.CenterRight,
                TextColor = ZigbeeColor.Current.GXCTextColor,
                SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor,
            };
            zoneItemFL.AddChidren(zoneCode);
 
            EventHandler<MouseEventArgs> selectedZone = (sender, e) =>
            {
                tempClickZoneCodeBtn.IsSelected = false;
                tempClickZoneNameBtn.IsSelected = false;
                tempClickZoneItemFL.BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
                zoneItemNameBtn.IsSelected = true;
                zoneCode.IsSelected = true;
                tempClickZoneCodeBtn = zoneCode;
                tempClickZoneNameBtn = zoneItemNameBtn;
                tempClickZoneItemFL = zoneItemFL;
                zoneItemFL.BackgroundColor = ZigbeeColor.Current.GXCRowSelectedColor;
                CommonPage.PhoneZoneStr = zoneItemLCode;
            };
 
            zoneCode.MouseUpEventHandler += selectedZone;
            zoneItemNameBtn.MouseUpEventHandler += selectedZone;
            //默认
            if (zoneItemLCode == CommonPage.PhoneZoneStr)
            {
                zoneItemNameBtn.IsSelected = true;
                zoneCode.IsSelected = true;
                zoneItemFL.BackgroundColor = ZigbeeColor.Current.GXCRowSelectedColor;
                tempClickZoneCodeBtn = zoneCode;
                tempClickZoneNameBtn = zoneItemNameBtn;
                tempClickZoneItemFL = zoneItemFL;
            }
        }
    }
}