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
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
using System;
 
namespace Shared.SimpleControl.Phone
{
    public class AccountModifyPassword : FrameLayout
    {
        public AccountModifyPassword ()
        {
            BackgroundColor = SkinStyle.Current.MainColor;
        }
 
        public void ShowAccountModifyPassword ()
        {
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID (R.MyInternationalizationString.Account),
                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,
                Gravity = Gravity.CenterVertical,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                Gravity = Gravity.CenterVertical,
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                UserMiddle.SettingPageView.PageIndex = UserMiddle.SettingPageView.ChildrenCount - 2;
            };
            #endregion
 
            var BodyView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                Y = topView.Bottom,
                BackgroundColor = SkinStyle.Current.ViewColor,
            };
            AddChidren (BodyView);
 
            Button btnCurEmail = new Button () {
                Height = Application.GetRealHeight (140),
                Text = MainPage.LoginUser.AccountString,
                Enable = false,
                TextColor = SkinStyle.Current.TextColor1
            };
            BodyView.AddChidren (btnCurEmail);
 
            var ResetPasswrodView = new FrameLayout () {
                Height = Application.GetRealHeight (Application.DesignHeight - 126 - 140)
            };
            BodyView.AddChidren (ResetPasswrodView);
 
            EditText originalPassword = new EditText () {
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (70),
                Y = Application.GetRealHeight (200),
                PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseEnterOldPassword),
                UnSelectedImagePath = "Register/Register_Password_kuang.png",
                PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight (0),
                SecureTextEntry = true,
                TextColor = SkinStyle.Current.TextColor1,
            };
            originalPassword.MouseUpEventHandler += (sender, e) => {
                //originalPassword.IsSelected = !originalPassword.IsSelected;
            };
            ResetPasswrodView.AddChidren (originalPassword);
 
            EditText etNewPassword = new EditText () {
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (70),
                Y = originalPassword.Bottom + Application.GetRealHeight (70),
                UnSelectedImagePath = "Register/Register_Password_kuang.png",
                PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseSetNewPasword),
                PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight (0),
                TextColor = SkinStyle.Current.TextColor1,
                SecureTextEntry = true
            };
            ResetPasswrodView.AddChidren (etNewPassword);
 
            EditText etNewPassword2 = new EditText () {
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (70),
                Y = etNewPassword.Bottom + Application.GetRealHeight (70),
                UnSelectedImagePath = "Register/Register_Password_kuang.png",
                PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseConfirmNewPassword),
                PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight (0),
                TextColor = SkinStyle.Current.TextColor1,
                SecureTextEntry = true
            };
            ResetPasswrodView.AddChidren (etNewPassword2);
 
            Button btnSave = new Button () {
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (70),
                Y = Application.GetRealHeight (750),
                BackgroundColor = SkinStyle.Current.ButtonColor,
                SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                TextID = R.MyInternationalizationString.SAVE,
                TextColor = SkinStyle.Current.TextColor1,
                TextSize = 16,
            };
            ResetPasswrodView.AddChidren (btnSave);
            var tipConfrimPW = new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.NewCipherInconsistencies), Direction = AMPopTipDirection.Up, CloseTime = 20 };
            var tipConfrimShort = new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Up, CloseTime = 3 };
 
            //etNewPassword.TextChangeEventHandler += (sender, e) => {
            //    if (etNewPassword.Text.Trim ().Length < 6 ) {
            //            tipConfrimShort.Show (etNewPassword);
            //    } else {
            //        tipConfrimShort.CloseTime = 0;
            //    }
            //};
 
            etNewPassword2.TextChangeEventHandler += (sender, e) => {
                if (etNewPassword.Text.Trim ().Length == etNewPassword2.Text.Trim ().Length) {
                    if (etNewPassword.Text.Trim () != etNewPassword2.Text.Trim ()) {
                        tipConfrimPW.Show (etNewPassword2);
                    } else {
                    }
                }
            };
 
            btnSave.MouseDownEventHandler += (sender, e) => {
                btnSave.IsSelected = true;
            };
            btnSave.MouseUpEventHandler += (sender, e) => {
                try {
                    btnSave.IsSelected = false;
                    if (MainPage.LoginUser == null) {
                        return;
                    }
 
                    if (string.IsNullOrEmpty (etNewPassword.Text.Trim ())) {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.NewPasswordIsEmpty),
                               Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    } else if (etNewPassword.Text.Trim () != etNewPassword2.Text.Trim ()) {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseConfirmPasswordIsCorrect),
                               Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    } else {
                        string oldPassword = originalPassword.Text.Trim ();
                        string newPassword = etNewPassword.Text.Trim ();
                        try {
                            var requestObj = new UpdatePasswordObj () { OldPassword = oldPassword, Password = newPassword };
                            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
                            var revertObj = MainPage.RequestHttps ("UpdatePassword", requestJson);
                            if (revertObj.StateCode == "SUCCESS") {
                                MainPage.LoginUser.Password = newPassword;
                                MainPage.LoginUser.SaveUserInfo ();
                                Application.RunOnMainThread (() => {
                                    this.RemoveFromParent ();
                                    new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordModificationSuccess),Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                });
                            }
                        } catch {
                            Application.RunOnMainThread (() => {
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.FailureToServer),
                                           Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            });
                        } finally {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                            });
                        }
                    }
                } catch (Exception ex) {
                    new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.CheckInternet),
                               Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    string mess = ex.Message;
                }
            };
        }
    }
}