using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using Shared.SimpleControl.R;
using Shared.SimpleControl.Phone.Music;
using Shared.SimpleControl.Phone;
using System.Xml;
using System.Net;
using System.Security.Cryptography;
using Shared.SimpleControl;
namespace SmartHome.UI.SimpleControl.Phone.Music
{
class A31TidalLogin : FrameLayout
{
///
/// 密码
///
EditText password;
///
/// 用户名
///
EditText username;
A31MusicModel currentMusiceA31;
public void Show (A31MusicModel a31)
{
currentMusiceA31 = a31;
AddChidren (new Button {
Height = Application.GetRealHeight (36),
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
});
var topFrameLayout = new FrameLayout {
Height = Application.GetRealHeight (100),
Y = Application.GetRealHeight (36),
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
};
AddChidren (topFrameLayout);
var LocallistName = new Button {
Text = "TIDAL LOGIN",
TextColor = SkinStyle.Current.MusicTextColor,
};
topFrameLayout.AddChidren (LocallistName);
var back = new Button {
Width = Application.GetRealWidth (82),
Height = Application.GetRealHeight (89),
X = Application.GetRealWidth (10),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/HomepageBack.png",
};
topFrameLayout.AddChidren (back);
back.MouseDownEventHandler += (sender, e) => {
RemoveFromParent ();
};
var middle = new FrameLayout ();
middle.Y = topFrameLayout.Bottom;
middle.Height = Application.GetRealHeight (Application.DesignHeight - 136);
//middle.BackgroundColor = 0xff2F2F2F;
middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout;
AddChidren (middle);
username = new EditText {
Width = Application.GetRealWidth (580),
Height = Application.GetRealHeight (80),
X = Application.GetRealWidth (30),
Y = Application.GetRealHeight (180),
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
PlaceholderText = Language.StringByID (MyInternationalizationString.Youremail),
PlaceholderTextColor = SkinStyle.Current.MusicEditTextPlaceholderTextColor,
TextColor = SkinStyle.Current.MusicTextColor,
BorderWidth = 2,
BorderColor = SkinStyle.Current.MusicEditBorderColor,
Radius = 2,
//Text = "airableqc5",
};
middle.AddChidren (username);
password = new EditText {
Width = Application.GetRealWidth (580),
Height = Application.GetRealHeight (80),
X = Application.GetRealWidth (30),
Y = Application.GetRealHeight (300),
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
PlaceholderText = Language.StringByID (MyInternationalizationString.Yourpassword),
PlaceholderTextColor = SkinStyle.Current.MusicEditTextPlaceholderTextColor,
TextColor = SkinStyle.Current.MusicTextColor,
BorderWidth = 2,
BorderColor = SkinStyle.Current.MusicEditBorderColor,
Radius = 2,
//Text = "tidalx",
};
middle.AddChidren (password);
var tidalConfigText = Newtonsoft.Json.JsonConvert.DeserializeObject (Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (TidalConfig.FileName)));
if (tidalConfigText != null) {
username.Text = tidalConfigText.UserName;
password.Text = tidalConfigText.Passwrod;
}
Button loginBtn = new Button {
Width = Application.GetRealWidth (500),
Height = Application.GetRealHeight (100),
X = Application.GetRealWidth (70),
Y = Application.GetRealHeight (460),
BackgroundColor = 0xff656565,
Text = "Login",
TextSize = 18,
Radius = (uint)Application.GetRealHeight (16),
};
loginBtn.MouseUpEventHandler += (sender, e) => {
loginBtn.BackgroundColor = 0xff656565;
if (username.Text.Trim () == "" || password.Text.Trim () == "") {
new Alert (Language.StringByID (MyInternationalizationString.Tip),
Language.StringByID (MyInternationalizationString.TipPleaseEnterTheCorrectData),
Language.StringByID (MyInternationalizationString.Close)).Show ();
return;
}
login (username.Text.Trim (), password.Text.Trim ());
};
loginBtn.MouseDownEventHandler += (sender, e) => {
loginBtn.BackgroundColor = 0xffFE5E00;
};
middle.AddChidren (loginBtn);
}
///
/// 登录
///
/// The login.
/// 账户名
/// 密码
void login (string userName, string passWord)
{
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
System.Threading.Tasks.Task.Run (() => {
try {
Tidal.InitTokenTime ();
//可能网络或者其它原因,时间获取不到,下面代码不能执行
if (Tidal.CurrentTidal == null) {
return;
}
var result = Tidal.GetResult ("https://meta.airable.io/tidal/login?username=" + userName + "&password=" + passWord);
var musics = Newtonsoft.Json.JsonConvert.DeserializeObject (result);
if (musics.title != "TIDAL") {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (MyInternationalizationString.Tip),
Language.StringByID (MyInternationalizationString.Accountorpassworderro),
Language.StringByID (MyInternationalizationString.Close)).Show ();
});
return;
}
Tidal.CurrentTidal.IsLogin = true;
Tidal.CurrentTidal.Save ();
var tidalConfigBytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new TidalConfig { UserName = userName, Passwrod = passWord }));
Shared.IO.FileUtils.WriteFileByBytes (TidalConfig.FileName, tidalConfigBytes);
} catch { } finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
if (Tidal.CurrentTidal == null || !Tidal.CurrentTidal.IsLogin) {
return;
}
RemoveFromParent ();
var a31TidalHomePage = new A31TidalHomePage ();
MainPage.MainFrameLayout.AddChidren (a31TidalHomePage);
a31TidalHomePage.Show ();
});
}
});
}
}
}