private void SendTrendingShowsToFacade(IEnumerable <TraktTrendingShow> shows) { // clear facade GUIControl.ClearControl(GetID, Facade.GetID); if (shows.Count() == 0) { GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoTrendingShows); GUIWindowManager.ShowPreviousWindow(); return; } // filter shows shows = GUICommon.FilterTrendingShows(shows); // sort shows var showList = shows.ToList(); showList.Sort(new GUIListItemShowSorter(TraktSettings.SortByTrendingShows.Field, TraktSettings.SortByTrendingShows.Direction)); int itemId = 0; List <TraktShow.ShowImages> showImages = new List <TraktShow.ShowImages>(); foreach (var show in showList) { GUITraktTrendingShowListItem item = new GUITraktTrendingShowListItem(show.Title); item.Label2 = show.Year.ToString(); item.TVTag = show; item.Item = show.Images; item.ItemId = Int32.MaxValue - itemId; item.IconImage = "defaultVideo.png"; item.IconImageBig = "defaultVideoBig.png"; item.ThumbnailImage = "defaultVideoBig.png"; item.OnItemSelected += OnShowSelected; Utils.SetDefaultIcons(item); Facade.Add(item); itemId++; // add image for download showImages.Add(show.Images); } // Set Facade Layout Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout)); GUIControl.FocusControl(GetID, Facade.GetID); Facade.SelectIndex(PreviousSelectedIndex); // set facade properties GUIUtils.SetProperty("#itemcount", shows.Count().ToString()); GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", shows.Count().ToString(), shows.Count() > 1 ? Translation.SeriesPlural : Translation.Series)); GUIUtils.SetProperty("#Trakt.Trending.PeopleCount", shows.Sum(s => s.Watchers).ToString()); GUIUtils.SetProperty("#Trakt.Trending.Description", string.Format(Translation.TrendingTVShowsPeople, shows.Sum(s => s.Watchers).ToString(), shows.Count().ToString())); // Download show images Async and set to facade GetImages(showImages); }
private void SendTrendingShowsToFacade(TraktShowsTrending trendingItems) { // clear facade GUIControl.ClearControl(GetID, Facade.GetID); if (trendingItems == null) { GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral); GUIWindowManager.ShowPreviousWindow(); TrendingShowPages = null; return; } if (trendingItems.Shows.Count() == 0) { GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoTrendingShows); GUIWindowManager.ShowPreviousWindow(); TrendingShowPages = null; return; } // filter shows var filteredTrendingList = GUICommon.FilterTrendingShows(trendingItems.Shows).Where(s => !string.IsNullOrEmpty(s.Show.Title)).ToList(); // sort shows filteredTrendingList.Sort(new GUIListItemShowSorter(TraktSettings.SortByTrendingShows.Field, TraktSettings.SortByTrendingShows.Direction)); int itemId = 0; var showImages = new List <GUITmdbImage>(); // Add Previous Page Button if (trendingItems.CurrentPage != 1) { var prevPageItem = new GUIShowListItem(Translation.PreviousPage, (int)TraktGUIWindows.TrendingShows); 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++; } foreach (var trendingItem in filteredTrendingList) { var item = new GUIShowListItem(trendingItem.Show.Title, (int)TraktGUIWindows.TrendingShows); // add image for download var image = new GUITmdbImage { ShowImages = new TmdbShowImages { Id = trendingItem.Show.Ids.Tmdb } }; showImages.Add(image); item.Label2 = trendingItem.Show.Year.ToString(); item.TVTag = trendingItem; item.Show = trendingItem.Show; item.Images = image; item.ItemId = Int32.MaxValue - itemId; item.IconImage = GUIImageHandler.GetDefaultPoster(false); item.IconImageBig = GUIImageHandler.GetDefaultPoster(); item.ThumbnailImage = GUIImageHandler.GetDefaultPoster(); item.OnItemSelected += OnShowSelected; Utils.SetDefaultIcons(item); Facade.Add(item); itemId++; } // Add Next Page Button if (trendingItems.CurrentPage != trendingItems.TotalPages) { var nextPageItem = new GUIShowListItem(Translation.NextPage, (int)TraktGUIWindows.TrendingShows); 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.SeriesPlural : Translation.Series)); GUIUtils.SetProperty("#Trakt.Trending.PeopleCount", trendingItems.TotalWatchers.ToString()); GUIUtils.SetProperty("#Trakt.Trending.Description", string.Format(Translation.TrendingTVShowsPeople, 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.MaxTrendingShowsRequest.ToString()); // Download show images Async and set to facade GUIShowListItem.GetImages(showImages); }