internal void ChangeSort(string p) { int sum = 0; var artists = ArtistList.ToList(); var list = new List <ArtistViewModel>(); switch (p) { case "Name": ArtistList.Clear(); foreach (var artist in artists) { list.AddRange(artist); } var grouped = GroupedItem <ArtistViewModel> .CreateGroupsByAlpha(list); foreach (var item in grouped) { ArtistList.Add(new GroupedItem <ArtistViewModel>(item.Key, item)); sum += item.Sum(x => x.SongsCount); } ArtistsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartArtists"), artists.Count); SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), sum); break; default: break; } }
internal async void ChangeSort(int selectedIndex) { var albums = await FileReader.GetAllAlbumsAsync(); IEnumerable <GroupedItem <AlbumViewModel> > grouped; switch (selectedIndex) { case 0: grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.Year, true); break; case 1: grouped = GroupedItem <AlbumViewModel> .CreateGroupsByAlpha(albums.ConvertAll(x => new AlbumViewModel(x))); break; case 2: grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists()); break; default: grouped = GroupedItem <AlbumViewModel> .CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.Year, true); break; } AlbumList.Clear(); foreach (var item in grouped) { AlbumList.Add(item); } }
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")); } }); }
public async Task GetSongsAsync() { var songs = await FileReader.GetAllSongAsync(); var grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); //var grouped = GroupedItem<AlbumViewModel>.CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists()); //var grouped = GroupedItem<SongViewModel>.CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Year, true); var aCount = await FileReader.GetArtistsCountAsync(); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), songs.Count); ArtistsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartArtists"), aCount); }); var b = ThreadPool.RunAsync(async x => { var aa = (from s in songs group s by s.Album).ToList(); aa.Shuffle(); var list = new List <Uri>(); for (int j = 0; j < aa.Count && list.Count < 6; j++) { if (aa[j].FirstOrDefault().PicturePath.IsNullorEmpty()) { continue; } list.Add(new Uri(aa[j].FirstOrDefault().PicturePath)); } list.Shuffle(); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { HeroImage = list.ConvertAll(y => (ImageSource) new BitmapImage(y)); foreach (var item in SongsList) { foreach (var song in item) { song.RefreshFav(); } } }); }); }
internal async void ChangeSort(int selectedIndex) { var songs = await FileReader.GetAllSongAsync(); IEnumerable <GroupedItem <SongViewModel> > grouped; switch (selectedIndex) { case 0: grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); break; case 1: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.FormattedAlbum); break; case 2: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.GetFormattedArtists()); break; default: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Song.Year, true); break; } SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } foreach (var item in SongsList) { foreach (var song in item) { song.RefreshFav(); } } }
public async Task GetArtists() { var opr = SQLOperator.Current(); var artists = await opr.GetArtistsAsync(); var grouped = GroupedItem <ArtistViewModel> .CreateGroupsByAlpha(artists.ConvertAll(x => new ArtistViewModel { Name = x.AlbumArtists, SongsCount = x.Count })); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { ArtistList.Clear(); long sum = 0; foreach (var item in grouped) { ArtistList.Add(item); sum += item.Sum(x => x.SongsCount); } ArtistsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartArtists"), artists.Count); SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), sum); var t = ThreadPool.RunAsync(async x => { foreach (var item in ArtistList) { foreach (var art in item) { var uri = await opr.GetAvatarAsync(art.RawName); if (Uri.TryCreate(uri, UriKind.Absolute, out var u)) { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { art.Avatar = u; }); } else { } } } }); }); }
public void Init(StorageFile playlistFile) { this.playlistFile = playlistFile; Task.Run(async() => { playlist = await Playlist.LoadAsync(playlistFile); var list = new List <StorageSongViewModel>(); foreach (var item in playlist.Files) { try { using (var properties = TagLib.File.Create(item)) { var tag = properties.Tag; var song = await Song.Create(tag, item.Path, await item.GetViolatePropertiesAsync(), properties.Properties, null); list.Add(new StorageSongViewModel(song) { File = item }); } } catch (Exception) { continue; } } var grouped = GroupedItem <StorageSongViewModel> .CreateGroupsByAlpha(list); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), list.Count); Description = playlistFile.Path; Title = playlistFile.DisplayName; }); }); }
public async Task GetSongsAsync(PlayList model) { Model = await SQLOperator.Current().GetPlayListAsync(model.ID); if (Model == null) { return; } var songs = await SQLOperator.Current().GetSongsAsync(Model.SongsID); var grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); //var grouped = GroupedItem<AlbumViewModel>.CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists()); //var grouped = GroupedItem<SongViewModel>.CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Year, true); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), songs.Count); Description = Model.Description; Title = Model.Title; HeroImage = Array.ConvertAll(Model.HeroArtworks ?? new string[] { }, x => new Uri(x)).ToList(); foreach (var item in SongsList) { foreach (var song in item) { song.RefreshFav(); } } }); }
internal void ChangeSort(int selectedIndex) { var songs = SongsList.SelectMany(a => a).ToList(); SongsList.Clear(); IEnumerable <GroupedItem <StorageSongViewModel> > grouped; switch (selectedIndex) { case 0: grouped = GroupedItem <StorageSongViewModel> .CreateGroupsByAlpha(songs); break; case 1: grouped = GroupedItem <StorageSongViewModel> .CreateGroups(songs, x => x.FormattedAlbum); break; case 2: grouped = GroupedItem <StorageSongViewModel> .CreateGroups(songs, x => x.GetFormattedArtists()); break; default: grouped = GroupedItem <StorageSongViewModel> .CreateGroups(songs, x => x.Song.Year, true); break; } foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } }
public async Task Init(ArtistViewModel artist) { var b = ThreadPool.RunAsync(async x => { var art = await MainPageViewModel.Current.GetArtistInfoAsync(artist.RawName); if (art != null) { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { Artist.Description = art.Description; Artist.Avatar = art.AvatarUri; }); } }); var opr = SQLOperator.Current(); var albums = await opr.GetAlbumsOfArtistAsync(artist.RawName); var songs = await opr.GetSongsAsync(albums.SelectMany(s => s.Songs)); var empty = artist.RawName.IsNullorEmpty(); for (int i = songs.Count - 1; i >= 0; i--) { if (empty) { if (songs[i].Performers == null || songs[i].Performers.Length == 0) { continue; } else { songs.RemoveAt(i); } } else { var flag = false; if (songs[i].Performers != null) { foreach (var p in songs[i].Performers) { if (artist.RawName == p) { flag = true; break; } } } if (!flag) { if (songs[i].AlbumArtists == null || songs[i].AlbumArtists.Length == 0) { songs.RemoveAt(i); continue; } else { foreach (var p in songs[i].AlbumArtists) { if (artist.RawName == p) { flag = true; break; } } } } if (!flag) { songs.RemoveAt(i); } } } var grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); var a = albums.OrderByDescending(x => x.Year); var genres = (from alb in a where !alb.Genres.IsNullorEmpty() group alb by alb.Genres into grp orderby grp.Count() descending select grp.Key).FirstOrDefault(); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { AlbumList.Clear(); foreach (var item in a) { AlbumList.Add(new AlbumViewModel(item)); } SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartAlbums"), AlbumList.Count); Genres = genres.IsNullorEmpty() ? Consts.Localizer.GetString("VariousGenresText") : string.Join(Consts.CommaSeparator, genres); }); }
public async Task InitAsync() { var songs = await FileReader.GetAllSongAsync(); IEnumerable <GroupedItem <SongViewModel> > grouped; //var grouped = GroupedItem<AlbumViewModel>.CreateGroups(albums.ConvertAll(x => new AlbumViewModel(x)), x => x.GetFormattedArtists()); //var grouped = GroupedItem<SongViewModel>.CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Year, true); switch (Settings.Current.SongsSort) { case SortMode.Alphabet: grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); SortIndex = 0; break; case SortMode.Album: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.FormattedAlbum); SortIndex = 1; break; case SortMode.Artist: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.GetFormattedArtists()); SortIndex = 2; break; case SortMode.Year: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Song.Year); SortIndex = 3; break; default: grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); SortIndex = 0; break; } var aCount = await FileReader.GetArtistsCountAsync(); var favors = await SQLOperator.Current().GetFavoriteAsync(); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { SongsList.Clear(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } SongsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartSongs"), songs.Count); ArtistsCount = SmartFormat.Smart.Format(Consts.Localizer.GetString("SmartArtists"), aCount); foreach (var item in grouped) { foreach (var song in item) { if (favors.Count == 0) { return; } if (favors.Contains(song.ID)) { song.Favorite = true; favors.Remove(song.ID); } } } var tileId = "songs"; IsPinned = SecondaryTile.Exists(tileId); if (IsPinned) { Core.Tools.Tile.UpdateImage(tileId, SongsList.SelectMany(a => a.Where(c => c.Artwork != null).Select(b => b.Artwork.OriginalString)).Distinct().OrderBy(x => Guid.NewGuid()).Take(10).ToList(), Consts.Localizer.GetString("SongsText"), Consts.Localizer.GetString("SongsTile")); } }); }
internal async void ChangeSort(int selectedIndex) { SongsList.Clear(); var songs = await FileReader.GetAllSongAsync(); IEnumerable <GroupedItem <SongViewModel> > grouped; switch (selectedIndex) { case 0: grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); Settings.Current.SongsSort = SortMode.Alphabet; break; case 1: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.FormattedAlbum); Settings.Current.SongsSort = SortMode.Album; break; case 2: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.GetFormattedArtists()); Settings.Current.SongsSort = SortMode.Artist; break; case 3: grouped = GroupedItem <SongViewModel> .CreateGroups(songs.ConvertAll(x => new SongViewModel(x)), x => x.Song.Year); Settings.Current.SongsSort = SortMode.Year; break; default: grouped = GroupedItem <SongViewModel> .CreateGroupsByAlpha(songs.ConvertAll(x => new SongViewModel(x))); Settings.Current.SongsSort = SortMode.Alphabet; break; } SortIndex = selectedIndex; Settings.Current.Save(); foreach (var item in grouped) { item.Aggregate((x, y) => { y.Index = x.Index + 1; return(y); }); SongsList.Add(item); } //foreach (var item in SongsList) //{ // foreach (var song in item) // { // song.RefreshFav(); // } //} var favors = await SQLOperator.Current().GetFavoriteAsync(); foreach (var item in SongsList) { foreach (var song in item) { if (favors.Count == 0) { return; } if (favors.Contains(song.ID)) { song.Favorite = true; favors.Remove(song.ID); } } } }