wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.Xml;
using Shared;
namespace HDL_ON.UI.Music
{
    public class A31Radio : FrameLayout
    {
        public A31Radio()
        {
            Tag = "Music";
 
        }
 
        VerticalRefreshLayout middViewLayout;
        /// <summary>
        /// 先加载界面出来
        /// </summary>
        public void Show(string date)
        {
            InitList(date);
            #region   界面布局------
            this.BackgroundColor = Color.ViewColor;
            var topView = new TopView();
            this.AddChidren(topView.TopFLayoutView());
            topView.topNameBtn.TextID = StringId.radio;
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            middViewLayout = new VerticalRefreshLayout
            {
                BackgroundColor = Color.WhiteColor,
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(middViewLayout);
            middViewLayout.BeginHeaderRefreshingAction += () =>
            {
                middViewLayout.EndHeaderRefreshing();
            };
            #endregion
            RadioListView();
        }
        /// <summary> 
        /// 加载数据的方法
        /// </summary>
        public void RadioListView()
        {
           
            middViewLayout.RemoveAll();
            for (int i = 0; i < A31MusicModel.Current.CnRadioInfoList.Count; i++)
            {
                var radioInfo = A31MusicModel.Current.CnRadioInfoList[i];
                RowLayout addFlieRow = new RowLayout
                {
                    Height = Application.GetRealHeight(78),
                    LineColor = Color.WhiteColor,
                    SubViewWidth = Application.GetRealWidth(90),//改变编辑控件宽度多少;
                };
                middViewLayout.AddChidren(addFlieRow);
                //文件图标
                Button fileIconBtn = new Button
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(8),
                    Width = Application.GetMinRealAverage(62),
                    Height = Application.GetMinRealAverage(62),
                    UnSelectedImagePath = "MusicIcon/file.png",
                };
                addFlieRow.AddChidren(fileIconBtn);
                //文件名控件
                Button fileNameBtn = new Button
                {
                    X = fileIconBtn.Right + Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(29),
                    Width = Application.GetRealWidth(220),
                    Height = Application.GetRealHeight(20),
                    TextColor = Color.TextColor,
                    TextSize = TextSize.Text14,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = radioInfo.Title,
                };
                addFlieRow.AddChidren(fileNameBtn);
 
 
                Button clickBtn = new Button
                {
                    X = fileIconBtn.Right + Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(375 - 94),
                    Height = Application.GetRealHeight(78),
                    Tag = radioInfo.URL,
                };
                addFlieRow.AddChidren(clickBtn);
                clickBtn.MouseUpEventHandler += (sender, e) =>
                {
 
                    Loading loading = new Loading();
                    this.AddChidren(loading);
                    loading.Start();
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        try
                        {
                            var dataString = SendMethod.ReadRadioList(clickBtn.Tag.ToString());
                            if (dataString == null)
                            {
                                return;
                            }
                            int startIndex1 = dataString.IndexOf("<body>");
                            int endIndex1 = dataString.IndexOf("</body>") + "</body>".Length;
                            if (endIndex1 <= startIndex1)
                            {
                                return;
                            }
 
                            XmlDocument xml1 = new XmlDocument();
                            xml1.LoadXml(dataString.Substring(startIndex1, endIndex1 - startIndex1));
                            var dataList = xml1.SelectSingleNode("body");
                            if (dataList == null)
                            {
                                return;
                            }
                            A31MusicModel.Current.CnRadioInfoList.Clear();
                            foreach (XmlNode childNodes in dataList.ChildNodes)
                            {
                                if (childNodes.Name == "outline" && childNodes.Attributes["URL"] != null)
                                {
                                    MusicInfo musicInfoCN = new MusicInfo();
                                    musicInfoCN.URL = childNodes.Attributes["URL"] == null ? "" : childNodes.Attributes["URL"].Value;
                                    musicInfoCN.Title = childNodes.Attributes["text"] == null ? "" : childNodes.Attributes["text"].Value;
                                    musicInfoCN.Image = childNodes.Attributes["image"] == null ? "" : childNodes.Attributes["image"].Value;
                                    if (childNodes.Attributes["image"] != null)
                                    {
                                        string path = "";
                                        if (Shared.Application.IsPad)
                                        {
                                            path = "";
                                        }
                                        else
                                        {
                                            path = "Phone/" + "MusicImage/";
                                        }
                                    }
                                    musicInfoCN.Cntype = childNodes.Attributes["type"] == null ? "" : childNodes.Attributes["type"].Value;
                                    A31MusicModel.Current.CnRadioInfoList.Add(musicInfoCN);
                                }
                                foreach (XmlNode a in childNodes.ChildNodes)
                                {
                                    if (a.Name == "outline")
                                    {
                                        MusicInfo musicInfoCN = new MusicInfo();
                                        musicInfoCN.URL = a.Attributes["URL"] == null ? "" : a.Attributes["URL"].Value;
                                        musicInfoCN.Title = a.Attributes["text"] == null ? "" : a.Attributes["text"].Value;
 
                                        if (a.Attributes["image"] != null)
                                        {
                                            #region 初始化网络图片路径
                                            string path = "";
                                            if (Shared.Application.IsPad)
                                            {
                                                path = "Pad/" + "MusicImage/";
                                            }
                                            else
                                            {
                                                path = "Phone/" + "MusicImage/";
                                            }
                                            path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, path + a.Attributes["image"].Value.Replace('/', '_').Replace('\\', '_').Replace(':', '_').Replace('*', '_').Replace('?', '_').Replace('"', '_').Replace('<', '_').Replace('>', '_').Replace('|', '_'));
                                            musicInfoCN.Image = path;
                                            #endregion
                                            //Shared.IO.FileUtils.DownLoadImage(musicInfoCN.Image, a.Attributes["image"].Value);
                                        }
                                        musicInfoCN.Cntype = a.Attributes["type"] == null ? "" : a.Attributes["type"].Value;
                                        A31MusicModel.Current.CnRadioInfoList.Add(musicInfoCN);
 
                                    }
                                }
                            }
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                loading.Hide();
                                A31RadioList a31RadioList = new A31RadioList();
                                MainPage.BasePageView.AddChidren(a31RadioList);
                                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                                a31RadioList.Show(fileNameBtn.Text);
                            });
                        }
                    });
                };
 
            }
        }
 
        void InitList(string data)
        {
            try
            {
                var readString = data;
                if (readString == null)
                {
                    return;
                }
                int startIndex1 = readString.IndexOf("<body>");
                int endIndex = readString.IndexOf("</body>") + "</body>".Length;
                if (endIndex <= startIndex1)
                {
                    return;
                }
                var aa = readString.Substring(startIndex1, endIndex - startIndex1);
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(aa);
                var CNList = xml.SelectSingleNode("body");
                if (CNList == null)
                {
                    return;
                }
                A31MusicModel.Current.CnRadioInfoList.Clear();
                foreach (XmlNode v in CNList.ChildNodes)
                {
                    switch (v.Name)
                    {
                        case "outline":
                            MusicInfo musicInfo = new MusicInfo();
                            musicInfo.Title = v.Attributes["text"].Value;
                            musicInfo.URL = v.Attributes["URL"].Value;
                            musicInfo.Cnkey = v.Attributes["key"].Value;
 
                            A31MusicModel.Current.CnRadioInfoList.Add(musicInfo);
                            break;
                    }
                }
            }
            catch { }
        }
    }
}