using Newtonsoft.Json.Linq;
|
using Shared.SimpleControl;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net;
|
using System.Security.Cryptography;
|
using System.Text;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class AccountLogin : Dialog
|
{
|
public void LoginViewShow ()
|
{
|
var loginView = new LoginView ();
|
this.AddChidren (loginView);
|
loginView.LoginViewShow (this);
|
}
|
}
|
|
public class LoginView : FrameLayout
|
{
|
|
public void LoginViewShow (Dialog dialog = null)
|
{
|
string folderID = "";
|
var bodyView = new FrameLayout () {
|
BackgroundImagePath = "Logo/Register_bg.png"
|
};
|
AddChidren (bodyView);
|
|
FrameLayout logoView = new FrameLayout () {
|
Height = Application.GetRealHeight (400),
|
};
|
bodyView.AddChidren (logoView);
|
|
|
var btnQRCodeLoginType = new Button () {
|
Width = Application.GetMinRealAverage (500),
|
Height = Application.GetMinRealAverage (85),
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight (560),
|
Text = "QR-Code",
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
};
|
bodyView.AddChidren (btnQRCodeLoginType);
|
|
btnQRCodeLoginType.MouseUpEventHandler += (sender, e) => {
|
com.hdl.on.Scan.OpenScan ((scanMAC) => {
|
folderID = scanMAC;
|
double fId = 0;
|
double.TryParse (folderID, out fId);
|
if (fId == 0) {
|
new Alert ("", "Please enter the correct code.", "Close").Show ();
|
} else {
|
DownloadData (folderID, dialog);
|
}
|
});
|
};
|
var btnLoginCode = new Button () {
|
Width = Application.GetMinRealAverage (500),
|
Height = Application.GetMinRealAverage (85),
|
Gravity = Gravity.CenterHorizontal,
|
Y = btnQRCodeLoginType.Bottom + Application.GetRealHeight (70),
|
Text = "Verification Code",
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
};
|
bodyView.AddChidren (btnLoginCode);
|
|
btnLoginCode.MouseUpEventHandler += (sender, e) => {
|
if (btnLoginCode.Text == "Verification Code") {
|
btnQRCodeLoginType.RemoveFromParent ();
|
btnQRCodeLoginType.Y = btnLoginCode.Bottom + Application.GetRealHeight (20);
|
btnQRCodeLoginType.BackgroundColor = 0x00ffffff;
|
btnQRCodeLoginType.Text = "User QR-Code";
|
bodyView.AddChidren (btnQRCodeLoginType);
|
|
btnLoginCode.BackgroundColor = 0xFFCDAD7D;
|
btnLoginCode.Radius = (uint)Application.GetRealHeight (43);
|
|
|
var etCode = new EditText () {
|
Width = Application.GetMinRealAverage (500),
|
Height = Application.GetMinRealAverage (85),
|
X = Application.GetRealWidth (70),
|
Y = Application.GetRealHeight (560),
|
Radius = (uint)Application.GetRealHeight (2),
|
PlaceholderText = "Please entry verification code",
|
PlaceholderTextColor = 0xFF4A4A4A,
|
TextAlignment = TextAlignment.Center,
|
BorderColor = 0xFF4A4A4A,
|
BorderWidth = (uint)Application.GetRealHeight (2),
|
};
|
bodyView.AddChidren (etCode);
|
|
etCode.Foucs = true;
|
etCode.TextChangeEventHandler += (sender1, e1) => {
|
folderID = etCode.Text.Trim ();
|
};
|
etCode.EditorEnterAction += (obj) => {
|
Application.HideSoftInput ();
|
};
|
|
btnLoginCode.Text = "Download";
|
} else {
|
double fId = 0;
|
double.TryParse (folderID, out fId);
|
if (fId == 0) {
|
new Alert ("", "Please enter the correct code.", "Close").Show ();
|
} else {
|
DownloadData (folderID, dialog);
|
}
|
}
|
};
|
}
|
|
void DownloadData(string folderID, Dialog dialog = null)
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
});
|
new System.Threading.Thread (() => {
|
try {
|
var webClient = new WebClient ();
|
string url = $"https://developer.hdlcontrol.com/api/GetFolderByFolderID/?folderID={folderID}";
|
string responseString = null;
|
responseString = Encoding.UTF8.GetString (webClient.DownloadData (url));
|
var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
|
if (revertObj.StateCode == "SUCCESS") {
|
IO.FileUtils.DeleteAllFile ();
|
var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DemoBackup>> (revertObj.ResponseData.ToString ());
|
int index = 0;
|
foreach (var file in jt) {
|
if (file.Name == ".linphonerc" || file.Name == "error.wav" || file.Name == "jpush_stat_cache.json" || file.Name == "linphone -history.db" ||
|
file.Name == "linphone -log-history.db" || file.Name == "linphone1.log" || file.Name == "linphonerc" || file.Name == "wakeup_cache.json"
|
|| file.Name == "linphone-history.db" || file.Name == "linphone-log-history.db") {
|
Console.WriteLine ("'");
|
continue;
|
}
|
var ss = CommonPage.MyEncodingUTF8.GetString (file.DetailByte);
|
IO.FileUtils.WriteFileByBytes (file.Name, file.DetailByte);
|
index++;
|
Application.RunOnMainThread (() => {
|
int pro = (int)(index * 1.0 / jt.Count * 100);
|
MainPage.Loading.Text = pro.ToString () + "%";
|
});
|
}
|
Application.RunOnMainThread (() => {
|
MainPage.LoginUser = new UserInfo ();
|
MainPage.LoginUser.SaveUserInfo ();
|
MainPage.Loading.Hide ();
|
Room.InitAllRoom ();
|
UserMiddle.InitHomePageView ();
|
if (dialog != null) {
|
dialog.Close ();
|
}
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert ("", "Please enter the correct code.", "Close").Show ();
|
});
|
}
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
}) { IsBackground = true }.Start ();
|
}
|
|
}
|
|
|
public class DemoBackup
|
{
|
public string Name;
|
|
public byte [] DetailByte;
|
|
}
|
}
|