Inheritance: MediaPortal.GUI.Library.GUIListItem
Ejemplo n.º 1
0
        private void SendSearchResultsToFacade(IEnumerable <TraktEpisodeSummary> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (episodes == null || episodes.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Episodes = null;
                return;
            }

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

            // Add each show
            foreach (var episodeSummary in episodes)
            {
                // add images for download
                var images = new TraktImage
                {
                    EpisodeImages = episodeSummary.Episode.Images,
                    ShowImages    = episodeSummary.Show.Images
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.SearchEpisodes);

                item.Label2          = episodeSummary.Show.Year.ToString();
                item.TVTag           = episodeSummary;
                item.Images          = images;
                item.IsPlayed        = episodeSummary.Episode.Watched;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

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

            // Download images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 2
0
        private void SendRecentlyWatchedToFacade(IEnumerable <TraktActivity.Activity> activities)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (activities == null || activities.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNotWatchedEpisodes);
                PreviousUser = CurrentUser;
                CurrentUser  = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item watched
            foreach (var activity in activities)
            {
                // bad data in API
                if (activity.Show == null || activity.Episode == null)
                {
                    continue;
                }

                var episodeSummary = new TraktEpisodeSummary {
                    Episode = activity.Episode, Show = activity.Show
                };

                // skip invalid episodes
                if (episodeSummary.Episode.Number == 0)
                {
                    continue;
                }

                var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.RecentWatchedEpisodes);

                // add images for download
                var images = new TraktImage
                {
                    EpisodeImages = activity.Episode.Images,
                    ShowImages    = activity.Show.Images
                };
                showImages.Add(images);

                // add user watched date as second label
                item.Label2          = activity.Timestamp.FromEpoch().ToShortDateString();
                item.TVTag           = episodeSummary;
                item.Date            = activity.Timestamp.FromEpoch().ToLongDateString();
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IsPlayed        = activity.Episode.Watched;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (PreviousSelectedIndex >= activities.Count())
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

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

            // Download show images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 3
0
        private void SendSearchResultsToFacade(IEnumerable <TraktEpisodeSummaryEx> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            if (episodes.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Episodes = null;
                return;
            }

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

            // Add each show
            foreach (var episodeSummary in episodes)
            {
                // add images for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id      = episodeSummary.Show.Ids.Tmdb,
                        Season  = episodeSummary.Episode.Season,
                        Episode = episodeSummary.Episode.Number,
                        AirDate = episodeSummary.Episode.FirstAired == null ? null : episodeSummary.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.SearchEpisodes);

                item.Label2          = episodeSummary.Show.Year.ToString();
                item.TVTag           = episodeSummary;
                item.Episode         = episodeSummary.Episode;
                item.Show            = episodeSummary.Show;
                item.Images          = images;
                item.IsPlayed        = episodeSummary.Episode.IsWatched(episodeSummary.Show);
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

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

            // Download images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendSeasonEpisodesToFacade(IEnumerable <TraktEpisode> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (episodes == null || episodes.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoEpisodesInSeason);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // Set Common Show Properties
            GUICommon.SetShowProperties(Show);

            int itemCount     = 0;
            var episodeImages = new List <TraktImage>();

            foreach (var episode in episodes)
            {
                // use episode short string
                string itemLabel = string.Format("{0}. {1}", episode.Number.ToString(), string.IsNullOrEmpty(episode.Title) ? Translation.Episode + " " + episode.Number.ToString() : episode.Title);

                // add image for download
                var images = new TraktImage
                {
                    EpisodeImages = episode.Images,
                    ShowImages    = Show.Images
                };

                episodeImages.Add(images);

                var item = new GUIEpisodeListItem(itemLabel, (int)TraktGUIWindows.SeasonEpisodes);

                item.Label2 = episode.FirstAired == 0 ? " " : episode.FirstAired.FromEpoch().ToShortDateString();
                item.TVTag  = new TraktEpisodeSummary {
                    Episode = episode, Show = Show
                };
                item.IsPlayed        = episode.Watched;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemCount;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemCount++;
            }

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

            if (PreviousSelectedIndex >= itemCount)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(episodeImages);
        }
        private void SendRecentlyAddedToFacade(IEnumerable<TraktActivity.Activity> activities)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (activities == null || activities.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNoRecentAddedEpisodes);
                PreviousUser = CurrentUser;
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item added
            foreach (var activity in activities)
            {
                // bad data in API
                if (activity.Show == null || activity.Episodes == null)
                    continue;

                // trakt returns an episode array per activity
                // you may add more than one in bulk
                foreach (var episode in activity.Episodes)
                {
                    // prevent too many episodes loading in facade
                    // its possible that 1 activity item can represent many episodes
                    // e.g. user could of added 400 episodes of The Simpsons
                    if (episodeCount >= 100) continue;

                    var episodeSummary = new TraktEpisodeSummaryEx { Episode = episode, Show = activity.Show };

                    // skip invalid episodes
                    if (episodeSummary.Episode.Number == 0) continue;

                    var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.RecentAddedEpisodes);

                    // add images for download
                    var images = new GUITmdbImage
                    {
                        EpisodeImages = new TmdbEpisodeImages
                        {
                            Id = episodeSummary.Show.Ids.Tmdb,
                            Season = episodeSummary.Episode.Season,
                            Episode = episodeSummary.Episode.Number,
                            AirDate = episodeSummary.Episode.FirstAired == null ? null : episodeSummary.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                        }
                    };
                    showImages.Add(images);

                    // add user added date as second label
                    item.Label2 = activity.Timestamp.FromISO8601().ToShortDateString();
                    item.TVTag = episodeSummary;
                    item.Episode = episode;
                    item.Show = activity.Show;
                    item.Images = images;
                    item.Date = activity.Timestamp.FromISO8601().ToLongDateString();
                    item.ItemId = Int32.MaxValue - itemId++;
                    item.IsPlayed = episode.IsWatched(activity.Show);
                    item.IconImage = "defaultTraktEpisode.png";
                    item.IconImageBig = "defaultTraktEpisodeBig.png";
                    item.ThumbnailImage = "defaultTraktEpisodeBig.png";
                    item.OnItemSelected += OnEpisodeSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);
                    episodeCount++;
                }
            }

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

            if (PreviousSelectedIndex >= episodeCount)
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            else
                Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", episodeCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", episodeCount.ToString(), episodeCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download show images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendWatchListEpisodesToFacade(IEnumerable <TraktEpisodeWatchList> episodeWatchlist)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            if (episodeWatchlist.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoEpisodeWatchList, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemCount  = 0;
            var showImages = new List <GUITmdbImage>();

            // Add each show and underlying episodes
            // Should we do facade levels (Series,Season,Episodes)?
            foreach (var watchlistItem in episodeWatchlist)
            {
                // add image for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id      = watchlistItem.Show.Ids.Tmdb,
                        Season  = watchlistItem.Episode.Season,
                        Episode = watchlistItem.Episode.Number,
                        AirDate = watchlistItem.Episode.FirstAired == null ? null : watchlistItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(watchlistItem.ToString(), (int)TraktGUIWindows.WatchedListEpisodes);

                item.Label2          = watchlistItem.Episode.FirstAired == null ? " " : watchlistItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString();
                item.TVTag           = watchlistItem;
                item.Episode         = watchlistItem.Episode;
                item.Show            = watchlistItem.Show;
                item.Date            = watchlistItem.ListedAt.FromISO8601().ToShortDateString();
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemCount;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemCount++;
            }

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

            if (PreviousSelectedIndex >= itemCount)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 7
0
        private void SendCalendarToFacade(IEnumerable <TraktCalendar> calendar)
        {
            // check if we got a bad response
            if (calendar.Count() < PreviousCalendarDayCount)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.ErrorCalendar);
                // set defaults
                _CalendarMyShows   = null;
                _CalendarPremieres = null;
                _CalendarAllShows  = null;
                LastRequest        = new DateTime();
                return;
            }

            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            int itemCount = 0;
            List <TraktImage> showImages = new List <TraktImage>();

            // Add each days episodes to the list
            // Use Label3 of facade for Day/Group Idenitfier
            foreach (var day in calendar)
            {
                // apply watch list filter
                var episodes = day.Episodes;
                if (CurrentCalendar == CalendarType.MyShows)
                {
                    if (TraktSettings.CalendarHideTVShowsInWatchList)
                    {
                        episodes = day.Episodes.Where(e => !e.Show.InWatchList).ToList();
                    }
                }

                if (episodes.Count > 0)
                {
                    // add day header
                    GUIListItem item = new GUIListItem();
                    item.Label3          = GetDayHeader(DateTime.Parse(day.Date));
                    item.IconImage       = "defaultTraktCalendar.png";
                    item.IconImageBig    = "defaultTraktCalendarBig.png";
                    item.ThumbnailImage  = "defaultTraktCalendarBig.png";
                    item.OnItemSelected += OnCalendarDateSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);

                    foreach (var episode in episodes)
                    {
                        GUIEpisodeListItem episodeItem = new GUIEpisodeListItem(episode.ToString(), (int)TraktGUIWindows.Calendar);

                        // add image for download
                        TraktImage images = new TraktImage
                        {
                            EpisodeImages = episode.Episode.Images,
                            ShowImages    = episode.Show.Images
                        };
                        showImages.Add(images);

                        // extended skin properties
                        episodeItem.Date          = DateTime.Parse(day.Date).ToLongDateString();
                        episodeItem.SelectedIndex = (itemCount + 1).ToString();

                        episodeItem.Images          = images;
                        episodeItem.TVTag           = episode;
                        episodeItem.ItemId          = Int32.MaxValue - itemCount;
                        episodeItem.IsPlayed        = episode.Episode.Watched;
                        episodeItem.IconImage       = "defaultTraktEpisode.png";
                        episodeItem.IconImageBig    = "defaultTraktEpisodeBig.png";
                        episodeItem.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                        episodeItem.OnItemSelected += OnEpisodeSelected;
                        Utils.SetDefaultIcons(episodeItem);
                        Facade.Add(episodeItem);
                        itemCount++;
                    }
                }
            }

            // if nothing airing this week, then indicate to user
            if (!IsCached && (calendar.Count() == PreviousCalendarDayCount))
            {
                GUIListItem item = new GUIListItem();

                item.Label3          = Translation.NoEpisodesThisWeek;
                item.IconImage       = "defaultTraktCalendar.png";
                item.IconImageBig    = "defaultTraktCalendarBig.png";
                item.ThumbnailImage  = "defaultTraktCalendarBig.png";
                item.OnItemSelected += OnCalendarDateSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);

                // Stay on Next Week Item
                if (PreviousSelectedIndex > 0)
                {
                    PreviousSelectedIndex--;
                }
            }

            // Add Next Week Item so user can fetch next weeks calendar
            GUIListItem nextItem = new GUIListItem(Translation.NextWeek);

            nextItem.IconImage       = "traktNextWeek.png";
            nextItem.IconImageBig    = "traktNextWeek.png";
            nextItem.ThumbnailImage  = "traktNextWeek.png";
            nextItem.OnItemSelected += OnNextWeekSelected;
            nextItem.IsFolder        = true;
            Facade.Add(nextItem);

            // Set Facade Layout
            Facade.SetCurrentLayout("List");
            GUIControl.FocusControl(GetID, Facade.GetID);

            // Set the first episode on calendar on initial request (Index 0 is a day header),
            // Set last position if paging to next week
            if (!IsCached)
            {
                Facade.SelectIndex(PreviousSelectedIndex + 1);
            }
            else // If cached just set to last position
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendRecentlyWatchedToFacade(IEnumerable<TraktEpisodeHistory> recentlyWatched)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (recentlyWatched == null || recentlyWatched.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNotWatchedEpisodes);
                PreviousUser = CurrentUser;
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item watched
            foreach (var recent in recentlyWatched)
            {
                // bad data in API
                if (recent.Show == null || recent.Episode == null)
                    continue;

                // skip invalid episodes
                if (recent.Episode.Number == 0)
                    continue;

                string episodeName = string.Format("{0} - {1}x{2} - {3}", recent.Show.Title, recent.Episode.Season, recent.Episode.Number, recent.Episode.Title ?? string.Format("{0} {1}", Translation.Episode, recent.Episode.Number));

                var item = new GUIEpisodeListItem(episodeName, (int)TraktGUIWindows.RecentWatchedEpisodes);

                // add images for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id = recent.Show.Ids.Tmdb,
                        Season = recent.Episode.Season,
                        Episode = recent.Episode.Number,
                        AirDate = recent.Episode.FirstAired == null ? null : recent.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                // add user watched date as second label
                item.Label2 = recent.WatchedAt.ToPrettyDateTime();
                item.Date = recent.WatchedAt.FromISO8601().ToLongDateString();
                item.TVTag = recent;
                item.Episode = recent.Episode;
                item.Show = recent.Show;
                item.Images = images;
                item.ItemId = Int32.MaxValue - itemId;
                item.IsPlayed = CurrentUser != TraktSettings.Username ? recent.Episode.IsWatched(recent.Show) : false;
                item.IconImage = "defaultTraktEpisode.png";
                item.IconImageBig = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (PreviousSelectedIndex >= recentlyWatched.Count())
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            else
                Facade.SelectIndex(PreviousSelectedIndex);

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

            // Download show images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendRecentlyWatchedToFacade(IEnumerable <TraktEpisodeHistory> recentlyWatched)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (recentlyWatched == null || recentlyWatched.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNotWatchedEpisodes);
                PreviousUser = CurrentUser;
                CurrentUser  = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item watched
            foreach (var recent in recentlyWatched)
            {
                // bad data in API
                if (recent.Show == null || recent.Episode == null)
                {
                    continue;
                }

                // skip invalid episodes
                if (recent.Episode.Number == 0)
                {
                    continue;
                }

                string episodeName = string.Format("{0} - {1}x{2} - {3}", recent.Show.Title, recent.Episode.Season, recent.Episode.Number, recent.Episode.Title ?? string.Format("{0} {1}", Translation.Episode, recent.Episode.Number));

                var item = new GUIEpisodeListItem(episodeName, (int)TraktGUIWindows.RecentWatchedEpisodes);

                // add images for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id      = recent.Show.Ids.Tmdb,
                        Season  = recent.Episode.Season,
                        Episode = recent.Episode.Number,
                        AirDate = recent.Episode.FirstAired == null ? null : recent.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                // add user watched date as second label
                item.Label2          = recent.WatchedAt.ToPrettyDateTime();
                item.Date            = recent.WatchedAt.FromISO8601().ToLongDateString();
                item.TVTag           = recent;
                item.Episode         = recent.Episode;
                item.Show            = recent.Show;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IsPlayed        = CurrentUser != TraktSettings.Username ? recent.Episode.IsWatched(recent.Show) : false;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (PreviousSelectedIndex >= recentlyWatched.Count())
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

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

            // Download show images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 10
0
        private void SendRecentlyAddedToFacade(IEnumerable <TraktActivity.Activity> activities)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (activities == null || activities.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNoRecentAddedEpisodes);
                PreviousUser = CurrentUser;
                CurrentUser  = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item added
            foreach (var activity in activities)
            {
                // bad data in API
                if (activity.Show == null || activity.Episodes == null)
                {
                    continue;
                }

                // trakt returns an episode array per activity
                // you may add more than one in bulk
                foreach (var episode in activity.Episodes)
                {
                    // prevent too many episodes loading in facade
                    // its possible that 1 activity item can represent many episodes
                    // e.g. user could of added 400 episodes of The Simpsons
                    if (episodeCount >= 100)
                    {
                        continue;
                    }

                    var episodeSummary = new TraktEpisodeSummaryEx {
                        Episode = episode, Show = activity.Show
                    };

                    // skip invalid episodes
                    if (episodeSummary.Episode.Number == 0)
                    {
                        continue;
                    }

                    var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.RecentAddedEpisodes);

                    // add images for download
                    var images = new GUITmdbImage
                    {
                        EpisodeImages = new TmdbEpisodeImages
                        {
                            Id      = episodeSummary.Show.Ids.Tmdb,
                            Season  = episodeSummary.Episode.Season,
                            Episode = episodeSummary.Episode.Number,
                            AirDate = episodeSummary.Episode.FirstAired == null ? null : episodeSummary.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                        }
                    };
                    showImages.Add(images);

                    // add user added date as second label
                    item.Label2          = activity.Timestamp.FromISO8601().ToShortDateString();
                    item.TVTag           = episodeSummary;
                    item.Episode         = episode;
                    item.Show            = activity.Show;
                    item.Images          = images;
                    item.Date            = activity.Timestamp.FromISO8601().ToLongDateString();
                    item.ItemId          = Int32.MaxValue - itemId++;
                    item.IsPlayed        = episode.IsWatched(activity.Show);
                    item.IconImage       = "defaultTraktEpisode.png";
                    item.IconImageBig    = "defaultTraktEpisodeBig.png";
                    item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                    item.OnItemSelected += OnEpisodeSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);
                    episodeCount++;
                }
            }

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

            if (PreviousSelectedIndex >= episodeCount)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", episodeCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", episodeCount.ToString(), episodeCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download show images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendWatchListEpisodesToFacade(IEnumerable<TraktEpisodeWatchList> episodeWatchlist)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            if (episodeWatchlist.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoEpisodeWatchList, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemCount = 0;
            var showImages = new List<GUITmdbImage>();

            // Add each show and underlying episodes
            // Should we do facade levels (Series,Season,Episodes)?
            foreach (var watchlistItem in episodeWatchlist)
            {
                // add image for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id = watchlistItem.Show.Ids.Tmdb,
                        Season = watchlistItem.Episode.Season,
                        Episode = watchlistItem.Episode.Number,
                        AirDate = watchlistItem.Episode.FirstAired == null ? null : watchlistItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(watchlistItem.ToString(), (int)TraktGUIWindows.WatchedListEpisodes);

                item.Label2 = watchlistItem.Episode.FirstAired == null ? " " : watchlistItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString();
                item.TVTag = watchlistItem;
                item.Episode = watchlistItem.Episode;
                item.Show = watchlistItem.Show;
                item.Date = watchlistItem.ListedAt.FromISO8601().ToShortDateString();
                item.Images = images;
                item.ItemId = Int32.MaxValue - itemCount;
                item.IconImage = "defaultTraktEpisode.png";
                item.IconImageBig = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemCount++;
            }

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

            if (PreviousSelectedIndex >= itemCount)
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            else
                Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 12
0
        private void SendCalendarToFacade(Dictionary <string, List <TraktShowCalendar> > calendar)
        {
            // check if we got a bad response
            if (calendar == null)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.ErrorCalendar);
                // set defaults
                TVShowCalendar = null;
                LastRequest    = new DateTime();
                return;
            }

            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            int itemCount  = 0;
            var showImages = new List <GUITmdbImage>();

            // Add Previous Days Item so user can go back to previous calendar entries
            var prevItem = new GUIListItem(string.Format(Translation.PreviousDays, TraktSettings.TvCalendarMaxDays))
            {
                IconImage      = "traktPrevWeek.png",
                IconImageBig   = "traktPrevWeek.png",
                ThumbnailImage = "traktPrevWeek.png",
                TVTag          = "previous",
                IsFolder       = true
            };

            prevItem.OnItemSelected += OnPrevWeekSelected;
            Facade.Add(prevItem);

            // Add each days episodes to the list
            // Use Label3 of facade for Day/Group Idenitfier
            foreach (var day in calendar)
            {
                // apply watchlist filter
                var episodesInDay = day.Value;
                if (TraktSettings.CalendarHideTVShowsInWatchList && !string.IsNullOrEmpty(TraktSettings.UserAccessToken))
                {
                    episodesInDay = day.Value.Where(e => !e.Show.IsWatchlisted()).ToList();
                }

                // filter hidden shows
                if (FilterHiddenShows && !string.IsNullOrEmpty(TraktSettings.UserAccessToken))
                {
                    // for each hidden trakt show in the calendar, remove from our request
                    // this only needs to be done if we have manually hidden a show whilst using a cached calendar
                    episodesInDay.RemoveAll(e => e.Show.IsHidden("calendar"));
                }

                if (episodesInDay.Count() > 0)
                {
                    // add day header
                    var item = new GUIListItem();
                    item.Label3          = GetDayHeader(day.Key.FromISO8601());
                    item.IconImage       = "defaultTraktCalendar.png";
                    item.IconImageBig    = "defaultTraktCalendarBig.png";
                    item.ThumbnailImage  = "defaultTraktCalendarBig.png";
                    item.OnItemSelected += OnCalendarDateSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);

                    foreach (var calendarItem in episodesInDay)
                    {
                        var episodeItem = new GUIEpisodeListItem(calendarItem.ToString(), (int)TraktGUIWindows.CalendarTV);

                        // add image for download
                        var images = new GUITmdbImage
                        {
                            EpisodeImages = new TmdbEpisodeImages
                            {
                                Id      = calendarItem.Show.Ids.Tmdb,
                                Season  = calendarItem.Episode.Season,
                                Episode = calendarItem.Episode.Number,
                                AirDate = calendarItem.Episode.FirstAired == null ? null : calendarItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                            }
                        };
                        showImages.Add(images);

                        // extended skin properties
                        episodeItem.Date          = DateTime.Parse(day.Key).ToLongDateString();
                        episodeItem.SelectedIndex = (itemCount + 1).ToString();

                        episodeItem.Images          = images;
                        episodeItem.TVTag           = calendarItem;
                        episodeItem.Episode         = calendarItem.Episode;
                        episodeItem.Show            = calendarItem.Show;
                        episodeItem.ItemId          = Int32.MaxValue - itemCount;
                        episodeItem.IsPlayed        = calendarItem.Episode.IsWatched(calendarItem.Show);
                        episodeItem.IconImage       = "defaultTraktEpisode.png";
                        episodeItem.IconImageBig    = "defaultTraktEpisodeBig.png";
                        episodeItem.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                        episodeItem.OnItemSelected += OnEpisodeSelected;
                        Utils.SetDefaultIcons(episodeItem);
                        Facade.Add(episodeItem);
                        itemCount++;
                    }
                }
            }

            // if nothing airing this week, then indicate to user
            if (itemCount == 0)
            {
                var item = new GUIListItem()
                {
                    Label3         = Translation.NoEpisodesThisWeek,
                    IconImage      = "defaultTraktCalendar.png",
                    IconImageBig   = "defaultTraktCalendarBig.png",
                    ThumbnailImage = "defaultTraktCalendarBig.png"
                };

                item.OnItemSelected += OnCalendarDateSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
            }

            // Add Next Days Item so user can fetch next days calendar
            var nextItem = new GUIListItem(string.Format(Translation.NextDays, TraktSettings.TvCalendarMaxDays))
            {
                IconImage      = "traktNextWeek.png",
                IconImageBig   = "traktNextWeek.png",
                ThumbnailImage = "traktNextWeek.png",
                TVTag          = "next",
                IsFolder       = true
            };

            nextItem.OnItemSelected += OnNextWeekSelected;
            Facade.Add(nextItem);

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

            // if we cached the last selected index then use it
            // e.g. returning from another window and the cache has not expired
            if (PreviousSelectedIndex > 0)
            {
                Facade.SelectedListItemIndex = PreviousSelectedIndex;
            }
            else
            {
                // beginning of a page has a previous button
                // and a date header, so skip 2 items
                Facade.SelectedListItemIndex = 2;
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 13
0
        private void SendCalendarToFacade(Dictionary<string, List<TraktCalendar>> calendar)
        {
            // check if we got a bad response
            if (!IsCached && (calendar.Count() < PreviousCalendarDayCount))
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.ErrorCalendar);
                // set defaults
                _CalendarShows = null;
                _CalendarPremieres = null;
                _CalendarAllShows = null;
                LastRequest = new DateTime();
                return;
            }

            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            int itemCount = 0;
            var showImages = new List<GUITmdbImage>();

            // Add each days episodes to the list
            // Use Label3 of facade for Day/Group Idenitfier
            foreach (var day in calendar)
            {
                // apply watchlist filter
                var episodesInDay = day.Value;
                if (CurrentCalendar == CalendarType.MyShows)
                {
                    if (TraktSettings.CalendarHideTVShowsInWatchList)
                    {
                        episodesInDay = day.Value.Where(e => !e.Show.IsWatchlisted()).ToList();
                    }
                }

                if (episodesInDay.Count() > 0)
                {
                    // add day header
                    var item = new GUIListItem();
                    item.Label3 = GetDayHeader(day.Key.FromISO8601());
                    item.IconImage = "defaultTraktCalendar.png";
                    item.IconImageBig = "defaultTraktCalendarBig.png";
                    item.ThumbnailImage = "defaultTraktCalendarBig.png";
                    item.OnItemSelected += OnCalendarDateSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);

                    foreach (var calendarItem in episodesInDay)
                    {
                        var episodeItem = new GUIEpisodeListItem(calendarItem.ToString(), (int)TraktGUIWindows.Calendar);

                        // add image for download
                        var images = new GUITmdbImage
                        {
                            EpisodeImages = new TmdbEpisodeImages
                            {
                                Id = calendarItem.Show.Ids.Tmdb,
                                Season = calendarItem.Episode.Season,
                                Episode = calendarItem.Episode.Number,
                                AirDate = calendarItem.Episode.FirstAired == null ? null : calendarItem.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                            }
                        };
                        showImages.Add(images);

                        // extended skin properties
                        episodeItem.Date = DateTime.Parse(day.Key).ToLongDateString();
                        episodeItem.SelectedIndex = (itemCount + 1).ToString();

                        episodeItem.Images = images;
                        episodeItem.TVTag = calendarItem;
                        episodeItem.Episode = calendarItem.Episode;
                        episodeItem.Show = calendarItem.Show;
                        episodeItem.ItemId = Int32.MaxValue - itemCount;
                        episodeItem.IsPlayed = calendarItem.Episode.IsWatched(calendarItem.Show);
                        episodeItem.IconImage = "defaultTraktEpisode.png";
                        episodeItem.IconImageBig = "defaultTraktEpisodeBig.png";
                        episodeItem.ThumbnailImage = "defaultTraktEpisodeBig.png";
                        episodeItem.OnItemSelected += OnEpisodeSelected;
                        Utils.SetDefaultIcons(episodeItem);
                        Facade.Add(episodeItem);
                        itemCount++;
                    }
                }
            }

            // if nothing airing this week, then indicate to user
            if (!IsCached && (calendar.Count() == PreviousCalendarDayCount))
            {
                GUIListItem item = new GUIListItem();

                item.Label3 = Translation.NoEpisodesThisWeek;
                item.IconImage = "defaultTraktCalendar.png";
                item.IconImageBig = "defaultTraktCalendarBig.png";
                item.ThumbnailImage = "defaultTraktCalendarBig.png";
                item.OnItemSelected += OnCalendarDateSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);

                // Stay on Next Week Item
                if (PreviousSelectedIndex > 0)
                    PreviousSelectedIndex--;
            }

            // Add Next Week Item so user can fetch next weeks calendar
            GUIListItem nextItem = new GUIListItem(Translation.NextWeek);

            nextItem.IconImage = "traktNextWeek.png";
            nextItem.IconImageBig = "traktNextWeek.png";
            nextItem.ThumbnailImage = "traktNextWeek.png";
            nextItem.OnItemSelected += OnNextWeekSelected;
            nextItem.IsFolder = true;
            Facade.Add(nextItem);

            // Set Facade Layout
            Facade.SetCurrentLayout("List");
            GUIControl.FocusControl(GetID, Facade.GetID);

            // Set the first episode on calendar on initial request (Index 0 is a day header),
            // Set last position if paging to next week
            if (!IsCached)
                Facade.SelectIndex(PreviousSelectedIndex + 1);
            else // If cached just set to last position
                Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 14
