Exemplo n.º 1
0
        /// <summary>
        /// Class constructor for new-style navigation params.
        /// </summary>
        /// <param name="args">Navigation event args.</param>
        public LibraryViewModel(GroupedViewNavigationArgs args) : base(Window.Current.Dispatcher)
        {
            RegisterEventHandlers();

            _isGrouped = true;
            _viewType  = args.PageType;

            // Fallback or default title
            DesktopTitleViewConfiguration.SetTitleBarText(
                CommonSharedStrings.LibraryTitle);

            // Always set last used comparer.
            if (_viewType == CommonItemType.Song)
            {
                var groupState = new PageGroupingStateManager <CommonGroupedListView>(_viewType);
                var comparer   = groupState.GetLastUsedPair();
                GroupedItems = new GroupedSource(comparer.Indexer, comparer.GroupComparer, comparer.ItemComparer);
            }
            else if (_viewType == CommonItemType.Album || _viewType == CommonItemType.Artist)
            {
                var groupState = new PageGroupingStateManager <CommonGroupedGridView>(_viewType);
                var comparer   = groupState.GetLastUsedPair();
                GroupedItems = new GroupedSource(comparer.Indexer, comparer.GroupComparer, comparer.ItemComparer);
            }
            else
            {
                GroupedItems = new GroupedSource(args.EntityIndexer, args.GroupComparer, args.ItemComparer);
            }
        }
Exemplo n.º 2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _navigationHelper.OnNavigatedTo(e);
            DesktopTitleViewConfiguration.SetTitleBarText(CommonSharedStrings.Home);
            base.OnNavigatedTo(e);

            if (AllFiles.Count == 0 && !LibraryService.IsIndexing)
            {
                await Task.Run(async() =>
                {
                    using (var scope = ApplicationServiceBase.App.GetScope())
                        using (var context = scope.ServiceProvider.GetRequiredService <MedialibraryDbContext>())
                        {
                            var files = Shuffle(context.MediaFiles, _random);
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                foreach (var file in files)
                                {
                                    AllFiles.Add(file);
                                }
                                EmptyIndicator.Visibility = AllFiles.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
                            });
                        }
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles page navigation.
        /// </summary>
        /// <param name="e">Instance of <see cref="NavigationEventArgs"/>.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Set title
            DesktopTitleViewConfiguration.SetTitleBarText(CommonSharedStrings.SettingsTitle);

            m_helper.OnNavigatedTo(e);
            base.OnNavigatedTo(e);

            LoadEntries();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Class constructor.
        /// </summary>
        /// <param name="type">Item type.</param>
        /// <param name="isGrouped">Indicates whether the value has been grouped.</param>
        public LibraryViewModel(CommonItemType type, bool isGrouped = false, string keyWord = "") : base(Window.Current.Dispatcher)
        {
            RegisterEventHandlers();

            _isGrouped = isGrouped;
            _viewType  = type;

            // Fallback or default title
            DesktopTitleViewConfiguration.SetTitleBarText(
                CommonSharedStrings.LibraryTitle);
        }
Exemplo n.º 5
0
        private async void OnNowPlayingItemChanged(object sender, NowPlayingChangedEventArgs e)
        {
            await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var metadata = e.NewItem?.File;
                if (metadata == null)
                {
                    return;
                }

                NowPlayingItem = e.NewItem;
                CheckFavorite();

                NowPlayingTitle     = metadata.Title;
                NowPlayingArtist    = metadata.Artist;
                NowPlayingAlbum     = metadata.Album;
                NowPlayingTotalTime = metadata.Duration;

                // Update cover, if available
                CoverImage = new ThumbnailTag
                {
                    Fallback      = "Album,AlbumPlaceholder",
                    AlbumName     = metadata.Album,
                    ArtistName    = metadata.Artist,
                    ThumbnailPath = metadata.Path,
                };
                if (!string.IsNullOrWhiteSpace(NowPlayingTitle))
                {
                    DesktopTitleViewConfiguration.SetTitleBarText(
                        string.Format(CommonSharedStrings.NowPlayingTitle, NowPlayingTitle));
                }
                else
                {
                    DesktopTitleViewConfiguration.SetTitleBarText(CommonSharedStrings.NowPlayingEmptyTitle);
                }
                //Call LrcAutoSearch on playlist item changed
                await LrcAutoSearch();
            });
        }
Exemplo n.º 6
0
        public async Task LoadTitleAsync()
        {
            _backendAlbum = await EntityRetrievalExtensions.GetAlbumByIdAsync(_itemId);

            if (_backendAlbum != null)
            {
                CoverImageTag = new ThumbnailTag
                {
                    Fallback      = "Album,AlbumPlaceholder",
                    ArtistName    = _backendAlbum.Artist,
                    AlbumName     = _backendAlbum.Title,
                    ThumbnailPath = _backendAlbum.FirstFileInAlbum,
                };

                // Get album detailed information
                Title  = _backendAlbum.Title;
                Artist = _backendAlbum.Artist;
                Year   = DateTimeHelper.GetItemDateYearString(_backendAlbum.Date);
                Intro  = _backendAlbum.Intro;
                Genre  = _backendAlbum.Genre;
                DesktopTitleViewConfiguration.SetTitleBarText(Title);
            }
        }
