예제 #1
0
 /// <summary>
 /// 获取兆赫列表
 /// </summary>
 /// <param name="type">类型:[0]收藏兆赫 [1]热门兆赫 [2]上升兆赫 [3]搜索到兆赫</param>
 /// <param name="page">页码</param>
 private async void getChannels(string queryKeywrod="")
 {
     string url = string.Empty;
     searchBoxCanvas.Visibility = Visibility.Collapsed;
     if(currentType==1)
         url = string.Format("http://douban.fm/j/explore/hot_channels?start={0}&limit={1}", (currentPage - 1) * 6, 6);
     else if (currentType == 2)
         url = string.Format("http://douban.fm/j/explore/up_trending_channels?start={0}&limit={1}", (currentPage - 1) * 6, 6);
     else if (currentType == 3)
     {
         if (queryKeywrod.Trim() != string.Empty)
             url = string.Format("http://douban.fm/j/explore/search?query={0}&start={1}&limit={2}", queryKeywrod, (currentPage - 1) * 6, 6);
         else
             return;
     }
     else
     {
         List<Channel> favchannels = favChannels.GetChannels(loginUserName);
         totalPage = (favchannels.Count - 1) / 6 + 1;
         if(currentPage==1)
             decPage.Visibility = Visibility.Collapsed;
         if (currentPage == totalPage)
             ascPage.Visibility = Visibility.Collapsed;
         else
             ascPage.Visibility = Visibility.Visible;
         int start = 6 * (currentPage - 1);
         int end = (favchannels.Count >= 6 * currentPage) ? 6 * currentPage - 1 : favchannels.Count - 1;
         channelTable.Children.Clear();
         for (int i = start; i <= end; i++)
         {
             int r = (i - start) / 3;
             int c = (i - start) % 3;
             DefChannelAlbum channelAlbum = new DefChannelAlbum(favchannels[i],true);
             channelAlbum.Margin = new Thickness(20 + 160 * c, 140 * r, 0, 0);
             channelAlbum.favPic.MouseLeftButtonDown += delegate
             {
                 if (channelAlbum.IsFaved)
                 {
                     favChannels.Delete(loginUserName, channelAlbum.channel.id);
                     favChannels.ToJson();
                     getChannels();
                 }
                 else
                 {
                     favChannels.Add(loginUserName, channelAlbum.channel.id, channelAlbum.channel.name, channelAlbum.channel.banner);
                     favChannels.ToJson();
                     getChannels();
                 }
             };
             channelAlbum.albumPic.MouseLeftButtonDown += delegate
             {
                 songControl.channelNo = channelAlbum.channel.id;
                 softwareTitle.Content = string.Format("豆瓣FM--{0}兆赫", channelAlbum.channel.name);
                 getSongList(true);
             };
             channelTable.Children.Add(channelAlbum);
         }
         return;
     }
     ChannelResult cr = new ChannelResult();
     tipLabel.Content = "加载中...";
     await Task.Run(() =>
     {
         string jsonresults = new ConnectionBase().Get(url);
         cr = ChannelResult.FromJson(jsonresults);
     });
     if (cr != null && cr.status)
     {
         tipLabel.Content = string.Empty;
         List<Channel> channels = cr.data.channels;
         totalPage = cr.data.total;
         if (currentPage == 1)
             decPage.Visibility = Visibility.Collapsed;
         if (currentPage == totalPage)
             ascPage.Visibility = Visibility.Collapsed;
         else
             ascPage.Visibility = Visibility.Visible;
         int start = 0;
         int end = channels.Count - 1;
         channelTable.Children.Clear();
         for (int i = start; i <= end; i++)
         {
             int r = (i - start) / 3;
             int c = (i - start) % 3;
             DefChannelAlbum channelAlbum = new DefChannelAlbum(channels[i % 6], favChannels.isFaved(loginUserName, channels[i % 6].id));
             channelAlbum.Margin = new Thickness(20 + 160 * c, 140 * r, 0, 0);
             channelAlbum.favPic.MouseLeftButtonDown += delegate
             {
                 if (channelAlbum.IsFaved)
                 {
                     favChannels.Delete(loginUserName, channelAlbum.channel.id);
                     favChannels.ToJson();
                 }
                 else
                 {
                     favChannels.Add(loginUserName, channelAlbum.channel.id, channelAlbum.channel.name, channelAlbum.channel.banner);
                     favChannels.ToJson();
                 }
             };
             channelAlbum.albumPic.MouseLeftButtonDown += delegate
             {
                 songControl.channelNo = channelAlbum.channel.id;
                 softwareTitle.Content = string.Format("豆瓣FM--{0}兆赫", channelAlbum.channel.name);
                 getSongList(true);
             };
             channelTable.Children.Add(channelAlbum);
         }
     }
     else
         tipLabel.Content = "加载失败...";
 }
