示例#1
0
        private async void LoadShows()
        {
            TraktShow[] myShows = await controller.getUserShows();

            List <String> seenShows = new List <string>();
            Dictionary <String, TraktShowProgress> progressDictionary = new Dictionary <string, TraktShowProgress>();
            String tvdbidstrings = "";

            foreach (TraktShow show in myShows)
            {
                tvdbidstrings += show.tvdb_id + ",";
            }

            if (fullprogress == null)
            {
                fullprogress = await controller.getShowProgressionByTVDBID(tvdbidstrings);
            }

            if (fullprogress != null)
            {
                foreach (TraktShowProgress progress in fullprogress)
                {
                    if (!progressDictionary.ContainsKey(progress.Show.tvdb_id))
                    {
                        progressDictionary.Add(progress.Show.tvdb_id, progress);
                    }

                    if (progress.Progress.Percentage == 100)
                    {
                        seenShows.Add(progress.Show.tvdb_id);
                    }
                }
            }


            ObservableCollection <ListItemViewModel> tempItems = new ObservableCollection <ListItemViewModel>();

            foreach (TraktShow show in myShows)
            {
                if (filter > 0)
                {
                    if (filter == 1)
                    {
                        if (!seenShows.Contains(show.tvdb_id))
                        {
                            continue;
                        }
                    }
                    else if (filter == 2)
                    {
                        if (seenShows.Contains(show.tvdb_id))
                        {
                            continue;
                        }
                    }
                }


                tempItems.Add(new ListItemViewModel()
                {
                    Name = show.Title, ImageSource = show.Images.Poster, Imdb = show.imdb_id, Tvdb = show.tvdb_id, SubItemText = show.year.ToString(), Genres = show.Genres, Progress = progressDictionary.ContainsKey(show.tvdb_id) ? progressDictionary[show.tvdb_id].Progress.Percentage : Int16.Parse("0"), ProgressText = progressDictionary.ContainsKey(show.tvdb_id) ? progressDictionary[show.tvdb_id].Progress.Left + " episodes left to see!" : "Can't fetch unseen episodes :-("
                });
            }

            if (tempItems.Count == 0)
            {
                tempItems.Add(new ListItemViewModel()
                {
                    Name = "Nothing Found"
                });
            }

            this.LoadingMyShows = false;
            this.IsDataLoaded   = true;
            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                this.ShowItems = AlphaKeyGroup <ListItemViewModel> .CreateGroups(tempItems, Thread.CurrentThread.CurrentUICulture, (ListItemViewModel s) => { return(s.Name); }, true);
                App.MyShowsViewModel.NotifyPropertyChanged("ShowItems");

                if (this.Indicator != null)
                {
                    this.Indicator.IsVisible = false;
                }
            });
        }