Ejemplo n.º 1
0
        /// <summary>
        /// 获取全部电台数据,显示分组数据
        /// </summary>
        /// <returns></returns>
        public static List<RadiosInfoInGroup> GetData()
        {
            #region 读取内容资源的电台数据
            if (_data == null)
            {
                _data = new List<RadiosInfoInGroup>();
                _radios = new List<RadiosInfo>();
                Dictionary<string, RadiosInfoInGroup> groups = new Dictionary<string, RadiosInfoInGroup>();
                foreach (char c in _groupLetters.ToUpper())
                {
                    RadiosInfoInGroup group = new RadiosInfoInGroup(c.ToString());
                    _data.Add(group);
                    groups[c.ToString()] = group;
                }

                //解析并获取数据
                //TODO:使用数据库,目前使用文本
                StreamResourceInfo resource = App.GetResourceStream(new Uri("Resources/RadioInfo.txt", UriKind.Relative));
                StreamReader sr = new StreamReader(resource.Stream);
                string line = sr.ReadLine();
                while (!string.IsNullOrWhiteSpace(line))
                {
                    var ary = line.Split('=');
                    var radioInfo = new RadiosInfo { Name = ary[0], URL = ary[1], NamePinyin = ary[2] };
                    _radios.Add(radioInfo);
                    groups[RadiosInfo.GetNameFirstPinyinKey(radioInfo)].Add(radioInfo);
                    line = sr.ReadLine();

                }

                resource = App.GetResourceStream(new Uri("Resources/Text1.txt", UriKind.Relative));
                sr = new StreamReader(resource.Stream);
                line = sr.ReadLine();
                while (!string.IsNullOrWhiteSpace(line))
                {
                    var ary = line.Split('=');
                    var radioInfo = new RadiosInfo { Name = ary[0], URL = ary[1] };
                    _radios.Add(radioInfo);
                    groups[RadiosInfo.GetNameFirstPinyinKey(radioInfo)].Add(radioInfo);
                    line = sr.ReadLine();

                }
            }
            #endregion
            return _data;
        }
Ejemplo n.º 2
0
 public static string GetNameFirstPinyinKey(RadiosInfo radioInfo)
 {
     if (radioInfo.NamePinyin == null)
        {
        try
        {
            radioInfo.NamePinyin = Pinyin.GetPinyin(radioInfo.Name);
        }
        catch (Exception ex)
        {
            UmengSDK.UmengAnalytics.TrackException(ex);
            Debug.WriteLine("拼音转换移除:"+ex);
        }
        }
        char index = char.ToUpper(radioInfo.NamePinyin[0]);
        if (index < 'A' || index > 'Z')
        {
        index = '#';
        }
        return index.ToString();
 }