예제 #2
0
        /// <summary>
        /// 获取兆赫列表
        /// </summary>
        /// <param name="type">类型:[0]收藏兆赫 [1]热门兆赫 [2]上升兆赫 [3]搜索到兆赫</param>
        /// <param name="page">页码</param>
        private async void getChannels(string queryKeywrod = "")
        {
            string url = string.Empty;

            searchBoxCanvas.Visibility = Visibility.Collapsed;
            if (currentType == 1)
            {
                url = string.Format("http://douban.fm/j/explore/hot_channels?start={0}&limit={1}", (currentPage - 1) * 6, 6);
            }
            else if (currentType == 2)
            {
                url = string.Format("http://douban.fm/j/explore/up_trending_channels?start={0}&limit={1}", (currentPage - 1) * 6, 6);
            }
            else if (currentType == 3)
            {
                if (queryKeywrod.Trim() != string.Empty)
                {
                    url = string.Format("http://douban.fm/j/explore/search?query={0}&start={1}&limit={2}", queryKeywrod, (currentPage - 1) * 6, 6);
                }
                else
                {
                    return;
                }
            }
            else
            {
                List <Channel> favchannels = favChannels.GetChannels(loginUserName);
                totalPage = (favchannels.Count - 1) / 6 + 1;
                if (currentPage == 1)
                {
                    decPage.Visibility = Visibility.Collapsed;
                }
                if (currentPage == totalPage)
                {
                    ascPage.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ascPage.Visibility = Visibility.Visible;
                }
                int start = 6 * (currentPage - 1);
                int end   = (favchannels.Count >= 6 * currentPage) ? 6 * currentPage - 1 : favchannels.Count - 1;
                channelTable.Children.Clear();
                for (int i = start; i <= end; i++)
                {
                    int             r            = (i - start) / 3;
                    int             c            = (i - start) % 3;
                    DefChannelAlbum channelAlbum = new DefChannelAlbum(favchannels[i], true);
                    channelAlbum.Margin = new Thickness(20 + 160 * c, 140 * r, 0, 0);
                    channelAlbum.favPic.MouseLeftButtonDown += delegate
                    {
                        if (channelAlbum.IsFaved)
                        {
                            favChannels.Delete(loginUserName, channelAlbum.channel.id);
                            favChannels.ToJson();
                            getChannels();
                        }
                        else
                        {
                            favChannels.Add(loginUserName, channelAlbum.channel.id, channelAlbum.channel.name, channelAlbum.channel.banner);
                            favChannels.ToJson();
                            getChannels();
                        }
                    };
                    channelAlbum.albumPic.MouseLeftButtonDown += delegate
                    {
                        songControl.channelNo = channelAlbum.channel.id;
                        softwareTitle.Content = string.Format("豆瓣FM--{0}兆赫", channelAlbum.channel.name);
                        getSongList(true);
                    };
                    channelTable.Children.Add(channelAlbum);
                }
                return;
            }
            ChannelResult cr = new ChannelResult();

            tipLabel.Content = "加载中...";
            await Task.Run(() =>
            {
                string jsonresults = new ConnectionBase().Get(url);
                cr = ChannelResult.FromJson(jsonresults);
            });

            if (cr != null && cr.status)
            {
                tipLabel.Content = string.Empty;
                List <Channel> channels = cr.data.channels;
                totalPage = cr.data.total;
                if (currentPage == 1)
                {
                    decPage.Visibility = Visibility.Collapsed;
                }
                if (currentPage == totalPage)
                {
                    ascPage.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ascPage.Visibility = Visibility.Visible;
                }
                int start = 0;
                int end   = channels.Count - 1;
                channelTable.Children.Clear();
                for (int i = start; i <= end; i++)
                {
                    int             r            = (i - start) / 3;
                    int             c            = (i - start) % 3;
                    DefChannelAlbum channelAlbum = new DefChannelAlbum(channels[i % 6], favChannels.isFaved(loginUserName, channels[i % 6].id));
                    channelAlbum.Margin = new Thickness(20 + 160 * c, 140 * r, 0, 0);
                    channelAlbum.favPic.MouseLeftButtonDown += delegate
                    {
                        if (channelAlbum.IsFaved)
                        {
                            favChannels.Delete(loginUserName, channelAlbum.channel.id);
                            favChannels.ToJson();
                        }
                        else
                        {
                            favChannels.Add(loginUserName, channelAlbum.channel.id, channelAlbum.channel.name, channelAlbum.channel.banner);
                            favChannels.ToJson();
                        }
                    };
                    channelAlbum.albumPic.MouseLeftButtonDown += delegate
                    {
                        songControl.channelNo = channelAlbum.channel.id;
                        softwareTitle.Content = string.Format("豆瓣FM--{0}兆赫", channelAlbum.channel.name);
                        getSongList(true);
                    };
                    channelTable.Children.Add(channelAlbum);
                }
            }
            else
            {
                tipLabel.Content = "加载失败...";
            }
        }