using System;
using Shared.Common;
using Shared.Phone.UserView;
namespace Shared.Phone.Device.Account
{
public class AccountRegisterSuccess : FrameLayout
{
///
/// registerSuccess
///
///
///
public void Show(string account, string password)
{
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);
}
///
/// AutoLogin
///
///
///
private void AutoLogin(string account, string password)
{
new System.Threading.Thread(() =>
{
System.Threading.Thread.Sleep(1500);
Application.RunOnMainThread(() =>
{
try
{
UserPage.Instance.Fresh();
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 () =>
{
ZigBee.Common.Application.Init();
//登录成功
var homes = await House.GetHomeLists();
//刷新个人中心的内存及线程
await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread();
Shared.Common.Room.CanInitAllRoom = true;
Shared.Common.Room.InitAllRoom();
Application.RunOnMainThread(() =>
{
UserPage.Instance.Fresh();
CommonPage.Loading.Hide();
});
})
{ 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();
this.RemoveFromParent();
CommonPage.Instance.RemoveViewByTag("Register");
CommonPage.Instance.RemoveViewByTag("Login");
}
});
})
{ IsBackground = true }.Start();
}
}
}