黄学彪
2019-11-25 160785587667cc0d927f85e44c139ec9dde13a9e
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
using System;
using System.Text;
using Shared.Common;
using Shared.Phone.UserView;
 
namespace Shared.Phone.Device.Account
{
    public class AccountRegisterSuccess : FrameLayout
    {
        /// <summary>
        /// registerSuccess
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        public void Show(string account, string password,string OpenID="")
        {
            var dialog = new FrameLayout()
            {
                BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
            };
            AddChidren(dialog);
 
            var blackBG = new FrameLayout()
            {
                Y = Application.GetRealHeight(527),
                Width = Application.GetRealWidth(688),
                Height = Application.GetRealHeight(274),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor
            };
            AddChidren(blackBG);
 
            var whiteBG = new FrameLayout()
            {
                Y = blackBG.Bottom,
                Width = Application.GetRealWidth(688),
                Height = Application.GetRealHeight(579),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            AddChidren(whiteBG);
 
            var accountImg = new Button()
            {
                Y = Application.GetRealHeight(648),
                Width = Application.GetMinRealAverage(294),
                Height = Application.GetMinRealAverage(316),
                Gravity = Gravity.CenterHorizontal,
                UnSelectedImagePath = "Account/Cat.png"
            };
            AddChidren(accountImg);
 
            var accountBtn = new Button()
            {
                Y = accountImg.Bottom,
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(80),
                Gravity = Gravity.CenterHorizontal,
                Text = account,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor2,
                TextSize = 14,
            };
            AddChidren(accountBtn);
 
            var tip = new Button()
            {
                Y = Application.GetRealHeight(1143),
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(80),
                Gravity = Gravity.CenterHorizontal,
                TextID = R.MyInternationalizationString.RegisterSuccessTip,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor2,
                TextSize = 16,
            };
            AddChidren(tip);
 
            var willLogin = new Button()
            {
                Y = tip.Bottom + Application.GetRealHeight(15),
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(80),
                Gravity = Gravity.CenterHorizontal,
                TextID = R.MyInternationalizationString.WillAutoLogin,
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 14,
            };
            AddChidren(willLogin);
 
            AutoLogin(account, password,OpenID);
        }
 
        /// <summary>
        /// AutoLogin
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void AutoLogin(string account, string password, string OpenID = "")
        {
            new System.Threading.Thread(() =>
            {
                System.Threading.Thread.Sleep(1500);
                Application.RunOnMainThread(() =>
                {
                    try
                    {
                        HomePage.Instance.ShowLoginLoadView();
 
                        CommonPage.Loading.Start(Language.StringByID(R.MyInternationalizationString.Logining));
                        Action action = async () => {
                            var loginSuccess = await HomePage.Instance.LoginByPWDAsync(account, password);
                            if (loginSuccess==1)
                            {
                                new System.Threading.Thread(async () =>
                                {
                                    if (string.IsNullOrEmpty(OpenID)==false)
                                    {
                                        BindAuthUser(Config.Instance.Guid, OpenID);
                                    }
                                    //登录成功
                                    var homes = await House.GetHomeLists();
                                    ZigBee.Common.Application.Init();
                                    //刷新个人中心的内存及线程
                                    await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
 
                                    Shared.Common.Room.InitAllRoom();
 
                                    Application.RunOnMainThread(() =>
                                    {
                                        CommonPage.Loading.Hide();
                                        this.RemoveFromParent();
                                        CommonPage.Instance.RemoveViewByTag("Register");
                                        CommonPage.Instance.RemoveViewByTag("Login");
                                        UserPage.Instance.Fresh();
                                    });
                                })
                                { IsBackground = true }.Start();
 
                            }
                            else
                            {
                                //未登录成功弹出登录界面 同时需要标记为未登录状态
                                Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
                                Config.Instance.Save();
                                var login = new Device.Account.AccountLogin { };
                                CommonPage.Instance.AddChidren(login);
                                login.Show(account, password);
                            }
                        };
                        action();
                    }
                    catch (Exception ex)
                    {
                        var errMsg = ex.Message;
                    }
                    finally
                    {
                        CommonPage.Loading.Hide();
                    }
                });
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="openId"></param>
        private void BindAuthUser(string guid, string openId)
        {
            new System.Threading.Thread(async () =>
            {
                var auth = new SendDataToServer.BindAuthUser
                {
                    AccountGuid = guid,
                    OpenID = openId
                };
                var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(auth);
                var revert = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/BindAuthUserToAccount", Encoding.UTF8.GetBytes(requestJson));
            })
            {
                IsBackground = true
            }.Start();
        }
    }
}