public async Task LoadAlbums() { //foreach(var album in await GetAlbums().ConfigureAwait(false)) //{ AlbumCollection.AddRange(await GetAlbums().ConfigureAwait(false));//.Add(album); // } }
public async Task LoadAlbums() { AlbumCollection.AddRange(await AlbumService.GetAlbumsAsync().ConfigureAwait(false));//.Add(album); AlbumCollection.CollectionChanged += AlbumCollection_CollectionChanged; if (AlbumCollection.Count <= 0) { AlbumsLoaded = false; } }
public async Task LoadAlbums() { RecordsLoading = true; if (AlbumCollection?.Count <= 0) { AlbumCollection.AddRange(await AlbumArtistService.GetAlbumsAsync().ConfigureAwait(false));//.Add(album); AlbumCollection.CollectionChanged += AlbumCollection_CollectionChanged; if (AlbumCollection.Count <= 0) { RecordsLoading = false; } } }
private async void AllMusic_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: MusicCollection.AddRange(e.NewItems.Cast <LocalMusic>()); // ArtistCollection.AddRange(e.NewItems.Cast<LocalMusic>()); AlbumCollection.AddRange(e.NewItems.Cast <LocalMusic>()); break; case NotifyCollectionChangedAction.Remove: foreach (LocalMusic item in e.OldItems) { MusicCollection.Remove(item); // ArtistCollection.Remove(item); AlbumCollection.Remove(item); } await ArtistCollection.AddRangeAsync(AllMusic.GroupBy(x => x.ArtistsName?.FirstOrDefault() ?? "未知艺术家").ToDictionary(x => x.Key, x => x.ToArray()) .Select(x => new LocalArtist { Name = x.Key, PicPath = x.Value.First().Id3Pic, LocalMusics = x.Value })); break; case NotifyCollectionChangedAction.Replace: break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Reset: MusicCollection.Clear(); ArtistCollection.Clear(); AlbumCollection.Clear(); break; default: throw new ArgumentOutOfRangeException(); } }