黄学彪
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
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 编辑胁迫密码的界面
    /// </summary>
    public class CoercePswEditorForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 用户账号
        /// </summary>
        private int pswNo = 5;
        /// <summary>
        /// 密码
        /// </summary>
        private string password = string.Empty;
        /// <summary>
        /// 密码提示
        /// </summary>
        private string passwordTip = string.Empty;
        /// <summary>
        /// 联系人的列表控件
        /// </summary>
        private FrameListControl listPhoneView = null;
        /// <summary>
        /// 信息控件
        /// </summary>
        private InformationEditorControl tableContr = null;
        /// <summary>
        /// 密码控件
        /// </summary>
        private NormalViewControl btnPassword = null;
        /// <summary>
        /// 当前的联系人列表
        /// </summary>
        private List<ZigBee.Device.Safeguard.PushTargetInfo> listPhoneData = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_password">用户密码</param>
        /// <param name="i_passwordTip">用户密码提示</param>
        public void ShowForm(string i_password, string i_passwordTip)
        {
            this.password = i_password;
            this.passwordTip = i_passwordTip;
            this.ScrollEnabled = false;
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCoercePassword));
 
            //初始化中部信息
            this.InitMiddleFrame(i_password);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        /// <param name="i_password">用户密码</param>
        private void InitMiddleFrame(string i_password)
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var listBackControl = new VerticalFrameControl();
            listBackControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBackControl);
 
            var frameback = new FrameLayout();
            frameback.Y = Application.GetRealHeight(179);
            frameback.Height = Application.GetRealHeight(395);
            frameback.Width = Application.GetRealWidth(717);
            frameback.Gravity = Gravity.CenterHorizontal;
            frameback.BackgroundImagePath = "Safeguard/SafeguardPasswordGround.png";
            listBackControl.frameTable.AddChidren(frameback);
            //当前使用密码
            var btnNowTip = new NormalViewControl(frameback.Width, Application.GetRealHeight(50), false);
            btnNowTip.Y = Application.GetRealHeight(81);
            btnNowTip.TextSize = 12;
            btnNowTip.TextAlignment = TextAlignment.Center;
            btnNowTip.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnNowTip.TextID = R.MyInternationalizationString.uNowUsePassword;
            frameback.AddChidren(btnNowTip);
            this.btnPassword = new NormalViewControl(frameback.Width, Application.GetRealHeight(90), false);
            btnPassword.TextAlignment = TextAlignment.Center;
            btnPassword.Y = Application.GetRealHeight(150);
            btnPassword.TextSize = 24;
            btnPassword.TextColor = 0xfffc744b;
            btnPassword.Text = i_password;
            btnPassword.IsBold = true;
            frameback.AddChidren(btnPassword);
 
            //初始化列表控件
            this.InitListViewControl(listBackControl);
        }
 
        /// <summary>
        /// 初始化列表控件
        /// </summary>
        private void InitListViewControl(VerticalFrameControl listBackControl)
        {
            //初始化桌布
            this.tableContr = new InformationEditorControl();
            var listView = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1025);
 
            //备注信息
            string caption = Language.StringByID(R.MyInternationalizationString.uNoteInformation);
            var rowNote = new FrameCaptionInputControl(caption, passwordTip, listView.rowSpace / 2);
            rowNote.txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPlesaeInputNoteInformation);
            rowNote.txtInput.MaxByte = 90;
            listView.AddChidren(rowNote);
            rowNote.InitControl();
            rowNote.AddBottomLine();
            rowNote.txtInput.FinishInputEvent += async () =>
            {
                if (rowNote.Text == string.Empty)
                {
                    rowNote.Text = passwordTip;
                    return;
                }
                if (passwordTip != rowNote.Text)
                {
                    //修改密码备注
                    await this.EditorPassworTip(password, rowNote.Text, true);
                }
            };
 
            //修改密码
            var rowPsw = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(rowPsw);
            rowPsw.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uChangedPassword), 300);
            rowPsw.AddRightArrow();
            rowPsw.AddBottomLine();
            rowPsw.ButtonClickEvent += (sender, e) =>
            {
                var form = new CoercePswAddNewForm();
                form.AddForm(rowNote.Text);
                form.PasswordChangedEvent += (newPassword) =>
                {
                    this.btnPassword.Text = newPassword;
                    this.password = newPassword;
                };
            };
 
            //初始化联系人控件
            this.InitPhoneControl(listView);
 
            //重写底层的返回按键事件
            this.BackButtonClickEvent = async (sender) =>
             {
                 sender.CanClick = false;
                 if (rowNote.Text == string.Empty || passwordTip == rowNote.Text)
                 {
                     this.CloseForm();
                 }
                 else
                 {
                     //修改密码备注
                     var result = await this.EditorPassworTip(password, rowNote.Text, false);
                     sender.CanClick = true;
                     if (result == true)
                     {
                         this.CloseForm();
                     }
                 }
             };
        }
 
        #endregion
 
        #region ■ 初始化联系人控件___________________
 
        /// <summary>
        /// 初始化联系人控件
        /// </summary>
        private void InitPhoneControl(FrameListControl listTableView)
        {
            //联系人的列表控件
            if (listPhoneView == null)
            {
                this.listPhoneView = new FrameListControl();
                listPhoneView.rowSpace = listTableView.rowSpace;
                listPhoneView.Height = Application.GetRealHeight(200);
                listTableView.AddChidren(listPhoneView);
                listPhoneView.Y -= listTableView.rowSpace;
            }
            else
            {
                this.listPhoneView.RemoveAll();
            }
 
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //开启进度条
                this.ShowProgressBar();
                //获取联系方式
                var result = await HdlSafeguardLogic.Current.GetCoercePhoneNumber();
                if (result == null)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.listPhoneData = new List<ZigBee.Device.Safeguard.PushTargetInfo>();
                    //联系人
                    var rowContact = new FrameRowControl(this.listPhoneView.rowSpace / 2);
                    rowContact.UseClickStatu = false;
                    listPhoneView.AddChidren(rowContact);
                    rowContact.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uContactPersion), 300);
                    var btnAdd = rowContact.AddMostRightEmptyIcon(81, 81);
                    btnAdd.UnSelectedImagePath = "Item/Add.png";
                    rowContact.ButtonClickEvent += (sender, e) =>
                    {
                        var form = new CoercePswAddContactForm();
                        form.AddForm(listPhoneData);
                        form.AddPhoneEvent += () =>
                        {
                            //重新刷新
                            this.InitPhoneControl(listTableView);
                        };
                    };
 
                    if (result.Actions.Count > 0)
                    {
                        listPhoneData = result.Actions[0].PushTarget;
                        foreach (var data in listPhoneData)
                        {
                            //添加联系人行
                            this.AddPhoneNumRowLayout(data);
                        }
                    }
                    else
                    {
                        //没有联系人的话,添加个底线
                        rowContact.AddBottomLine();
                    }
                    //调整桌布大小
                    this.AdjustPhoneContrlTable();
                });
            });
        }
 
        /// <summary>
        /// 调整桌布大小
        /// </summary>
        private void AdjustPhoneContrlTable()
        {
            //调整桌布
            listPhoneView.AdjustRealHeight();
            tableContr.FinishInitControl(false, true);
        }
 
        #endregion
 
        #region ■ 添加联系人行_______________________
 
        /// <summary>
        /// 添加联系人行
        /// </summary>
        /// <param name="data"></param>
        private void AddPhoneNumRowLayout(ZigBee.Device.Safeguard.PushTargetInfo data)
        {
            var strArry = data.PushNumber.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            if (strArry.Length != 2)
            {
                return;
            }
            string areaCode2 = strArry[0];
            string phoneNum = strArry[1];
 
            string strPhone = "+" + areaCode2 + " " + phoneNum;
            if (phoneNum.Length >= 11)
            {
                phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 7, '*') + phoneNum.Substring(phoneNum.Length - 4, 4);
                strPhone = "+" + areaCode2 + " " + phoneNum;
            }
            else if (phoneNum.Length >= 5)
            {
                //或许这是国外的手机吧
                phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 5, '*') + phoneNum.Substring(phoneNum.Length - 2, 2);
                strPhone = "+" + areaCode2 + " " + phoneNum;
            }
 
            var rowContact = new RowLayoutControl();
            rowContact.MainKeys = strPhone;
            this.listPhoneView.AddChidren(rowContact);
            rowContact.frameTable.UseClickStatu = false;
            //联系方式
            rowContact.frameTable.AddLeftCaption(strPhone + " (" + data.PushNumberNote + ")", 800);
            rowContact.frameTable.AddBottomLine();
            //删除
            var btnDetete = rowContact.AddDeleteControl();
            btnDetete.ButtonClickEvent += (sender, e) =>
            {
                string[] Arry = data.PushNumber.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                string PNumber = string.Empty;
                string areaCode = string.Empty;
                if (Arry.Length == 1)
                {
                    PNumber = Arry[0];
                }
                else
                {
                    areaCode = Arry[0];
                    PNumber = Arry[1];
                }
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除联系人方式
                    this.DeleteCoercePhoneNumber(areaCode, PNumber, rowContact);
                });
            };
        }
 
        /// <summary>
        /// 删除联系人方式
        /// </summary>
        /// <param name="areaCode"></param>
        /// <param name="phone"></param>
        /// <param name="rowContact"></param>
        public async void DeleteCoercePhoneNumber(string areaCode, string phone, RowLayoutControl rowContact)
        {
            bool result = await HdlSafeguardLogic.Current.DeleteCoercePhoneNumber(areaCode, phone);
            if (result == true)
            {
                bool canMove = false;
                for (int i = 0; i < this.listPhoneView.ChildrenCount; i++)
                {
                    var myRow = this.listPhoneView.GetChildren(i) as RowLayoutControl;
                    if (myRow != null && myRow.MainKeys == rowContact.MainKeys)
                    {
                        //循环到了当前控件
                        canMove = true;
                        continue;
                    }
                    if (canMove == true)
                    {
                        //它之后的控件全部往上移动
                        myRow.Y -= rowContact.Height;
                    }
                }
                rowContact.RemoveFromParent();
 
                //移除缓存
                string checkKeys = areaCode + "-" + phone;
                for (int i = 0; i < this.listPhoneData.Count; i++)
                {
                    if (listPhoneData[i].PushNumber == checkKeys)
                    {
                        listPhoneData.RemoveAt(i);
                    }
                }
                //调整桌布大小
                this.AdjustPhoneContrlTable();
            }
        }
 
        #endregion
 
        #region ■ 修改备注___________________________
 
        /// <summary>
        /// 修改密码备注
        /// </summary>
        /// <param name="i_password">用户密码</param>
        /// <param name="i_passwordTip">用户密码提示</param>
        private async System.Threading.Tasks.Task<bool> EditorPassworTip(string i_password, string i_passwordTip, bool ShowMsg)
        {
            var result = await HdlSafeguardLogic.Current.AddPassWordTips(this.pswNo, i_password, i_passwordTip);
            if (result == true)
            {
                if (ShowMsg == true)
                {
                    //修改备注信息成功!
                    string msg = Language.StringByID(R.MyInternationalizationString.uEditorNoteInformationSuccess);
                    this.ShowMassage(ShowMsgType.Tip, msg);
                }
 
                this.passwordTip = i_passwordTip;
            }
            return result;
        }
 
        #endregion
    }
}