Ejemplo n.º 1
0
        TraktMoviesAnticipated GetAnticipatedMovies(int page)
        {
            TraktMoviesAnticipated trendingMovies = null;

            if (AnticipatedMoviePages == null || LastRequest < DateTime.UtcNow.Subtract(new TimeSpan(0, TraktSettings.WebRequestCacheMinutes, 0)))
            {
                // get the first page
                trendingMovies = TraktAPI.TraktAPI.GetAnticipatedMovies(1, TraktSettings.MaxAnticipatedMoviesRequest);

                // reset to defaults
                LastRequest           = DateTime.UtcNow;
                CurrentPage           = 1;
                PreviousSelectedIndex = 0;

                // clear the cache
                if (AnticipatedMoviePages == null)
                {
                    AnticipatedMoviePages = new Dictionary <int, TraktMoviesAnticipated>();
                }
                else
                {
                    AnticipatedMoviePages.Clear();
                }

                // add page to cache
                AnticipatedMoviePages.Add(1, trendingMovies);
            }
            else
            {
                // get page from cache if it exists
                if (AnticipatedMoviePages.TryGetValue(page, out trendingMovies))
                {
                    return(trendingMovies);
                }

                // request next page
                trendingMovies = TraktAPI.TraktAPI.GetAnticipatedMovies(page, TraktSettings.MaxAnticipatedMoviesRequest);
                if (trendingMovies != null && trendingMovies.Movies != null)
                {
                    // add to cache
                    AnticipatedMoviePages.Add(page, trendingMovies);
                }
            }
            return(trendingMovies);
        }
Ejemplo n.º 2
0
        private void SendAnticipatedMoviesToFacade(TraktMoviesAnticipated anticipatedItems)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            // filter movies
            var filteredAnticipatedList = FilterAnticipatedMovies(anticipatedItems.Movies).Where(m => !string.IsNullOrEmpty(m.Movie.Title)).ToList();

            // sort movies
            filteredAnticipatedList.Sort(new GUIListItemMovieSorter(TraktSettings.SortByAnticipatedMovies.Field, TraktSettings.SortByAnticipatedMovies.Direction));

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

            // Add Previous Page Button
            if (anticipatedItems.CurrentPage != 1)
            {
                var prevPageItem = new GUIMovieListItem(Translation.PreviousPage, (int)TraktGUIWindows.AnticipatedMovies);
                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 anticipatedItem in filteredAnticipatedList)
            {
                // add image for download
                var images = new GUITmdbImage {
                    MovieImages = new TmdbMovieImages {
                        Id = anticipatedItem.Movie.Ids.Tmdb
                    }
                };
                movieImages.Add(images);

                var item = new GUIMovieListItem(anticipatedItem.Movie.Title, (int)TraktGUIWindows.AnticipatedMovies);

                item.Label2          = anticipatedItem.Movie.Year == null ? "----" : anticipatedItem.Movie.Year.ToString();
                item.TVTag           = anticipatedItem;
                item.Movie           = anticipatedItem.Movie;
                item.Images          = images;
                item.IsPlayed        = anticipatedItem.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 (anticipatedItems.CurrentPage != anticipatedItems.TotalPages)
            {
                var nextPageItem = new GUIMovieListItem(Translation.NextPage, (int)TraktGUIWindows.AnticipatedMovies);
                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.Movies : Translation.Movie));

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

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