HDL Home App 第二版本 旧平台金堂用 正在使用
xm
2020-04-16 6fa9d69da922c8049f5acfcbb9ce9fd26811024c
ZigbeeApp/Shared/Phone/Login/AccountRegisterSuccess.cs
New file
@@ -0,0 +1,186 @@
using System;
using System.Text;
using Shared.Common;
using Shared.Phone.UserView;
namespace Shared.Phone.Login
{
    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();
                                    //刷新个人中心的内存及线程
                                    await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
                                    //启动ZigBee
                                    ZigBee.Common.Application.Init();
                                    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 AccountLogin { };
                                CommonPage.Instance.AddChidren(login);
                                login.Show(account);
                            }
                        };
                        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();
        }
    }
}