using System; using System.Collections.Generic; using HDL_ON.DAL.Server; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { /// /// SelectServerDialog /// 服务器选择页面 /// public class SelectServerDialog : Dialog { /// /// /// FrameLayout bodyView; /// /// 选择事件 /// Action selectAction; /// /// /// public SelectServerDialog(Action selectAction) { bodyView = new FrameLayout(); this.selectAction = selectAction; } /// /// /// public void LoadPage() { bodyView.BackgroundColor = CSS_Color.MainBackgroundColor; this.AddChidren(bodyView); //加载顶部菜单栏 new TopViewDiv(this, bodyView, Language.StringByID(StringId.PleaseSelectCountryOrRegion)).LoadTopView(); //加载服务器区域选择 AddRegionalSelectionView(); //Show this.Show(); } /// /// 加载区域选择View /// void AddRegionalSelectionView() { VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(64), Height = bodyView.Height - Application.GetRealHeight(64), }; 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(); 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>(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(() => { if (waitPage != null) { waitPage.RemoveFromParent(); waitPage = null; } }); } }); } /// /// 加载区域选择RowView /// /// /// 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, TextAlignment = TextAlignment.CenterLeft }; rowView.AddChidren(urlBtn); //var lineView = new LineView(); //rowView.AddChidren(lineView); //lineView.Y = rowView.Height - lineView.Height; EventHandler 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; } } } }