/// <summary>
        /// Initializes a new instance of the ActorViewModel class.
        /// </summary>
        public ActorViewModel(IExtendedApiClient apiClient, INavigationService navigationService)
        {
            _apiClient = apiClient;
            _navigationService = navigationService;

            if (IsInDesignMode)
            {
                SelectedPerson = new BaseItemPerson {Name = "Jeff Goldblum"};
                var list = new List<BaseItemDto>
                {
                    new BaseItemDto
                    {
                        Id = "6536a66e10417d69105bae71d41a6e6f",
                        Name = "Jurassic Park",
                        SortName = "Jurassic Park",
                        Overview = "Lots of dinosaurs eating people!",
                        People = new[]
                        {
                            new BaseItemPerson {Name = "Steven Spielberg", Type = "Director"},
                            new BaseItemPerson {Name = "Sam Neill", Type = "Actor"},
                            new BaseItemPerson {Name = "Richard Attenborough", Type = "Actor"},
                            new BaseItemPerson {Name = "Laura Dern", Type = "Actor"}
                        }
                    }
                };

                Films = Utils.GroupItemsByName(list).Result;
            }
        
        }
Ejemplo n.º 2
0
        public PersonListItemViewModel(BaseItemPerson person, IApiClient apiClient, IImageManager imageManager, ISessionManager sessionManager, INavigator navigator)
        {
            _person = person;
            _apiClient = apiClient;
            _imageManager = imageManager;
            _sessionManager = sessionManager;
            _navigator = navigator;

            NavigateCommand = new RelayCommand(arg => NavigateToPerson());
        }
