示例#1
0
        public override async void Activate()
        {
            if (Albums.IsNullOrEmpty())
            {
                await LoadAlbums();
            }

            if (Artists.IsNullOrEmpty())
            {
                await LoadArtists(_cancellationToken.Token);
            }
        }
示例#2
0
        private async Task LoadSelectedArtist()
        {
            if (SelectedArtist == null)
            {
                return;
            }

            OnTaskStarted("artists");

            try
            {
                if (Albums.IsNullOrEmpty())
                {
                    await LoadAlbums();
                }

                var albums = await ServiceLocator.LocalMusicService.GetArtistAlbums(SelectedArtist.Id);

                if (!albums.IsNullOrEmpty())
                {
                    foreach (var album in albums)
                    {
                        var tracks = await ServiceLocator.LocalMusicService.GetAlbumTracks(album.Id);

                        if (!tracks.IsNullOrEmpty())
                        {
                            album.Tracks = tracks.Cast <Audio>().ToList();
                        }
                    }
                }
                else
                {
                    albums = new List <AudioAlbum>();
                }

                if (SelectedArtist == null)
                {
                    return;
                }

                var unsortedTracks = await ServiceLocator.LocalMusicService.GetArtistUnsortedTracks(SelectedArtist.Id);

                if (!unsortedTracks.IsNullOrEmpty())
                {
                    var unsortedAlbum = new AudioAlbum()
                    {
                        Tracks = unsortedTracks.OfType <Audio>().ToList()
                    };
                    albums.Insert(0, unsortedAlbum);
                }

                SelectedArtistAlbums = albums;
                SelectedArtistTracks = albums.SelectMany(a => a.Tracks).Cast <LocalAudio>().ToList();
            }
            catch (Exception ex)
            {
                OnTaskError("artists", ErrorResources.LoadArtistsErrorCommon);

                LoggingService.Log(ex);
            }

            OnTaskFinished("artists");
        }