private async Task LoadDataAysnc() { indicator.IsActive = true; await ChannelAPI.GetList(12, channels => { if (channels == null) { return; } viewModel.Categories.Clear(); if (channels.Recommendation != null) { foreach (var item in channels.Recommendation.Children.FlashItems) { viewModel.Recommendation.FlashVideos.Add(CopyVideoData(item)); } foreach (var item in channels.Recommendation.Children.Recommendations) { viewModel.Recommendation.Videos.Add(CopyVideoData(item)); } } if (channels.Channels != null) { foreach (var channel in channels.Channels) { Category category = new Category(); category.ChannelId = channel.Id; category.Name = channel.Name; if (channel.Children != null) { foreach (var videoItem in channel.Children) { category.Videos.Add(CopyVideoData(videoItem)); } } viewModel.Categories.Add(category); } } // lazy init // this.FindName("contentScrollViewer"); indicator.IsActive = false; this.recommendataion.StartScrollAnimation(); try { // update live tile // if (viewModel.Recommendation != null && viewModel.Recommendation.FlashVideos.Count > 0) { var video = viewModel.Recommendation.FlashVideos[(new Random()).Next(0, viewModel.Recommendation.FlashVideos.Count)]; ImageHelper imageHelper = new ImageHelper(); string fileName = MD5Core.GetHashString(video.ImageUrl) + ".jpg"; imageHelper.Download(video.ImageUrl, "Images", fileName, localFile => { LiveTileHelper.UpdateSecondaryTileAsync( Constants.TileId, video.Name, video.Intro, TimeSpan.FromHours(1), "ms-appdata:///local/Images/" + fileName); }); } } catch { } }, error => { //indicator.IsActive = false; var dialog = new MessageDialog(error.Message); dialog.ShowAsync(); }); }
public MainPageViewModel() { recommendation = new Category(); Categories = new ObservableCollection<Category>(); }