public MenuFlyout GetPlaylistMenuFlyout(IMenuFlyoutItemClickListener listener = null, MenuFlyoutOption option = null) { if (option == null) { option = new MenuFlyoutOption() { ShowSelect = false } } ; var flyout = new MenuFlyout(); var shuffleItem = new MenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Shuffle), Text = Helper.Localize("Shuffle"), Name = PlaylistMenuName }; shuffleItem.SetToolTip("Shuffle and Play"); shuffleItem.Click += (s, args) => { MediaHelper.ShuffleAndPlay(Data as IEnumerable <Music>); }; flyout.Items.Add(shuffleItem); flyout.Items.Add(GetAddToMenuFlyoutSubItem(listener)); if (option.ShowMultiSelect) { flyout.Items.Add(GetMultiSelectItem(listener, option.MultiSelectOption)); } else if (option.ShowSelect) { flyout.Items.Add(GetSelectItem(listener, option.MultiSelectOption)); } return(flyout); }
public static MenuFlyoutItem GetRemovableMenuFlyoutItem(Music music, IMenuFlyoutItemClickListener listener = null) { var removeItem = new MenuFlyoutItem { Icon = new SymbolIcon(Symbol.Remove), Text = Helper.Localize("Remove From List") }; removeItem.Click += (sender, args) => { listener?.Remove(music); }; removeItem.SetToolTip(Helper.LocalizeMessage("RemoveFromList", music.Name), false); return(removeItem); }
public MenuFlyout GetMusicMenuFlyout(IMenuFlyoutItemClickListener listener = null, MenuFlyoutOption option = null) { if (option == null) { option = new MenuFlyoutOption(); } Music music = (Data as IMusicable).ToMusic(); var flyout = new MenuFlyout(); var localizedPlay = Helper.Localize("Play"); var playItem = new MenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Play), Text = localizedPlay, Name = MusicMenuName }; playItem.SetToolTip(localizedPlay + Helper.LocalizeMessage("MusicName", music.Name)); playItem.Click += (s, args) => { MediaHelper.SetMusicAndPlay(music); }; flyout.Items.Add(playItem); if (MediaHelper.CurrentMusic != null && music != MediaHelper.CurrentMusic) { var playNextItem = new MenuFlyoutItem() { Text = Helper.LocalizeText("PlayNext"), Icon = new SymbolIcon(Symbol.Upload) }; playNextItem.Click += (s, args) => { int index = MediaHelper.CurrentMusic.Index + 1; if (music.Index >= 0) { MediaHelper.MoveMusic(music.Index, index); } else { MediaHelper.AddMusic(music, index); listener?.AddTo(music, MediaHelper.CurrentPlaylist, index, AddToCollectionType.NowPlaying); foreach (var clickListener in ClickListeners) { clickListener.AddTo(music, MediaHelper.CurrentPlaylist, index, AddToCollectionType.NowPlaying); } } Helper.ShowNotificationWithoutLocalization(Helper.LocalizeMessage("SetPlayNext", music.Name)); }; flyout.Items.Add(playNextItem); } flyout.Items.Add(GetAddToMenuFlyoutSubItem(listener)); if (option.ShowRemove) { flyout.Items.Add(GetRemovableMenuFlyoutItem(music, listener)); } if (option.ShowSelect || option.MultiSelectOption != null) { flyout.Items.Add(GetSelectItem(listener, option.MultiSelectOption)); } flyout.Items.Add(GetShowInExplorerItem(music.Path, StorageItemTypes.File)); var deleteItem = new MenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Delete), Text = Helper.Localize("Delete From Disk") }; deleteItem.Click += async(s, args) => { await new RemoveDialog() { Message = Helper.LocalizeMessage("DeleteMusicMessage", music.Name), Confirm = async() => { MainPage.Instance?.Loader.ShowIndeterminant("ProcessRequest"); MusicLibraryPage.AllSongs.Remove(music); Settings.settings.RemoveMusic(music); MediaHelper.DeleteMusic(music); listener?.Delete(music); if (!await Helper.FileNotExist(music.Path)) { StorageFile file = await StorageFile.GetFileFromPathAsync(music.Path); await file.DeleteAsync(); } MainPage.Instance?.Loader.Hide(); Helper.ShowNotification(Helper.LocalizeMessage("MusicDeleted", music.Name)); } }.ShowAsync(); }; deleteItem.SetToolTip(Helper.LocalizeMessage("DeleteMusic", music.Name), false); flyout.Items.Add(deleteItem); foreach (var item in GetMusicPropertiesMenuFlyout(option.ShowSeeArtistsAndSeeAlbum).Items) { flyout.Items.Add(item); } return(flyout); }
public MenuFlyout GetAddToPlaylistsMenuFlyout(IMenuFlyoutItemClickListener listener = null) { var flyout = new MenuFlyout(); var newPlaylistItem = new MenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Add), Text = Helper.Localize("New Playlist") }; newPlaylistItem.Click += async(sender, args) => { if (Data is IMusicable musicable) { Music music = musicable.ToMusic(); if (await Helper.FileNotExist(music.Path)) { Helper.ShowMusicNotFoundNotification(music.Name); return; } } var renameActionListener = new VirtualRenameActionListener { Data = Data, ConfirmAction = () => { listener?.AddTo(Data, null, -1, AddToCollectionType.NewPlaylist); foreach (var clickListener in ClickListeners) { clickListener?.AddTo(Data, null, -1, AddToCollectionType.NewPlaylist); } } }; var dialog = new RenameDialog(renameActionListener, RenameOption.New, DefaultPlaylistName); renameActionListener.Dialog = dialog; await dialog.ShowAsync(); }; newPlaylistItem.SetToolTip("Create a New Playlist"); flyout.Items.Add(newPlaylistItem); foreach (var playlist in Settings.settings.Playlists) { if (playlist.Name == CurrentPlaylistName || (Data is IMusicable m && playlist.Contains(m.ToMusic()))) { continue; } var item = new MenuFlyoutItem() { Icon = new SymbolIcon(Symbol.Audio), Text = playlist.Name }; item.Click += async(sender, args) => { if (Data is IMusicable musicable) { Music music = musicable.ToMusic(); if (await Helper.FileNotExist(music.Path)) { Helper.ShowMusicNotFoundNotification(music.Name); return; } playlist.Add(music); listener?.AddTo(Data, playlist, playlist.Count - 1, AddToCollectionType.Playlist); foreach (var clickListener in ClickListeners) { clickListener.AddTo(Data, playlist, playlist.Count - 1, AddToCollectionType.Playlist); } Helper.ShowCancelableNotificationWithoutLocalization(Helper.LocalizeMessage("SongAddedTo", music.Name, playlist.Name), () => { playlist.Remove(music); }); } else if (Data is IEnumerable <IMusicable> songs) { if (songs.Count() == 0) { return; } playlist.Add(Data); string message = songs.Count() == 1 ? Helper.LocalizeMessage("SongAddedTo", songs.ElementAt(0).ToMusic().Name, playlist.Name) : Helper.LocalizeMessage("SongsAddedTo", songs.Count(), playlist.Name); listener?.AddTo(Data, playlist, playlist.Count - songs.Count() - 1, AddToCollectionType.Playlist); foreach (var clickListener in ClickListeners) { clickListener.AddTo(Data, playlist, playlist.Count - songs.Count() - 1, AddToCollectionType.Playlist); } Helper.ShowCancelableNotificationWithoutLocalization(message, () => { playlist.Remove(songs); }); } else { return; } }; flyout.Items.Add(item); } return(flyout); }