Пример #1
0
        public async void LoadData(String searchTerm)
        {
            if (!this.Loading)
            {
                App.TrackEvent("Search", "Searching for " + searchTerm);
                this.Loading = true;

                this.progressBar.Visibility = System.Windows.Visibility.Visible;

                App.SearchViewModel.clearResult();

                TraktShow[] shows = await showController.searchForShows(searchTerm);

                TraktMovie[] movies = await movieController.searchForMovies(searchTerm);

                List <Object> mergedList = new List <object>();

                Boolean isShow = shows.Length > 0 ? true : false;

                Int16 showLocation  = 0;
                Int16 movieLocation = 0;
                for (int i = 0; i < shows.Length + movies.Length; i++)
                {
                    if (isShow)
                    {
                        if (showLocation < shows.Length)
                        {
                            mergedList.Add(shows[showLocation++]);
                        }

                        isShow = false;
                    }
                    else
                    {
                        if (movieLocation < movies.Length)
                        {
                            mergedList.Add(movies[movieLocation++]);
                        }

                        isShow = true;
                    }
                }


                foreach (Object result in mergedList)
                {
                    if (result.GetType() == typeof(TraktShow))
                    {
                        TraktShow show = (TraktShow)result;
                        App.SearchViewModel.ResultItems.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, Type = "show"
                        });
                    }
                    else
                    {
                        TraktMovie movie = (TraktMovie)result;
                        App.SearchViewModel.ResultItems.Add(new ListItemViewModel()
                        {
                            Name = movie.Title, ImageSource = movie.Images.Poster, Imdb = movie.imdb_id, SubItemText = movie.year.ToString(), Genres = movie.Genres, Type = "movie"
                        });
                    }
                }

                App.SearchViewModel.NotifyPropertyChanged("ResultItems");

                this.progressBar.Visibility = System.Windows.Visibility.Collapsed;
                this.Loading = false;
            }
        }