Ejemplo n.º 3
0
        public void NavigateTo(BaseItemDto item)
        {
            App.SelectedItem = item;
            var type = item.Type.ToLower();
            if (type.Contains("collectionfolder")) type = "collectionfolder";
            if (type.StartsWith("genre")) type = "genre";
            switch (type)
            {
                case "collectionfolder":
                case "genre":
                case "trailercollectionfolder":
                case "playlistsfolder":
                case "userview":
                    var viewType = string.IsNullOrEmpty(item.CollectionType) ? string.Empty : item.CollectionType.ToLower();
                    switch (viewType)
                    {
                        case "movies":
                            var moviesVm = SimpleIoc.Default.GetInstance<MovieCollectionViewModel>();
                            moviesVm.SetParentId(item.Id);

                            NavigateTo(Constants.Pages.Predefined.MovieCollectionView);
                            break;
                        case "tvshows":
                            var tvVm = SimpleIoc.Default.GetInstance<TvCollectionViewModel>();
                            tvVm.SetParentId(item.Id);

                            NavigateTo(Constants.Pages.Predefined.TvCollectionView);
                            break;
                        case "music":
                            var musicVm = SimpleIoc.Default.GetInstance<MusicCollectionViewModel>();
                            musicVm.SetParentId(item.Id);

                            NavigateTo(Constants.Pages.Predefined.MusicCollectionView);
                            break;
                        case "channels":
                            NavigateTo(Constants.Pages.Channels.ChannelsView);
                            break;
                        case "livetv":
                            NavigateTo(Constants.Pages.LiveTv.LiveTvView);
                            break;
                        case "playlists":
                            NavigateTo(Constants.Pages.FolderView + item.Id);
                            break;
                        default:
                            if (App.SpecificSettings.JustShowFolderView)
                            {
                                NavigateTo(Constants.Pages.FolderView + item.Id);
                            }
                            else
                            {
                                NavigateTo(Constants.Pages.CollectionView);
                            }
                            break;
                    }
                    break;
                case "photoalbum":
                case "folder":
                case "boxset":
                    NavigateTo(Constants.Pages.FolderView + item.Id);
                    break;
                case "movie":
                    NavigateTo(Constants.Pages.MovieView);
                    break;
                case "series":
                    NavigateTo(Constants.Pages.TvShowView);
                    break;
                case "season":
                    NavigateTo(Constants.Pages.SeasonView);
                    break;
                case "episode":
                    NavigateTo(Constants.Pages.EpisodeView);
                    break;
                case "trailer":
                    if (SimpleIoc.Default.GetInstance<TrailerViewModel>() != null)
                    {
                        Messenger.Default.Send(new NotificationMessage(Constants.Messages.ChangeTrailerMsg));
                        NavigateTo(Constants.Pages.TrailerView);
                    }
                    break;
                case "musicartist":
                case "artist":
                    if (SimpleIoc.Default.GetInstance<MusicViewModel>() != null)
                    {
                        Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.MusicArtistChangedMsg));
                        NavigateTo(Constants.Pages.ArtistView);
                    }
                    break;
                case "musicalbum":
                    if (SimpleIoc.Default.GetInstance<MusicViewModel>() != null)
                    {
                        Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.MusicAlbumChangedMsg));
                        NavigateTo(Constants.Pages.AlbumView);
                    }
                    break;
                case "channel":
                case "channelfolderitem":
                    NavigateTo(Constants.Pages.Channels.ChannelView + item.Id);
                    break;
                case "playlist":
                    if (SimpleIoc.Default.GetInstance<ServerPlaylistsViewModel>() != null)
                    {
                        Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.ServerPlaylistChangedMsg));
                        NavigateTo(Constants.Pages.Playlists.PlaylistView);
                    }
                        
                    break;
                case "person":
                    var actor = new BaseItemPerson
                    {
                        Name = item.Name,
                        Id = item.Id,
                        PrimaryImageTag = item.HasPrimaryImage ? item.ImageTags.FirstOrDefault(x => x.Key == ImageType.Primary).Value : string.Empty
                    };

                    App.SelectedItem = actor;
                    NavigateTo(Constants.Pages.ActorView);
                    break;
                default:
                    if (SimpleIoc.Default.GetInstance<GenericItemViewModel>() != null)
                    {
                        Messenger.Default.Send(new NotificationMessage(item, Constants.Messages.GenericItemChangedMsg));
                        NavigateTo(Constants.Pages.GenericItemView);
                    }

                    break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attaches People DTO's to a DTOBaseItem
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <returns>Task.</returns>
        private async Task AttachPeople(BaseItemDto dto, BaseItem item)
        {
            // Ordering by person type to ensure actors and artists are at the front.
            // This is taking advantage of the fact that they both begin with A
            // This should be improved in the future
            var people = item.People.OrderBy(i => i.Type).ToList();

            // Attach People by transforming them into BaseItemPerson (DTO)
            dto.People = new BaseItemPerson[people.Count];

            var entities = await Task.WhenAll(people.Select(p => p.Name)
                .Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
                    Task.Run(async () =>
                    {
                        try
                        {
                            return await _libraryManager.GetPerson(c).ConfigureAwait(false);
                        }
                        catch (IOException ex)
                        {
                            _logger.ErrorException("Error getting person {0}", ex, c);
                            return null;
                        }
                    })

            )).ConfigureAwait(false);

            var dictionary = entities.Where(i => i != null)
                .DistinctBy(i => i.Name)
                .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);

            for (var i = 0; i < people.Count; i++)
            {
                var person = people[i];

                var baseItemPerson = new BaseItemPerson
                {
                    Name = person.Name,
                    Role = person.Role,
                    Type = person.Type
                };

                Person entity;

                if (dictionary.TryGetValue(person.Name, out entity))
                {
                    var primaryImagePath = entity.PrimaryImagePath;

                    if (!string.IsNullOrEmpty(primaryImagePath))
                    {
                        baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
                    }
                }

                dto.People[i] = baseItemPerson;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attaches People DTO's to a DTOBaseItem
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <returns>Task.</returns>
        private void AttachPeople(BaseItemDto dto, BaseItem item)
        {
            // Ordering by person type to ensure actors and artists are at the front.
            // This is taking advantage of the fact that they both begin with A
            // This should be improved in the future
            var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue)
                .ThenBy(i =>
                {
                    if (i.IsType(PersonType.Actor))
                    {
                        return 0;
                    }
                    if (i.IsType(PersonType.GuestStar))
                    {
                        return 1;
                    }
                    if (i.IsType(PersonType.Director))
                    {
                        return 2;
                    }
                    if (i.IsType(PersonType.Writer))
                    {
                        return 3;
                    }
                    if (i.IsType(PersonType.Producer))
                    {
                        return 4;
                    }
                    if (i.IsType(PersonType.Composer))
                    {
                        return 4;
                    }

                    return 10;
                })
                .ToList();

            var list = new List<BaseItemPerson>();

            var dictionary = people.Select(p => p.Name)
                .Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
                {
                    try
                    {
                        return _libraryManager.GetPerson(c);
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorException("Error getting person {0}", ex, c);
                        return null;
                    }

                }).Where(i => i != null)
                .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
                .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);

            for (var i = 0; i < people.Count; i++)
            {
                var person = people[i];

                var baseItemPerson = new BaseItemPerson
                {
                    Name = person.Name,
                    Role = person.Role,
                    Type = person.Type
                };

                Person entity;

                if (dictionary.TryGetValue(person.Name, out entity))
                {
                    baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
                    baseItemPerson.Id = entity.Id.ToString("N");
                    list.Add(baseItemPerson);
                }
            }

            dto.People = list.ToArray();
        }
 public ItemPersonViewModel(BaseItemPerson person, IApiClient apiClient, IImageManager imageManager)
 {
     _person = person;
     _apiClient = apiClient;
     _imageManager = imageManager;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Attaches People DTO's to a DTOBaseItem
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <returns>Task.</returns>
        private void AttachPeople(BaseItemDto dto, BaseItem item)
        {
            // Ordering by person type to ensure actors and artists are at the front.
            // This is taking advantage of the fact that they both begin with A
            // This should be improved in the future
            var people = item.People.OrderBy(i => i.SortOrder ?? int.MaxValue).ThenBy(i => i.Type).ToList();

            // Attach People by transforming them into BaseItemPerson (DTO)
            dto.People = new BaseItemPerson[people.Count];

            var dictionary = people.Select(p => p.Name)
                .Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
                {
                    try
                    {
                        return _libraryManager.GetPerson(c);
                    }
                    catch (IOException ex)
                    {
                        _logger.ErrorException("Error getting person {0}", ex, c);
                        return null;
                    }

                }).Where(i => i != null)
                .DistinctBy(i => i.Name)
                .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);

            for (var i = 0; i < people.Count; i++)
            {
                var person = people[i];

                var baseItemPerson = new BaseItemPerson
                {
                    Name = person.Name,
                    Role = person.Role,
                    Type = person.Type
                };

                Person entity;

                if (dictionary.TryGetValue(person.Name, out entity))
                {
                    baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
                }

                dto.People[i] = baseItemPerson;
            }
        }