0
        private void SendWatchListEpisodesToFacade(IEnumerable <TraktWatchListEpisode> shows)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (shows.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoEpisodeWatchList, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemCount  = 0;
            var showImages = new List <TraktImage>();

            // Add each show and underlying episodes
            // Should we do facade levels (Series,Season,Episodes)?
            foreach (var show in shows)
            {
                foreach (var episode in show.Episodes)
                {
                    // add image for download
                    var images = new TraktImage
                    {
                        EpisodeImages = episode.Images,
                        ShowImages    = show.Images
                    };
                    showImages.Add(images);

                    var episodeSummary = new TraktEpisodeSummary {
                        Episode = episode, Show = show
                    };

                    var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.WatchedListEpisodes);

                    item.Label2          = episode.FirstAired.FromEpoch().ToShortDateString();
                    item.TVTag           = episodeSummary;
                    item.Date            = episode.Inserted.FromEpoch().ToShortDateString();
                    item.Images          = images;
                    item.ItemId          = Int32.MaxValue - itemCount;
                    item.IconImage       = "defaultTraktEpisode.png";
                    item.IconImageBig    = "defaultTraktEpisodeBig.png";
                    item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                    item.OnItemSelected += OnEpisodeSelected;
                    Utils.SetDefaultIcons(item);
                    Facade.Add(item);
                    itemCount++;
                }
            }

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

            if (PreviousSelectedIndex >= itemCount)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
        private void SendSeasonEpisodesToFacade(IEnumerable<TraktEpisodeSummary> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

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

            // Set Common Show Properties
            GUICommon.SetShowProperties(Show);

            int itemCount = 0;
            var episodeImages = new List<GUITmdbImage>();

            foreach (var episode in episodes)
            {
                // skip invalid episodes
                if (episode.Number == 0)
                    continue;

                // use episode short string
                string itemLabel = string.Format("{0}. {1}", episode.Number.ToString(), string.IsNullOrEmpty(episode.Title) ? Translation.Episode + " " + episode.Number.ToString() : episode.Title);

                // add image for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id = Show.Ids.Tmdb,
                        Episode = episode.Number,
                        Season = episode.Season,
                        AirDate = episode.FirstAired == null ? null : episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    },
                };

                episodeImages.Add(images);

                var item = new GUIEpisodeListItem(itemLabel, (int)TraktGUIWindows.SeasonEpisodes);

                item.Label2 = episode.FirstAired == null ? " " : episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString();
                item.TVTag = episode;
                item.Show = Show;
                item.Episode = episode;
                item.IsPlayed = episode.IsWatched(Show);
                item.Images = images;
                item.ItemId = Int32.MaxValue - itemCount;
                item.IconImage = "defaultTraktEpisode.png";
                item.IconImageBig = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemCount++;
            }

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

            if (PreviousSelectedIndex >= itemCount)
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            else
                Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", itemCount.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", itemCount.ToString(), itemCount > 1 ? Translation.Episodes : Translation.Episode));

            // Download episode images Async and set to facade
            GUIEpisodeListItem.GetImages(episodeImages);
        }
        private void SendSearchResultsToFacade(IEnumerable<TraktEpisodeSummaryEx> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            if (episodes.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Episodes = null;
                return;
            }

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

            // Add each show
            foreach (var episodeSummary in episodes)
            {
                // add images for download
                var images = new GUITmdbImage
                {
                    EpisodeImages = new TmdbEpisodeImages
                    {
                        Id = episodeSummary.Show.Ids.Tmdb,
                        Season = episodeSummary.Episode.Season,
                        Episode = episodeSummary.Episode.Number,
                        AirDate = episodeSummary.Episode.FirstAired == null ? null : episodeSummary.Episode.FirstAired.FromISO8601().ToLocalTime().ToShortDateString()
                    }
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.SearchEpisodes);

                item.Label2 = episodeSummary.Show.Year.ToString();
                item.TVTag = episodeSummary;
                item.Episode = episodeSummary.Episode;
                item.Show = episodeSummary.Show;
                item.Images = images;
                item.IsPlayed = episodeSummary.Episode.IsWatched(episodeSummary.Show);
                item.ItemId = Int32.MaxValue - itemId;
                item.IconImage = "defaultTraktEpisode.png";
                item.IconImageBig = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

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

            if (SearchTermChanged) PreviousSelectedIndex = 0;
            Facade.SelectIndex(PreviousSelectedIndex);

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

            // Download images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }