示例#1
0
        /// <summary>
        /// Returns a list of context menu items for a selected item in the Activity Dashboard
        /// </summary>
        internal static List<GUIListItem> GetContextMenuItemsForActivity(TraktActivity.Activity activity)
        {
            GUIListItem listItem = null;
            var listItems = new List<GUIListItem>();

            // Add Watchlist
            if (!activity.IsWatchlisted())
            {
                listItem = new GUIListItem(Translation.AddToWatchList);
                listItem.ItemId = (int)ActivityContextMenuItem.AddToWatchList;
                listItems.Add(listItem);
            }
            else if (activity.Type != ActivityType.list.ToString())
            {
                listItem = new GUIListItem(Translation.RemoveFromWatchList);
                listItem.ItemId = (int)ActivityContextMenuItem.RemoveFromWatchList;
                listItems.Add(listItem);
            }

            // Mark As Watched
            if (activity.Type == ActivityType.episode.ToString() || activity.Type == ActivityType.movie.ToString())
            {
                if (!activity.IsWatched())
                {
                    listItem = new GUIListItem(Translation.MarkAsWatched);
                    listItem.ItemId = (int)ActivityContextMenuItem.MarkAsWatched;
                    listItems.Add(listItem);
                }
                else
                {
                    listItem = new GUIListItem(Translation.MarkAsUnWatched);
                    listItem.ItemId = (int)ActivityContextMenuItem.MarkAsUnwatched;
                    listItems.Add(listItem);
                }
            }

            // Add To Collection
            if (activity.Type == ActivityType.episode.ToString() || activity.Type == ActivityType.movie.ToString())
            {
                if (!activity.IsCollected())
                {
                    listItem = new GUIListItem(Translation.AddToLibrary);
                    listItem.ItemId = (int)ActivityContextMenuItem.AddToCollection;
                    listItems.Add(listItem);
                }
                else
                {
                    listItem = new GUIListItem(Translation.RemoveFromLibrary);
                    listItem.ItemId = (int)ActivityContextMenuItem.RemoveFromCollection;
                    listItems.Add(listItem);
                }
            }

            // Add to Custom list
            listItem = new GUIListItem(Translation.AddToList);
            listItem.ItemId = (int)ActivityContextMenuItem.AddToList;
            listItems.Add(listItem);

            // Shouts
            listItem = new GUIListItem(Translation.Comments);
            listItem.ItemId = (int)ActivityContextMenuItem.Shouts;
            listItems.Add(listItem);

            // Rate
            listItem = new GUIListItem(Translation.Rate + "...");
            listItem.ItemId = (int)ActivityContextMenuItem.Rate;
            listItems.Add(listItem);

            // Cast and Crew
            listItem = new GUIListItem(Translation.Cast);
            listItem.ItemId = (int)ActivityContextMenuItem.Cast;
            listItems.Add(listItem);

            listItem = new GUIListItem(Translation.Crew);
            listItem.ItemId = (int)ActivityContextMenuItem.Crew;
            listItems.Add(listItem);

            // Trailers
            if (TraktHelper.IsTrailersAvailableAndEnabled)
            {
                listItem = new GUIListItem(Translation.Trailers);
                listItem.ItemId = (int)ActivityContextMenuItem.Trailers;
                listItems.Add(listItem);
            }

            return listItems;
        }
示例#2
0
        internal static string GetActivityItemName(TraktActivity.Activity activity)
        {
            string name = string.Empty;

            try
            {
                ActivityType type = (ActivityType)Enum.Parse(typeof(ActivityType), activity.Type);
                ActivityAction action = (ActivityAction)Enum.Parse(typeof(ActivityAction), activity.Action);

                switch (type)
                {
                    case ActivityType.episode:
                        if (action == ActivityAction.seen || action == ActivityAction.collection)
                        {
                            if (activity.Episodes.Count > 1)
                            {
                                // just return show name
                                name = activity.Show.Title;
                            }
                            else
                            {
                                //  get the first and only item in collection of episodes
                                string episodeIndex = activity.Episodes.First().Number.ToString();
                                string seasonIndex = activity.Episodes.First().Season.ToString();
                                string episodeName = activity.Episodes.First().Title;

                                if (!string.IsNullOrEmpty(episodeName))
                                    episodeName = string.Format(" - {0}", episodeName);

                                name = string.Format("{0} - {1}x{2}{3}", activity.Show.Title, seasonIndex, episodeIndex, episodeName);
                            }
                        }
                        else
                        {
                            string episodeName = activity.Episode.Title;

                            if (!string.IsNullOrEmpty(episodeName))
                                episodeName = string.Format(" - {0}", episodeName);

                            name = string.Format("{0} - {1}x{2}{3}", activity.Show.Title, activity.Episode.Season.ToString(), activity.Episode.Number.ToString(), episodeName);
                        }
                        break;

                    case ActivityType.show:
                        name = activity.Show.Title;
                        break;

                    case ActivityType.season:
                        name = string.Format("{0} - {1} {2}", activity.Show.Title, Translation.Season, activity.Season.Number);
                        break;

                    case ActivityType.movie:
                        name = string.Format("{0} ({1})", activity.Movie.Title, activity.Movie.Year);
                        break;

                    case ActivityType.person:
                        name = string.Format("{0}", activity.Person.Name);
                        break;

                    case ActivityType.list:
                        if (action == ActivityAction.item_added)
                        {
                            // return the name of the item added to the list
                            switch (activity.ListItem.Type)
                            {
                                case "show":
                                    name = activity.ListItem.Show.Title;
                                    break;

                                case "season":
                                    name = string.Format("{0} - {1} {2}", activity.ListItem.Show.Title, Translation.Season, activity.ListItem.Season.Number);
                                    break;

                                case "episode":
                                    string episodeIndex = activity.ListItem.Episode.Number.ToString();
                                    string seasonIndex = activity.ListItem.Episode.Season.ToString();
                                    string episodeName = activity.ListItem.Episode.Title;

                                    if (string.IsNullOrEmpty(episodeName))
                                        episodeName = string.Format("{0} {1}", Translation.Episode, episodeIndex);

                                    name = string.Format("{0} - {1}x{2} - {3}", activity.ListItem.Show.Title, seasonIndex, episodeIndex, episodeName);
                                    break;

                                case "movie":
                                    name = string.Format("{0} ({1})", activity.ListItem.Movie.Title, activity.ListItem.Movie.Year);
                                    break;

                                case "person":
                                    name = string.Format("{0}", activity.Person.Name);
                                    break;

                            }
                        }
                        else
                        {
                            // return the list name
                            name = activity.List.Name;
                        }
                        break;

                    case ActivityType.comment:
                        name = activity.Shout.Text.Truncate(30);
                        break;
                }
            }
            catch
            {
                // most likely trakt returned a null object
                name = string.Empty;
            }

            return name;
        }
示例#3
0
        internal static string GetActivityListItemTitle(TraktActivity.Activity activity, ActivityView view = ActivityView.community)
        {
            if (activity == null)
                return null;

            string itemName = GetActivityItemName(activity);
            if (string.IsNullOrEmpty(itemName))
                return null;

            string userName = activity.User == null ? "" : activity.User.Username;
            string title = string.Empty;

            if (string.IsNullOrEmpty(activity.Action) || string.IsNullOrEmpty(activity.Type))
                return null;

            var action = (ActivityAction)Enum.Parse(typeof(ActivityAction), activity.Action);
            var type = (ActivityType)Enum.Parse(typeof(ActivityType), activity.Type);

            switch (action)
            {
                case ActivityAction.watching:
                    title = string.Format(Translation.ActivityWatching, userName, itemName);
                    break;

                case ActivityAction.scrobble:
                    if (activity.Plays() > 1)
                    {
                        title = string.Format(Translation.ActivityWatchedWithPlays, userName, itemName, activity.Plays());
                    }
                    else
                    {
                        title = string.Format(Translation.ActivityWatched, userName, itemName);
                    }
                    break;

                case ActivityAction.checkin:
                    title = string.Format(Translation.ActivityCheckedIn, userName, itemName);
                    break;

                case ActivityAction.seen:
                    if (type == ActivityType.episode && activity.Episodes.Count > 1)
                    {
                        title = string.Format(Translation.ActivitySeenEpisodes, userName, activity.Episodes.Count, itemName);
                    }
                    else
                    {
                        title = string.Format(Translation.ActivitySeen, userName, itemName);
                    }
                    break;

                case ActivityAction.collection:
                    if (type == ActivityType.episode && activity.Episodes.Count > 1)
                    {
                        title = string.Format(Translation.ActivityCollectedEpisodes, userName, activity.Episodes.Count, itemName);
                    }
                    else
                    {
                        title = string.Format(Translation.ActivityCollected, userName, itemName);
                    }
                    break;

                case ActivityAction.rating:
                    title = string.Format(Translation.ActivityRatingAdvanced, userName, itemName, activity.Rating);
                    break;

                case ActivityAction.watchlist:
                    if (view != ActivityView.me)
                    {
                        title = string.Format(Translation.ActivityWatchlist, userName, itemName);
                    }
                    else
                    {
                        title = string.Format(Translation.ActivityYourWatchlist, userName, itemName);
                    }
                    break;

                case ActivityAction.review:
                    title = string.Format(Translation.ActivityReview, userName, itemName);
                    break;

                case ActivityAction.shout:
                    title = string.Format(Translation.ActivityShouts, userName, itemName);
                    break;

                case ActivityAction.pause:
                    title = string.Format(Translation.ActivityPaused, userName, itemName, Math.Round(activity.Progress, 0));
                    break;

                case ActivityAction.created: // created list
                    title = string.Format(Translation.ActivityCreatedList, userName, itemName);
                    break;

                case ActivityAction.updated: // updated list
                    if (activity.List.ItemCount == 0)
                    {
                        title = string.Format(Translation.ActivityUpdatedList, userName, itemName);
                    }
                    else if (activity.List.ItemCount == 1)
                    {
                        title = string.Format(Translation.ActivityUpdatedListWithItemCountSingular, userName, itemName, 1);
                    }
                    else
                    {
                        title = string.Format(Translation.ActivityUpdatedListWithItemCount, userName, itemName, activity.List.ItemCount);
                    }
                    break;

                case ActivityAction.item_added: // added item to list
                    title = string.Format(Translation.ActivityAddToList, userName, itemName, activity.List.Name);
                    break;

                case ActivityAction.like:
                    if (type == ActivityType.comment)
                    {
                        title = string.Format(Translation.ActivityLikedComment, userName, activity.Shout.User.Username, itemName);
                    }
                    else if (type == ActivityType.list)
                    {
                        title = string.Format(Translation.ActivityLikedList, userName, itemName);
                    }
                    break;
            }

            // remove user name from your own feed, its not needed - you know who you are
            if ((ActivityView)TraktSettings.ActivityStreamView == ActivityView.me && title.StartsWith(TraktSettings.Username))
                title = title.Replace(TraktSettings.Username + " ", string.Empty);

            return title;
        }
        private string GetAvatarImage(TraktActivity.Activity activity)
        {
            if (activity.User == null)
                return "defaultTraktUser.png";

            string filename = activity.User.Images.Avatar.LocalImageFilename(ArtworkType.Avatar);
            if (string.IsNullOrEmpty(filename) || !System.IO.File.Exists(filename))
            {
                filename = "defaultTraktUser.png";
            }
            return filename;
        }
        /// <summary>
        /// gets the activity for the currently logged in user from 
        /// the local cache
        /// </summary>
        private TraktActivity GetMyActivityFromCache()
        {
            int i = 0;
            int maxActivityItems = TraktSkinSettings.DashboardActivityFacadeMaxItems;
            TraktActivity activity = new TraktActivity();

            // create activities from cached data
            activity.Timestamps = new TraktActivity.TraktTimestamps { Current = DateTime.UtcNow.ToEpoch() };
            activity.Activities = new List<TraktActivity.Activity>();

            TraktLogger.Debug("Getting current user cached activity");

            #region watched episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Watched)
            {
                var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true);
                if (watchedEpisodes != null)
                {
                    foreach (var episode in watchedEpisodes.OrderByDescending(e => e.WatchedAt).Take(maxActivityItems))
                    {
                        var watchedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.scrobble.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = new TraktEpisodeId(),
                                Number = episode.Number,
                                Season = episode.Season
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.ShowTitle,
                                Year = episode.ShowYear,
                                Ids = new TraktShowId
                                {
                                    Imdb = episode.ShowImdbId,
                                    Trakt = episode.ShowId,
                                    Tvdb = episode.ShowTvdbId
                                },
                            },
                            Timestamp = episode.WatchedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchedEpActivity);
                    }
                }
            }
            #endregion

            #region watched movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Watched)
            {
                var watchedMovies = TraktCache.GetWatchedMoviesFromTrakt(true);
                if (watchedMovies != null)
                {
                    foreach (var movie in watchedMovies.OrderByDescending(m => m.LastWatchedAt).Take(maxActivityItems))
                    {
                        var watchedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.scrobble.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.LastWatchedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchedEpActivity);
                    }
                }
            }
            #endregion

            #region collected episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Collected)
            {
                var collectedEpisodes = TraktCache.GetCollectedEpisodesFromTrakt(true);
                if (collectedEpisodes != null)
                {
                    foreach (var episode in collectedEpisodes.OrderByDescending(e => e.CollectedAt).Take(maxActivityItems))
                    {
                        var collectedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.collection.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episodes = new List<TraktEpisodeSummary>
                            {
                                new TraktEpisodeSummary
                                {
                                    Ids = new TraktEpisodeId(),
                                    Number = episode.Number,
                                    Season = episode.Season
                                }
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.ShowTitle,
                                Year = episode.ShowYear,
                                Ids = new TraktShowId
                                {
                                    Imdb = episode.ShowImdbId,
                                    Trakt = episode.ShowId,
                                    Tvdb = episode.ShowTvdbId
                                },
                            },
                            Timestamp = episode.CollectedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(collectedEpActivity);
                    }
                }
            }
            #endregion

            #region collected movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Collected)
            {
                var collectedMovies = TraktCache.GetCollectedMoviesFromTrakt(true);
                if (collectedMovies != null)
                {
                    foreach (var movie in collectedMovies.OrderByDescending(m => m.CollectedAt).Take(maxActivityItems))
                    {
                        var collectedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.collection.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.CollectedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(collectedEpActivity);
                    }
                }
            }
            #endregion

            #region watchlisted episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedEpisodes = TraktCache.GetWatchlistedEpisodesFromTrakt(true);
                if (watchlistedEpisodes != null)
                {
                    foreach (var episode in watchlistedEpisodes.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = episode.Episode.Ids,
                                Number = episode.Episode.Number,
                                Season = episode.Episode.Season,
                                Title = episode.Episode.Title
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.Show.Title,
                                Year = episode.Show.Year,
                                Ids = episode.Show.Ids
                            },
                            Timestamp = episode.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedEpActivity);
                    }
                }
            }
            #endregion

            #region watchlisted shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedShows = TraktCache.GetWatchlistedShowsFromTrakt(true);
                if (watchlistedShows != null)
                {
                    foreach (var show in watchlistedShows.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.show.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = show.Show.Title,
                                Year = show.Show.Year,
                                Ids = show.Show.Ids
                            },
                            Timestamp = show.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedShowActivity);
                    }
                }
            }
            #endregion

            #region watchlisted seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedSeasons = TraktCache.GetWatchlistedSeasonsFromTrakt(true);
                if (watchlistedSeasons != null)
                {
                    foreach (var item in watchlistedSeasons.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedSeasonActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.season.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = item.Show.Title,
                                Year = item.Show.Year,
                                Ids = item.Show.Ids
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = item.Season.Ids,
                                Number = item.Season.Number
                            },
                            Timestamp = item.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedSeasonActivity);
                    }
                }
            }
            #endregion

            #region watchlisted movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedMovies = TraktCache.GetWatchlistedMoviesFromTrakt(true);
                if (watchlistedMovies != null)
                {
                    foreach (var movie in watchlistedMovies.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedMovieActivity);
                    }
                }
            }
            #endregion

            #region rated episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedEpisodes = TraktCache.GetRatedEpisodesFromTrakt(true);
                if (ratedEpisodes != null)
                {
                    foreach (var episode in ratedEpisodes.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = episode.Episode.Ids,
                                Number = episode.Episode.Number,
                                Season = episode.Episode.Season,
                                Title = episode.Episode.Title
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.Show.Title,
                                Year = episode.Show.Year,
                                Ids = episode.Show.Ids
                            },
                            Rating = episode.Rating,
                            Timestamp = episode.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedEpActivity);
                    }
                }
            }
            #endregion

            #region rated seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedSeasons = TraktCache.GetRatedSeasonsFromTrakt(true);
                if (ratedSeasons != null)
                {
                    foreach (var season in ratedSeasons.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.season.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = season.Show.Title,
                                Year = season.Show.Year,
                                Ids = season.Show.Ids
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = season.Season.Ids ?? new TraktSeasonId(),
                                Number = season.Season.Number
                            },
                            Rating = season.Rating,
                            Timestamp = season.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedShowActivity);
                    }
                }
            }
            #endregion

            #region rated shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedShows = TraktCache.GetRatedShowsFromTrakt(true);
                if (ratedShows != null)
                {
                    foreach (var show in ratedShows.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.show.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = show.Show.Title,
                                Year = show.Show.Year,
                                Ids = show.Show.Ids
                            },
                            Rating = show.Rating,
                            Timestamp = show.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedShowActivity);
                    }
                }
            }
            #endregion

            #region rated movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedMovies = TraktCache.GetRatedMoviesFromTrakt(true);
                if (ratedMovies != null)
                {
                    foreach (var movie in ratedMovies.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Rating = movie.Rating,
                            Timestamp = movie.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedMovieActivity);
                    }
                }
            }
            #endregion

            #region lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists)
            {
                var lists = TraktCache.GetCustomLists(true);
                if (lists != null)
                {
                    foreach (var list in lists.OrderByDescending(l => l.Key.UpdatedAt).Take(maxActivityItems))
                    {
                        var userList = list.Key;

                        if (TraktSettings.DashboardActivityFilter.Actions.Updated)
                        {
                            var listActivity = new TraktActivity.Activity
                            {
                                Id = i++,
                                Action = ActivityAction.updated.ToString(),
                                Type = ActivityType.list.ToString(),
                                List = userList,
                                Timestamp = list.Key.UpdatedAt,
                                User = GetUserProfile()
                            };

                            // add activity to the list
                            activity.Activities.Add(listActivity);
                        }

                        if (TraktSettings.DashboardActivityFilter.Actions.Added)
                        {
                            foreach (var listItem in list.Value.OrderByDescending(l => l.ListedAt).Take(maxActivityItems))
                            {
                                var listItemActivity = new TraktActivity.Activity
                                {
                                    Id = i++,
                                    Action = ActivityAction.item_added.ToString(),
                                    Type = listItem.Type,
                                    Timestamp = listItem.ListedAt,
                                    List = userList,
                                    Movie = listItem.Movie,
                                    Show = listItem.Show,
                                    Episode = listItem.Episode,
                                    Season = listItem.Season,
                                    Person = listItem.Person,
                                    User = GetUserProfile()
                                };

                                // add activity to the list
                                activity.Activities.Add(listItemActivity);
                            }
                        }
                    }
                }
            }
            #endregion

            #region commented episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedEpisodes = TraktCache.GetCommentedEpisodesFromTrakt(true);
                if (commentedEpisodes != null)
                {
                    foreach (var comment in commentedEpisodes.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedEpisodeActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = comment.Episode.Ids,
                                Number = comment.Episode.Number,
                                Season = comment.Episode.Season,
                                Title = comment.Episode.Title
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedEpisodeActivity);
                    }
                }
            }
            #endregion

            #region commented seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedSeasons = TraktCache.GetCommentedSeasonsFromTrakt(true);
                if (commentedSeasons != null)
                {
                    foreach (var comment in commentedSeasons.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedSeasonActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = comment.Season.Ids,
                                Number = comment.Season.Number
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedSeasonActivity);
                    }
                }
            }
            #endregion

            #region commented shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedShows = TraktCache.GetCommentedShowsFromTrakt(true);
                if (commentedShows != null)
                {
                    foreach (var comment in commentedShows.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedShowActivity);
                    }
                }
            }
            #endregion

            #region commented movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedMovies = TraktCache.GetCommentedMoviesFromTrakt(true);
                if (commentedMovies != null)
                {
                    foreach (var comment in commentedMovies.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Movie = new TraktMovieSummary
                            {
                                Ids = comment.Movie.Ids,
                                Title = comment.Movie.Title,
                                Year = comment.Movie.Year
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedMovieActivity);
                    }
                }
            }
            #endregion

            #region commented lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedLists = TraktCache.GetCommentedMoviesFromTrakt(true);
                if (commentedLists != null)
                {
                    foreach (var comment in commentedLists.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedListActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            List = comment.List,
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedListActivity);
                    }
                }
            }
            #endregion

            #region paused episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Paused)
            {
                string lastEpisodeProcessedAt;
                var pausedEpisodes = TraktCache.GetPausedEpisodes(out lastEpisodeProcessedAt, true);
                if (pausedEpisodes != null)
                {
                    foreach (var pause in pausedEpisodes.OrderByDescending(e => e.PausedAt).Take(maxActivityItems))
                    {
                        var pausedEpisodeActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.pause.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = pause.Show.Title,
                                Year = pause.Show.Year,
                                Ids = pause.Show.Ids
                            },
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = pause.Episode.Ids,
                                Number = pause.Episode.Number,
                                Season = pause.Episode.Season,
                                Title = pause.Episode.Title
                            },
                            Progress = pause.Progress,
                            Timestamp = pause.PausedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(pausedEpisodeActivity);
                    }
                }
            }
            #endregion

            #region paused movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Paused)
            {
                string lastMovieProcessedAt;
                var pausedMovies = TraktCache.GetPausedMovies(out lastMovieProcessedAt, true);
                if (pausedMovies != null)
                {
                    foreach (var pause in pausedMovies.OrderByDescending(e => e.PausedAt).Take(maxActivityItems))
                    {
                        var pausedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.pause.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = pause.Movie.Ids,
                                Title = pause.Movie.Title,
                                Year = pause.Movie.Year
                            },
                            Progress = pause.Progress,
                            Timestamp = pause.PausedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(pausedMovieActivity);
                    }
                }
            }
            #endregion

            #region liked comments
            if (TraktSettings.DashboardActivityFilter.Types.Comments && TraktSettings.DashboardActivityFilter.Actions.Liked)
            {
                var likedComments = TraktCache.GetLikedCommentsFromTrakt(true);
                if (likedComments != null)
                {
                    foreach (var like in likedComments.OrderByDescending(c => c.LikedAt).Take(maxActivityItems))
                    {
                        var likedCommentActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.like.ToString(),
                            Type = ActivityType.comment.ToString(),
                            Shout = like.Comment,
                            Timestamp = like.LikedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(likedCommentActivity);
                    }
                }
            }
            #endregion

            #region liked lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists && TraktSettings.DashboardActivityFilter.Actions.Liked)
            {
                var likedLists = TraktCache.GetLikedListsFromTrakt(true);
                if (likedLists != null)
                {
                    foreach (var like in likedLists.OrderByDescending(c => c.LikedAt).Take(maxActivityItems))
                    {
                        var likedListActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.like.ToString(),
                            Type = ActivityType.list.ToString(),
                            List = like.List,
                            Timestamp = like.LikedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(likedListActivity);
                    }
                }
            }
            #endregion

            TraktLogger.Debug("Finished getting users cached activity");

            // sort by time inserted into library
            activity.Activities = activity.Activities.OrderByDescending(a => a.Timestamp).Take(TraktSkinSettings.DashboardActivityFacadeMaxItems).ToList();

            return activity;
        }
 private string GetActivityShoutText(TraktActivity.Activity activity)
 {
     if (activity.Action != ActivityAction.shout.ToString()) return string.Empty;
     if (activity.Shout.IsSpoiler) return Translation.HiddenToPreventSpoilers;
     return activity.Shout.Text;
 }
        private string GetActivityImage(TraktActivity.Activity activity)
        {
            if (activity == null || string.IsNullOrEmpty(activity.Action))
                return string.Empty;

            string imageFilename = string.Empty;
            ActivityAction action = (ActivityAction)Enum.Parse(typeof(ActivityAction), activity.Action);

            switch (action)
            {
                case ActivityAction.checkin:
                case ActivityAction.watching:
                case ActivityAction.pause:
                    imageFilename = "traktActivityWatching.png";
                    break;

                case ActivityAction.seen:
                case ActivityAction.scrobble:
                    imageFilename = "traktActivityWatched.png";
                    break;

                case ActivityAction.collection:
                    imageFilename = "traktActivityCollected.png";
                    break;

                case ActivityAction.rating:
                    imageFilename = activity.Rating > 5 ? "traktActivityLove.png" : "traktActivityHate.png";
                    break;

                case ActivityAction.watchlist:
                    imageFilename = "traktActivityWatchlist.png";
                    break;

                case ActivityAction.shout:
                case ActivityAction.review:
                    imageFilename = "traktActivityShout.png";
                    break;

                case ActivityAction.item_added:
                case ActivityAction.created:
                case ActivityAction.updated:
                    imageFilename = "traktActivityList.png";
                    break;

                case ActivityAction.like:
                    imageFilename = "traktActivityLike.png";
                    break;
            }

            return imageFilename;
        }
        private void ViewShout(TraktActivity.Activity activity)
        {
            switch (activity.Type)
            {
                case "movie":
                    TraktHelper.ShowMovieShouts(activity.Movie);
                    break;

                case "show":
                    TraktHelper.ShowTVShowShouts(activity.Show);
                    break;

                case "episode":
                    TraktHelper.ShowEpisodeShouts(activity.Show, activity.Episode);
                    break;

                default:
                    break;
            }
        }
        private void PublishActivityProperties(TraktActivity activity)
        {
            if (activity == null) return;

            var activities = activity.Activities;
            if (activities == null) return;

            int maxItems = activities.Count() < TraktSkinSettings.DashboardActivityFacadeMaxItems ? activities.Count() : TraktSkinSettings.DashboardActivityFacadeMaxItems;

            for (int i = 0; i < maxItems; i++)
            {
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Action", i), activities[i].Action);
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Type", i), activities[i].Type);
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.ActivityPinIcon", i), GetActivityImage(activities[i]));
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.ActivityPinIconNoExt", i), GetActivityImage(activities[i]).Replace(".png", string.Empty));
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Title", i), GUICommon.GetActivityItemName(activities[i]));
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Time", i), activities[i].Timestamp.FromISO8601().ToLocalTime().ToShortTimeString());
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Day", i), activities[i].Timestamp.FromISO8601().ToLocalTime().DayOfWeek.ToString().Substring(0, 3));
                GUIUtils.SetProperty(string.Format("#Trakt.Activity.{0}.Shout", i), GetActivityShoutText(activities[i]));
            }
        }
        private void LoadActivityFacade(TraktActivity activities, GUIFacadeControl facade)
        {
            if (TraktSkinSettings.DashBoardActivityWindows == null || !TraktSkinSettings.DashBoardActivityWindows.Contains(GUIWindowManager.ActiveWindow.ToString()))
                return;

            // if no activities report to user
            if (activities == null || activities.Activities == null || activities.Activities.Count == 0)
            {
                facade.Clear();

                var item = new GUIListItem(Translation.NoActivities);
                facade.Add(item);
                facade.SetCurrentLayout(TraktSkinSettings.DashboardActivityFacadeType);
                ClearSelectedActivityProperties();
                return;
            }

            // get the current view
            var view = (ActivityView)TraktSettings.ActivityStreamView;

            // if no new activities then nothing to do
            if (facade.Count > 0 && !ReloadActivityView)
            {
                var mostRecentActivity = facade[0].TVTag as TraktActivity.Activity;
                var lastActivity = facade[facade.Count - 1].TVTag as TraktActivity.Activity;

                if (mostRecentActivity != null && lastActivity != null)
                {
                    // only check the timestamp if only showing yourself
                    // check first and last because we may insert something in the middle between last load
                    if (view == ActivityView.me && mostRecentActivity.Timestamp == activities.Activities.First().Timestamp
                                                && lastActivity.Timestamp == activities.Activities.Last().Timestamp)
                        return;

                    if (mostRecentActivity.Timestamp == activities.Activities.First().Timestamp &&
                        mostRecentActivity.User.Username == activities.Activities.First().User.Username)
                    {
                        return;
                    }
                }
            }

            ReloadActivityView = false;
            TraktLogger.Debug("Loading Trakt Activity Facade");

            // stop any existing image downloads
            GUIUserListItem.StopDownload = true;

            // clear facade
            GUIControl.ClearControl(GUIWindowManager.ActiveWindow, facade.GetID);

            int itemId = 0;
            int PreviousSelectedIdx = -1;
            var userImages = new List<GUITraktImage>();

            // Add each activity item to the facade
            foreach (var activity in activities.Activities.Distinct().OrderByDescending(a => a.Timestamp))
            {
                if (PreviousSelectedIdx == -1 && PreviousSelectedActivity != null && TraktSettings.RememberLastSelectedActivity)
                {
                    if (activity.Equals(PreviousSelectedActivity))
                        PreviousSelectedIdx = itemId;
                }

                string itemLabel = GUICommon.GetActivityListItemTitle(activity, view);
                if (string.IsNullOrEmpty(itemLabel))
                    continue;

                var item = new GUIUserListItem(itemLabel, GUIWindowManager.ActiveWindow);

                string activityImage = GetActivityImage(activity);
                string avatarImage = GetAvatarImage(activity);

                // add image to download
                var images = new GUITraktImage { UserImages = activity.User.Images };
                if (avatarImage == "defaultTraktUser.png")
                    userImages.Add(images);

                item.Label2 = activity.Timestamp.ToPrettyDateTime();
                item.TVTag = activity;
                item.User = activity.User;
                item.Images = images;
                item.ItemId = Int32.MaxValue - itemId;
                item.IconImage = avatarImage;
                item.IconImageBig = avatarImage;
                item.ThumbnailImage = avatarImage;
                item.PinImage = activityImage;
                item.OnItemSelected += OnActivitySelected;
                facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            facade.SetCurrentLayout(TraktSkinSettings.DashboardActivityFacadeType);
            facade.SetVisibleFromSkinCondition();

            // Select previously selected item
            if (facade.LayoutControl.IsFocused && PreviousSelectedIdx >= 0)
                facade.SelectIndex(PreviousSelectedIdx);

            // set facade properties
            GUIUtils.SetProperty("#Trakt.Activity.Count", activities.Activities.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Activity.Items", string.Format("{0} {1}", activities.Activities.Count().ToString(), activities.Activities.Count() > 1 ? Translation.Activities : Translation.Activity));
            GUIUtils.SetProperty("#Trakt.Activity.Description", GetActivityDescription((ActivityView)TraktSettings.ActivityStreamView));

            // Download avatar images Async and set to facade
            GUIUserListItem.StopDownload = false;
            GUIUserListItem.GetImages(userImages);

            TraktLogger.Debug("Finished Loading Activity facade");
        }