Inheritance: MediaPortal.GUI.Library.GUIListItem
        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 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 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);
        }
        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);
        }
        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);
        }