TraktPlugin.GUI.GUITrendingMovies.SendTrendingMoviesToFacade C# (CSharp) Méthode

SendTrendingMoviesToFacade() private méthode

private SendTrendingMoviesToFacade ( TraktMoviesTrending trendingItems ) : void
trendingItems TraktPlugin.TraktAPI.DataStructures.TraktMoviesTrending
Résultat void
        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.SetCurrentLayout(Enum.GetName(typeof(Layout), 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);
        }