コード例 #1
0
        private void SendTrendingMoviesToFacade(IEnumerable <TraktTrendingMovie> movies)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (movies.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoTrendingMovies);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // filter movies
            movies = GUICommon.FilterTrendingMovies(movies);

            // sort movies
            var movieList = movies.Where(m => !string.IsNullOrEmpty(m.Title)).ToList();

            movieList.Sort(new GUIListItemMovieSorter(TraktSettings.SortByTrendingMovies.Field, TraktSettings.SortByTrendingMovies.Direction));

            int itemId      = 0;
            var movieImages = new List <TraktImage>();

            // Add each movie mark remote if not in collection
            foreach (var movie in movieList)
            {
                // add image for download
                var images = new TraktImage {
                    MovieImages = movie.Images
                };
                movieImages.Add(images);

                var item = new GUIMovieListItem(movie.Title, (int)TraktGUIWindows.TrendingMovies);

                item.Label2   = movie.Year == "0" ? "----" : movie.Year;
                item.TVTag    = movie;
                item.Images   = images;
                item.IsPlayed = movie.Watched;
                item.ItemId   = Int32.MaxValue - itemId;
                // movie in collection doesnt nessararily mean
                // that the movie is locally available on this computer
                // as 'keep library clean' might not be enabled
                //item.IsRemote = !movie.InCollection;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnMovieSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", movies.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", movies.Count().ToString(), movies.Count() > 1 ? Translation.Movies : Translation.Movie));
            GUIUtils.SetProperty("#Trakt.Trending.PeopleCount", movies.Sum(m => m.Watchers).ToString());
            GUIUtils.SetProperty("#Trakt.Trending.Description", string.Format(Translation.TrendingMoviePeople, movies.Sum(m => m.Watchers).ToString(), movies.Count().ToString()));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
コード例 #2
0
        private void SendTrendingMoviesToFacade(TraktMoviesTrending trendingItems)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (trendingItems == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                TrendingMoviePages = null;
                return;
            }

            if (trendingItems.Movies.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoTrendingMovies);
                GUIWindowManager.ShowPreviousWindow();
                TrendingMoviePages = null;
                return;
            }

            // filter movies
            var filteredTrendingList = GUICommon.FilterTrendingMovies(trendingItems.Movies).Where(m => !string.IsNullOrEmpty(m.Movie.Title)).ToList();

            // sort movies
            filteredTrendingList.Sort(new GUIListItemMovieSorter(TraktSettings.SortByTrendingMovies.Field, TraktSettings.SortByTrendingMovies.Direction));

            int itemId      = 0;
            var movieImages = new List <GUITmdbImage>();

            // Add Previous Page Button
            if (trendingItems.CurrentPage != 1)
            {
                var prevPageItem = new GUIMovieListItem(Translation.PreviousPage, (int)TraktGUIWindows.TrendingMovies);
                prevPageItem.IsPrevPageItem  = true;
                prevPageItem.IconImage       = "traktPreviousPage.png";
                prevPageItem.IconImageBig    = "traktPreviousPage.png";
                prevPageItem.ThumbnailImage  = "traktPreviousPage.png";
                prevPageItem.OnItemSelected += OnPreviousPageSelected;
                prevPageItem.IsFolder        = true;
                Facade.Add(prevPageItem);
                itemId++;
            }

            // Add each movie mark remote if not in collection
            foreach (var trendingItem in filteredTrendingList)
            {
                // add image for download
                var images = new GUITmdbImage {
                    MovieImages = new TmdbMovieImages {
                        Id = trendingItem.Movie.Ids.Tmdb
                    }
                };
                movieImages.Add(images);

                var item = new GUIMovieListItem(trendingItem.Movie.Title, (int)TraktGUIWindows.TrendingMovies);

                item.Label2          = trendingItem.Movie.Year == null ? "----" : trendingItem.Movie.Year.ToString();
                item.TVTag           = trendingItem;
                item.Movie           = trendingItem.Movie;
                item.Images          = images;
                item.IsPlayed        = trendingItem.Movie.IsWatched();
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnMovieSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Add Next Page Button
            if (trendingItems.CurrentPage != trendingItems.TotalPages)
            {
                var nextPageItem = new GUIMovieListItem(Translation.NextPage, (int)TraktGUIWindows.TrendingMovies);
                nextPageItem.IsNextPageItem  = true;
                nextPageItem.IconImage       = "traktNextPage.png";
                nextPageItem.IconImageBig    = "traktNextPage.png";
                nextPageItem.ThumbnailImage  = "traktNextPage.png";
                nextPageItem.OnItemSelected += OnNextPageSelected;
                nextPageItem.IsFolder        = true;
                Facade.Add(nextPageItem);
                itemId++;
            }

            // Set Facade Layout
            Facade.CurrentLayout = CurrentLayout;
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", filteredTrendingList.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", filteredTrendingList.Count(), filteredTrendingList.Count() > 1 ? Translation.Movies : Translation.Movie));

            // set global trending properties
            GUIUtils.SetProperty("#Trakt.Trending.PeopleCount", trendingItems.TotalWatchers.ToString());
            GUIUtils.SetProperty("#Trakt.Trending.Description", string.Format(Translation.TrendingMoviePeople, trendingItems.TotalWatchers.ToString(), trendingItems.TotalItems.ToString()));

            // Page Properties
            GUIUtils.SetProperty("#Trakt.Facade.CurrentPage", trendingItems.CurrentPage.ToString());
            GUIUtils.SetProperty("#Trakt.Facade.TotalPages", trendingItems.TotalPages.ToString());
            GUIUtils.SetProperty("#Trakt.Facade.TotalItemsPerPage", TraktSettings.MaxTrendingMoviesRequest.ToString());

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }