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;
|
|
Button btnConfrim;
|
|
GlobalRegionListRes selectedRegion;
|
|
/// <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.PlsSelectServer)) { maginY = 10}.LoadTopView();
|
//加载服务器区域选择
|
AddRegionalSelectionView();
|
//Show
|
this.Show();
|
}
|
|
|
/// <summary>
|
/// 加载区域选择View
|
/// </summary>
|
void AddRegionalSelectionView()
|
{
|
|
VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(84),
|
Height = bodyView.Height - Application.GetRealHeight(84),
|
ScrollEnabled = false,
|
};
|
bodyView.AddChidren(VerticalScrolViewMiddle);
|
|
var waitPage = new Loading();
|
bodyView.AddChidren(waitPage);
|
waitPage.Start(Language.StringByID(StringId.PleaseWait));
|
|
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);
|
}
|
//if (string.IsNullOrEmpty(OnAppConfig.Instance.RequestHttpsHost))
|
//{
|
// if (Language.CurrentLanguage != "Chinese")
|
// {
|
// OnAppConfig.Instance.RequestHttpsHost = dataList.Find((obj)=>obj.regionUrl.Contains)
|
// }
|
//}
|
}
|
}
|
});
|
}
|
else
|
{
|
//提示错误
|
IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
|
}
|
}
|
catch
|
{
|
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (waitPage != null)
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
}
|
});
|
}
|
});
|
|
}
|
|
/// <summary>
|
/// 加载区域选择RowView
|
/// </summary>
|
/// <param name="mGlobalRegion"></param>
|
/// <param name="VerticalScrolViewMiddle"></param>
|
void AddRowView(GlobalRegionListRes mGlobalRegion, VerticalScrolViewLayout VerticalScrolViewMiddle)
|
{
|
var rowView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(60),
|
};
|
VerticalScrolViewMiddle.AddChidren(rowView);
|
|
rowView.AddChidren(new Button()
|
{
|
Y = Application.GetRealHeight(50 - 1),
|
Height = Application.GetRealHeight(1),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
});
|
|
var urlBtn = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(300),
|
Height = Application.GetRealHeight(30),
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = mGlobalRegion.regionName,
|
};
|
rowView.AddChidren(urlBtn);
|
|
var btnTip = new Button()
|
{
|
Y = Application.GetRealHeight(20),
|
X = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(300),
|
Height = Application.GetRealHeight(20),
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextColor = CSS_Color.PromptingColor1,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
rowView.AddChidren(btnTip);
|
if (mGlobalRegion.regionName.ToLower().Contains("china"))
|
{
|
btnTip.TextID = StringId.ChineseServerPrompt;
|
//if(Language.CurrentLanguage == "Chinese")
|
//{
|
// selectedRegion = mGlobalRegion;
|
// urlBtn.TextColor = CSS_Color.MainColor;
|
//}
|
}
|
else
|
{
|
btnTip.TextID = StringId.NonChineseServerPrompt;
|
}
|
|
EventHandler<MouseEventArgs> eHandler = (sender, e) =>
|
{
|
//selectedRegion = mGlobalRegion;
|
//urlBtn.TextColor = CSS_Color.MainColor;
|
|
OnAppConfig.Instance.RequestHttpsHost = mGlobalRegion.regionUrl;
|
OnAppConfig.Instance.GlobalRegion = mGlobalRegion;
|
OnAppConfig.Instance.SaveConfig();
|
//关闭页面
|
this.Close();
|
selectAction?.Invoke();
|
};
|
rowView.MouseUpEventHandler += eHandler;
|
urlBtn.MouseUpEventHandler += eHandler;
|
|
//if (mGlobalRegion.regionUrl == OnAppConfig.Instance.RequestHttpsHost)
|
//{
|
// urlBtn.TextColor = CSS_Color.MainColor;
|
//}
|
}
|
}
|
}
|