黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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 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);
                                    }
                                }
                            }
                        });
                    }
                    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(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<MouseEventArgs> eHandler = (sender, e) =>
            {
                OnAppConfig.Instance.RequestHttpsHost = mGlobalRegion.regionUrl;
                OnAppConfig.Instance.GlobalRegion = mGlobalRegion;
                OnAppConfig.Instance.SaveConfig();
                //关闭页面
                this.Close();
                selectAction?.Invoke();
            };
            rowView.MouseUpEventHandler += eHandler;
            urlBtn.MouseUpEventHandler += eHandler;
 
            urlBtn.Text = mGlobalRegion.regionName;
 
            if (mGlobalRegion.regionUrl == OnAppConfig.Instance.RequestHttpsHost)
            {
                urlBtn.TextColor = CSS_Color.MainColor;
            }
        }
    }
}