Exemplo n.º 7
0
        public void RegisterEvents()
        {
            PlaylistManager.Instance.FavoriteChanged   += OnFavoriteChanged;
            PlaybackControl.Instance.NowPlayingChanged += OnNowPlayingItemChanged;
            var metadata = PlaybackControl.Instance.Current?.File;

            if (metadata != null)
            {
                NowPlayingItem = PlaybackControl.Instance.Current;
                CheckFavorite();

                NowPlayingTitle     = metadata.Title;
                NowPlayingArtist    = metadata.Artist;
                NowPlayingAlbum     = metadata.Album;
                NowPlayingTotalTime = metadata.Duration;

                // Update cover, if available
                CoverImage = new ThumbnailTag
                {
                    Fallback      = "Album,AlbumPlaceholder",
                    AlbumName     = metadata.Album,
                    ArtistName    = metadata.Artist,
                    ThumbnailPath = metadata.Path,
                };
            }
            if (!string.IsNullOrWhiteSpace(NowPlayingTitle))
            {
                DesktopTitleViewConfiguration.SetTitleBarText(
                    string.Format(CommonSharedStrings.NowPlayingTitle, NowPlayingTitle));
            }
            else
            {
                DesktopTitleViewConfiguration.SetTitleBarText(
                    CommonSharedStrings.NowPlayingEmptyTitle);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Load data from database.
        /// </summary>
        /// <returns>An awaitable task.</returns>
        public async Task LoadDataAsync()
        {
            var elem = await EntityRetrievalExtensions.GetAlbumByIdAsync(_itemId);

            if (elem != null)
            {
                _backendAlbum = elem;

                CoverImageTag = new ThumbnailTag
                {
                    Fallback      = "Album,AlbumPlaceholder",
                    ArtistName    = _backendAlbum.Artist,
                    AlbumName     = _backendAlbum.Title,
                    ThumbnailPath = _backendAlbum.FirstFileInAlbum,
                };

                #region Basic Info
                // Get album detailed information
                Title  = elem.Title;
                Artist = elem.Artist;
                Year   = DateTimeHelper.GetItemDateYearString(elem.Date);
                Intro  = elem.Intro;
                Genre  = elem.Genre;
                DesktopTitleViewConfiguration.SetTitleBarText(Title);
                #endregion

                #region Items

                var tempOrderedItem       = new List <Tuple <int, int, DbMediaFile> >();
                var dbFileAsyncEnumerator = elem.MediaFiles.ToAsyncEnumerable().GetEnumerator();
                if (dbFileAsyncEnumerator != null)
                {
                    while (await dbFileAsyncEnumerator.MoveNext())
                    {
                        var item = dbFileAsyncEnumerator.Current;
                        int discNum = 0, trackNum = 0;
                        int.TryParse(item.DiscNumber, out discNum);
                        int.TryParse(item.TrackNumber, out trackNum);
                        tempOrderedItem.Add(new Tuple <int, int, DbMediaFile>(discNum, trackNum, item));
                    }
                }

                // Disk and Track
                var sortedItem = tempOrderedItem.OrderBy(i => i.Item1)
                                 .ThenBy(i => i.Item2);

                // Add subitems to the ListView data entity set
                foreach (var s in sortedItem)
                {
                    if (s == null)
                    {
                        continue;
                    }
                    ViewItems.Add(s.Item3);
                }
                #endregion
            }

            // Mark complete
            IsLoading = false;
        }
Exemplo n.º 9
0
        public async Task LoadContentAsync()
        {
            if (_backendArtist == null)
            {
                return;
            }

            HashSet <string> knownAlbums = new HashSet <string>();

            var albumAsyncEnumerator = _backendArtist.Albums.ToAsyncEnumerable().GetEnumerator();

            if (albumAsyncEnumerator != null)
            {
                while (await albumAsyncEnumerator.MoveNext())
                {
                    var album = albumAsyncEnumerator.Current;
                    album.MediaFiles = album.MediaFiles
                                       .OrderBy(x => ParseWithFallback(x.DiscNumber))
                                       .ThenBy(x => ParseWithFallback(x.TrackNumber))
                                       .ToList();
                    knownAlbums.Add(album.Title);
                    ArtistAlbums.Add(album);
                }
            }

            List <DbMediaFile> otherMusic = new List <DbMediaFile>();

            TimeSpan totalTime = TimeSpan.Zero;

            var artistAsyncEnumerator = _backendArtist.MediaFiles.ToAsyncEnumerable().GetEnumerator();

            if (artistAsyncEnumerator != null)
            {
                while (await artistAsyncEnumerator.MoveNext())
                {
                    var current = artistAsyncEnumerator.Current;
                    if (!knownAlbums.Contains(current.Album))
                    {
                        otherMusic.Add(current);
                    }
                    totalTime += current.Duration;
                }
            }

            var otherAlbums = otherMusic
                              .GroupBy(x => x.Album)
                              .Select(x =>
            {
                var f = x.First();
                return(new DbAlbum()
                {
                    Title = f.Album,
                    Artist = f.AlbumArtist,
                    Date = f.Date,
                    MediaFiles = x
                                 .OrderBy(k => ParseWithFallback(k.DiscNumber))
                                 .ThenBy(k => ParseWithFallback(k.TrackNumber))
                                 .ToList()
                });
            });

            foreach (var other in otherAlbums)
            {
                ArtistAlbums.Add(other);
            }

            TotalAlbums = ArtistAlbums.Count.ToString();

            TotalDuration = $"{(int)totalTime.TotalMinutes}:{totalTime.Seconds:00}";
            IsLoading     = false;
            DesktopTitleViewConfiguration.SetTitleBarText(ArtistName);
        }