using System;
|
using System.Collections.Generic;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
/// <summary>
|
/// SelectServerDialog
|
/// 服务器选择页面
|
/// </summary>
|
public class SelectServerDialog : Dialog
|
{
|
/// <summary>
|
///
|
/// </summary>
|
FrameLayout bodyView;
|
|
/// <summary>
|
/// 选择事件
|
/// </summary>
|
Action selectAction;
|
|
/// <summary>
|
///
|
/// </summary>
|
public SelectServerDialog(Action selectAction)
|
{
|
bodyView = new FrameLayout();
|
this.selectAction = selectAction;
|
}
|
|
|
/// <summary>
|
///
|
/// </summary>
|
public void LoadPage()
|
{
|
bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
|
this.AddChidren(bodyView);
|
//加载顶部菜单栏
|
new TopViewDiv(this, bodyView, Language.StringByID(StringId.PleaseSelectCountryOrRegion)).LoadTopView();
|
//加载服务器区域选择
|
AddRegionalSelectionView();
|
//Show
|
this.Show();
|
}
|
|
|
/// <summary>
|
/// 加载区域选择View
|
/// </summary>
|
void AddRegionalSelectionView()
|
{
|
|
VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = bodyView.Height - Application.GetRealHeight(64),
|
};
|
bodyView.AddChidren(VerticalScrolViewMiddle);
|
|
//var TipView = new Button()
|
//{
|
// Y = bodyView.Height - Application.GetRealHeight(60),
|
// Width = LayoutParams.MatchParent,
|
// Height = Application.GetRealHeight(60),
|
// BackgroundColor = 0xFFFFFFE0,
|
// TextSize = 11,
|
// //Text = "请选择注册的区域",
|
// //TextID = R.MyInternationalizationString.SelectRegisteredArea,
|
// TextColor = 0xFF1F1F1F,
|
// IsMoreLines = true
|
//};
|
//bodyView.AddChidren(TipView);
|
|
var waitPage = new Loading();
|
waitPage.Start("Please wait...");
|
|
System.Threading.Tasks.Task.Run(() => {
|
try
|
{
|
var dataList = new List<GlobalRegionListRes>();
|
var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark });
|
var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost);
|
if (revertObj.Code == StateCode.SUCCESS)
|
{
|
Application.RunOnMainThread(() => {
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GlobalRegionListRes>>(revertObj.Data.ToString());
|
if (responseDataObj != null)
|
{
|
dataList = responseDataObj;
|
if (dataList != null && dataList.Count > 0)
|
{
|
foreach (var data in dataList)
|
{
|
AddRowView(data, VerticalScrolViewMiddle);
|
}
|
}
|
}
|
});
|
}
|
else
|
{
|
//提示错误
|
IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
|
}
|
}
|
catch
|
{
|
|
}
|
finally
|
{
|
Application.RunOnMainThread(() => {
|
waitPage.Hide();
|
});
|
}
|
});
|
|
}
|
|
/// <summary>
|
/// 加载区域选择RowView
|
/// </summary>
|
/// <param name="mGlobalRegion"></param>
|
/// <param name="VerticalScrolViewMiddle"></param>
|
void AddRowView(GlobalRegionListRes mGlobalRegion, VerticalScrolViewLayout VerticalScrolViewMiddle)
|
{
|
var rowView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(44),
|
};
|
VerticalScrolViewMiddle.AddChidren(rowView);
|
|
var urlBtn = new Button() {
|
X = Application.GetRealWidth(16),
|
Height = rowView.Height,
|
Width = Application.GetRealWidth(200),
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
//Gravity = Gravity.CenterLeft,
|
TextAlignment = TextAlignment.CenterLeft
|
};
|
rowView.AddChidren(urlBtn);
|
|
//var lineView = new LineView();
|
//rowView.AddChidren(lineView);
|
//lineView.Y = rowView.Height - lineView.Height;
|
|
EventHandler<MouseEventArgs> eHandler = (sender, e) => {
|
UserInfo.Current.RequestHttpsHost = mGlobalRegion.regionUrl;
|
UserInfo.Current.GlobalRegion = mGlobalRegion;
|
UserInfo.Current.SaveUserInfo();
|
//关闭页面
|
this.Close();
|
selectAction?.Invoke();
|
};
|
rowView.MouseUpEventHandler += eHandler;
|
urlBtn.MouseUpEventHandler += eHandler;
|
|
urlBtn.Text = mGlobalRegion.regionName;
|
if (mGlobalRegion.regionUrl == UserInfo.Current.RequestHttpsHost)
|
{
|
urlBtn.TextColor = CSS_Color.MainColor;
|
}
|
}
|
}
|
}
|