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);
            }
        }
예제 #3
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"));
                }
            });
        }
예제 #4
0
        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();
                        }
                    }
                });
            });
        }
예제 #5
0
        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();
                }
            }
        }
예제 #6
0
        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 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());

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

            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 b = ThreadPool.RunAsync(async x =>
            {
                var aa = albums.ToList();
                aa.Shuffle();
                var list = new List <Uri>();
                for (int j = 0; j < aa.Count && list.Count < 6; j++)
                {
                    if (aa[j].PicturePath.IsNullorEmpty())
                    {
                        continue;
                    }
                    list.Add(new Uri(aa[j].PicturePath));
                }
                list.Shuffle();
                await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    HeroImage = list.ConvertAll(y => (ImageSource) new BitmapImage(y));
                });
            });
        }
        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();
                    }
                }
            });
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        public async Task GetSongsAsync(AlbumViewModel a)
        {
            Album = a;
            await a.GetSongsAsync();

            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                SongList.Clear();

                var songViewmodels = new List <SongViewModel>();

                for (int i = 0; i < a.Songs.Count; i++)
                {
                    songViewmodels.Add(new SongViewModel(a.Songs[i])
                    {
                        Index = (uint)i
                    });
                }

                var group = GroupedItem <SongViewModel> .CreateGroups(songViewmodels, s => s.Disc);

                foreach (var item in group)
                {
                    var ordered = item.OrderBy(s => s.Track).ToList();
                    item.Clear();
                    foreach (var o in ordered)
                    {
                        item.Add(o);
                    }
                    SongList.Add(item);
                }

                Task.Run(async() =>
                {
                    var favors = await SQLOperator.Current().GetFavoriteAsync();
                    await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        foreach (var disc in SongList)
                        {
                            foreach (var song in disc)
                            {
                                if (favors.Contains(song.ID))
                                {
                                    if (favors.Count == 0)
                                    {
                                        return;
                                    }
                                    song.Favorite = true;
                                    favors.Remove(song.ID);
                                }
                            }
                        }
                    });
                });
            });

            AlbumInfo info = null;

            try
            {
                if (Album.Name != null)
                {
                    info = await MainPageViewModel.Current.GetAlbumInfoAsync(Album.Name, Album.AlbumArtists?.FirstOrDefault());
                }
            }
            catch (Exception)
            {
            }
            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                if (info != null)
                {
                    if (Album.ArtworkUri == null && info.AltArtwork != null)
                    {
                        Album.ArtworkUri = info.AltArtwork;
                        var task         = ThreadPool.RunAsync(async k =>
                        {
                            if (!Album.IsOnline)
                            {
                                await SQLOperator.Current().UpdateAlbumArtworkAsync(album.ID, info.AltArtwork.OriginalString);
                            }
                        });
                    }
                    Album.Description = info.Description;
                }
                else
                {
                    Album.Description = $"# {Consts.Localizer.GetString("LocaAlbumTitle")}";
                }
            });
        }
예제 #11
0
        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"));
                }
            });
        }
예제 #12
0
        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);
                    }
                }
            }
        }