Exemplo n.º 1
0
        public async Task GetAlbums()
        {
            var albums = await FileReader.GetAllAlbumsAsync();

            //var grouped = GroupedItem<AlbumViewModel>.CreateGroupsByAlpha(albums.ConvertAll(x => new AlbumViewModel(x)));

            //var grouped = GroupedItem<AlbumViewModel>.CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists());
            IEnumerable <GroupedItem <AlbumViewModel> > grouped;

            switch (Settings.Current.AlbumsSort)
            {
            case SortMode.Alphabet:
                grouped = GroupedItem <AlbumViewModel> .CreateGroupsByAlpha(albums.ConvertAll(x => new AlbumViewModel(x)));

                SortIndex = 1;
                break;

            case SortMode.Year:
                grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.Year, true);

                SortIndex = 0;
                break;

            case SortMode.Artist:
                grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists());

                SortIndex = 2;
                break;

            default:
                grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.Year, true);

                SortIndex = 0;
                break;
            }

            var aCount = await FileReader.GetArtistsCountAsync();

            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                AlbumList.Clear();
                foreach (var item in grouped)
                {
                    AlbumList.Add(item);
                }
                SongsCount   = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartAlbums"), albums.Count);
                ArtistsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartArtists"), aCount);


                var tileId = "albums";
                IsPinned   = SecondaryTile.Exists(tileId);

                if (IsPinned)
                {
                    Core.Tools.Tile.UpdateImage(tileId, AlbumList.SelectMany(a => a.Where(c => c.ArtworkUri != null).Select(b => b.ArtworkUri.OriginalString)).Distinct().OrderBy(x => Guid.NewGuid()).Take(10).ToList(), Consts.Localizer.GetString("AlbumsText"), Consts.Localizer.GetString("AlbumsTile"));
                }
            });
        }