TraktShowsAnticipated GetAnticipatedShows(int page) { TraktShowsAnticipated AnticipatedShows = null; if (AnticipatedShowPages == null || LastRequest < DateTime.UtcNow.Subtract(new TimeSpan(0, TraktSettings.WebRequestCacheMinutes, 0))) { // get the first page AnticipatedShows = TraktAPI.TraktAPI.GetAnticipatedShows(1, TraktSettings.MaxAnticipatedShowsRequest); // reset to defaults LastRequest = DateTime.UtcNow; CurrentPage = 1; PreviousSelectedIndex = 0; // clear the cache if (AnticipatedShowPages == null) { AnticipatedShowPages = new Dictionary <int, TraktShowsAnticipated>(); } else { AnticipatedShowPages.Clear(); } // add page to cache AnticipatedShowPages.Add(1, AnticipatedShows); } else { // get page from cache if it exists if (AnticipatedShowPages.TryGetValue(page, out AnticipatedShows)) { return(AnticipatedShows); } // request next page AnticipatedShows = TraktAPI.TraktAPI.GetAnticipatedShows(page, TraktSettings.MaxAnticipatedShowsRequest); if (AnticipatedShows != null && AnticipatedShows.Shows != null) { // add to cache AnticipatedShowPages.Add(page, AnticipatedShows); } } return(AnticipatedShows); }
private void SendAnticipatedShowsToFacade(TraktShowsAnticipated anticipatedItems) { // clear facade GUIControl.ClearControl(GetID, Facade.GetID); if (anticipatedItems == null) { GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral); GUIWindowManager.ShowPreviousWindow(); AnticipatedShowPages = null; return; } // filter shows var filteredAnticipatedList = FilterAnticipatedShows(anticipatedItems.Shows).Where(s => !string.IsNullOrEmpty(s.Show.Title)).ToList(); // sort shows filteredAnticipatedList.Sort(new GUIListItemShowSorter(TraktSettings.SortByAnticipatedShows.Field, TraktSettings.SortByAnticipatedShows.Direction)); int itemId = 0; var showImages = new List <GUITmdbImage>(); // Add Previous Page Button if (anticipatedItems.CurrentPage != 1) { var prevPageItem = new GUIShowListItem(Translation.PreviousPage, (int)TraktGUIWindows.AnticipatedShows); 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 anticipatedItem in filteredAnticipatedList) { var item = new GUIShowListItem(anticipatedItem.Show.Title, (int)TraktGUIWindows.AnticipatedShows); // add image for download var image = new GUITmdbImage { ShowImages = new TmdbShowImages { Id = anticipatedItem.Show.Ids.Tmdb } }; showImages.Add(image); item.Label2 = anticipatedItem.Show.Year.ToString(); item.TVTag = anticipatedItem; item.Show = anticipatedItem.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 (anticipatedItems.CurrentPage != anticipatedItems.TotalPages) { var nextPageItem = new GUIShowListItem(Translation.NextPage, (int)TraktGUIWindows.AnticipatedShows); 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", filteredAnticipatedList.Count().ToString()); GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", filteredAnticipatedList.Count(), filteredAnticipatedList.Count() > 1 ? Translation.SeriesPlural : Translation.Series)); // Page Properties GUIUtils.SetProperty("#Trakt.Facade.CurrentPage", anticipatedItems.CurrentPage.ToString()); GUIUtils.SetProperty("#Trakt.Facade.TotalPages", anticipatedItems.TotalPages.ToString()); GUIUtils.SetProperty("#Trakt.Facade.TotalItemsPerPage", TraktSettings.MaxAnticipatedShowsRequest.ToString()); // Download show images Async and set to facade GUIShowListItem.GetImages(showImages); }