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 MenuFlyoutSubItem GetAddToMenuFlyoutSubItem(IMenuFlyoutItemClickListener listener = null) { MenuFlyoutSubItem addToItem = new MenuFlyoutSubItem() { Text = Helper.Localize("Add To"), Name = AddToSubItemName }; addToItem.SetToolTip("Add To Playlist"); if (CurrentPlaylistName != NowPlaying) { var nowPlayingItem = new MenuFlyoutItem() { Icon = new FontIcon() { Glyph = "\uEC4F" }, Text = NowPlaying }; nowPlayingItem.Click += async(sender, args) => { if (Data is IMusicable musicable) { Music music = musicable.ToMusic(); if (await Helper.FileNotExist(music.Path)) { Helper.ShowMusicNotFoundNotification(music.Name); return; } MediaHelper.AddMusic(music); listener?.AddTo(Data, MediaHelper.CurrentPlaylist, MediaHelper.CurrentPlaylist.Count - 1, AddToCollectionType.NowPlaying); foreach (var clickListener in ClickListeners) { clickListener.AddTo(Data, MediaHelper.CurrentPlaylist, MediaHelper.CurrentPlaylist.Count - 1, AddToCollectionType.NowPlaying); } Helper.ShowCancelableNotificationWithoutLocalization(Helper.LocalizeMessage("SongAddedTo", music.Name, NowPlaying), () => { MediaHelper.RemoveMusic(music); }); } else if (Data is IEnumerable <IMusicable> songs) { if (songs.Count() == 0) { return; } foreach (var song in songs) { MediaHelper.AddMusic(song); } string message = songs.Count() == 1 ? Helper.LocalizeMessage("SongAddedTo", songs.ElementAt(0).ToMusic().Name, NowPlaying) : Helper.LocalizeMessage("SongsAddedTo", songs.Count(), NowPlaying); listener?.AddTo(Data, MediaHelper.CurrentPlaylist, MediaHelper.CurrentPlaylist.Count - songs.Count() - 1, AddToCollectionType.NowPlaying); foreach (var clickListener in ClickListeners) { clickListener.AddTo(Data, MediaHelper.CurrentPlaylist, MediaHelper.CurrentPlaylist.Count - songs.Count() - 1, AddToCollectionType.NowPlaying); } Helper.ShowCancelableNotificationWithoutLocalization(message, () => { foreach (var song in songs) { MediaHelper.RemoveMusic(song.ToMusic()); } }); } else { return; } }; addToItem.Items.Add(nowPlayingItem); } if (CurrentPlaylistName != MyFavorites && ((Data is IMusicable m && !Settings.settings.MyFavorites.Contains(m.ToMusic())) || (Data is IEnumerable <IMusicable> list && list.Any(music => !Settings.settings.MyFavorites.Contains(music.ToMusic()))))) { var favItem = new MenuFlyoutItem() { Icon = new FontIcon() { Glyph = "\uEB51" }, Text = MyFavorites }; favItem.Click += async(sender, args) => { if (Data is IMusicable musicable) { Music music = musicable.ToMusic(); if (await Helper.FileNotExist(music.Path)) { Helper.ShowMusicNotFoundNotification(music.Name); return; } Settings.settings.LikeMusic(music); Helper.ShowCancelableNotificationWithoutLocalization(Helper.LocalizeMessage("SongAddedTo", music.Name, MyFavorites), () => { Settings.settings.DislikeMusic(music); }); } else if (Data is IEnumerable <IMusicable> songs) { Settings.settings.LikeMusic(songs); string message = songs.Count() == 1 ? Helper.LocalizeMessage("SongAddedTo", songs.ElementAt(0).ToMusic().Name, MyFavorites) : Helper.LocalizeMessage("SongsAddedTo", songs.Count(), MyFavorites); Helper.ShowCancelableNotificationWithoutLocalization(message, () => { foreach (var song in songs) { Settings.settings.DislikeMusic(song.ToMusic()); } }); } else { return; } listener?.Favorite(Data); }; addToItem.Items.Add(favItem); } if (addToItem.Items.Count > 0) { addToItem.Items.Add(new MenuFlyoutSeparator()); } foreach (var item in GetAddToPlaylistsMenuFlyout(listener).Items) { addToItem.Items.Add(item); } return(addToItem); }