Esempio n. 1
0
 public static MenuFlyoutSubItem AppendRecentAddedItem(MenuFlyoutSubItem parent, object title, List <Music> songs, int limit)
 {
     if (songs.Count > 0)
     {
         var recenItem = new MenuFlyoutItem()
         {
             Text = title is string stringTitle?Helper.LocalizeMessage(stringTitle) : title.ToString()
         };
         recenItem.Click += (sender, args) =>
         {
             MediaHelper.SetPlaylistAndPlay(songs.RandItems(limit));
         };
         parent.Items.Add(recenItem);
     }
     return(parent);
 }
Esempio n. 2
0
        public static MenuFlyout GetShuffleMenu(int limit = 100)
        {
            var flyout     = new MenuFlyout();
            var nowPlaying = new MenuFlyoutItem()
            {
                Text = Helper.Localize("NowPlaying")
            };

            nowPlaying.Click += (sender, args) =>
            {
                MediaHelper.ShuffleAndPlay();
            };
            flyout.Items.Add(nowPlaying);
            flyout.Items.Add(new MenuFlyoutSeparator());
            var musicLibrary = new MenuFlyoutItem()
            {
                Text = Helper.Localize("Music Library")
            };

            musicLibrary.Click += (sender, args) =>
            {
                MediaHelper.SetPlaylistAndPlay(MusicLibraryPage.AllSongs.RandItems(limit));
            };
            flyout.Items.Add(musicLibrary);
            var artist = new MenuFlyoutItem()
            {
                Text = Helper.Localize("Artist")
            };

            artist.Click += (sender, args) =>
            {
                var rArtist = MusicLibraryPage.AllSongs.GroupBy(m => m.Artist).RandItem();
                MediaHelper.SetPlaylistAndPlay(rArtist.Shuffle());
                Helper.ShowNotificationWithoutLocalization(Helper.LocalizeMessage("PlayRandomArtist", rArtist.Key));
            };
            flyout.Items.Add(artist);
            var album = new MenuFlyoutItem()
            {
                Text = Helper.Localize("Album")
            };

            album.Click += (sender, args) =>
            {
                var rAlbum = MusicLibraryPage.AllSongs.GroupBy(m => m.Album).RandItem();
                MediaHelper.SetPlaylistAndPlay(rAlbum.Shuffle());
                Helper.ShowNotificationWithoutLocalization(Helper.LocalizeMessage("PlayRandomAlbum", rAlbum.Key));
            };
            flyout.Items.Add(album);
            if (Settings.settings.Playlists.Count > 0)
            {
                var playlist = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Playlist")
                };
                playlist.Click += (sender, args) =>
                {
                    var rPlaylist = Settings.settings.Playlists.RandItem();
                    MediaHelper.SetPlaylistAndPlay(rPlaylist.Songs.RandItems(limit));
                    Helper.ShowNotificationWithoutLocalization(Helper.LocalizeMessage("PlayRandomPlaylist", rPlaylist.Name));
                };
                flyout.Items.Add(playlist);
            }
            if (!string.IsNullOrEmpty(Settings.settings.RootPath))
            {
                var localFolder = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Local Folder")
                };
                localFolder.Click += (sender, args) =>
                {
                    var rLocalFolder = Settings.settings.Tree.GetAllTrees().Where(tree => tree.Files.Count > 0).RandItem();
                    MediaHelper.SetMusicAndPlay(rLocalFolder.Files.RandItems(limit));
                    Helper.ShowNotificationWithoutLocalization(Helper.LocalizeMessage("PlayRandomLocalFolder", rLocalFolder.Directory));
                };
                flyout.Items.Add(localFolder);
            }
            if (RecentPage.RecentAdded?.Count > 0)
            {
                var recentAdded = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Recent Added")
                };
                recentAdded.Click += (sender, args) =>
                {
                    MediaHelper.SetMusicAndPlay(RecentPage.RecentAdded.TimeLine.RandItems(limit));
                };
                flyout.Items.Add(recentAdded);
            }
            if (Settings.settings.RecentPlayed.Count > 0)
            {
                var recentPlayed = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Recent Played")
                };
                recentPlayed.Click += (sender, args) =>
                {
                    MediaHelper.SetMusicAndPlay(Settings.settings.RecentPlayed.ToMusicList());
                };
                flyout.Items.Add(recentPlayed);
            }
            if (MusicLibraryPage.SongCount > limit)
            {
                flyout.Items.Add(new MenuFlyoutSeparator());
                var mostPlayed = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Most Played")
                };
                mostPlayed.Click += (sender, args) =>
                {
                    List <Music> list = new List <Music>();
                    foreach (var group in MusicLibraryPage.AllSongs.GroupBy(m => m.PlayCount).OrderByDescending(g => g.Key))
                    {
                        if (list.Count > limit)
                        {
                            break;
                        }
                        list.AddRange(group);
                    }
                    MediaHelper.SetPlaylistAndPlay(list.Shuffle().Take(limit));
                };
                flyout.Items.Add(mostPlayed);
                var leastPlayed = new MenuFlyoutItem()
                {
                    Text = Helper.Localize("Least Played")
                };
                leastPlayed.Click += (sender, args) =>
                {
                    List <Music> list = new List <Music>();
                    foreach (var group in MusicLibraryPage.AllSongs.GroupBy(m => m.PlayCount).OrderBy(g => g.Key))
                    {
                        if (list.Count > limit)
                        {
                            break;
                        }
                        list.AddRange(group);
                    }
                    MediaHelper.SetPlaylistAndPlay(list.Shuffle().Take(limit));
                };
                flyout.Items.Add(leastPlayed);
            }
            return(flyout);
        }