From 0793a074cf6299c53f5a6c5d7bdc842fee92f557 Mon Sep 17 00:00:00 2001 From: Zhe Fang Date: Mon, 29 Dec 2025 16:11:21 -0500 Subject: [PATCH] fix: add to playlists --- .../BetterLyrics.WinUI3.csproj | 1 + .../Controls/NowPlayingBar.xaml | 114 ++++- .../Controls/NowPlayingBar.xaml.cs | 53 ++- .../ViewModels/MusicGalleryPageViewModel.cs | 6 - .../Views/MusicGalleryPage.xaml | 445 +++++++----------- .../Views/MusicGalleryPage.xaml.cs | 102 ++-- .../Views/MusicGalleryWindow.xaml | 5 +- .../Views/MusicGalleryWindow.xaml.cs | 6 + 8 files changed, 408 insertions(+), 324 deletions(-) diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj index 9aed45b..9f5f563 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj @@ -69,6 +69,7 @@ + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml index b3217d2..2b68519 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml @@ -11,7 +11,6 @@ mc:Ignorable="d"> - + Spacing="12"> + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs index 0d40e1b..04dcd85 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs @@ -27,6 +27,15 @@ namespace BetterLyrics.WinUI3.Views { public MusicGalleryPageViewModel ViewModel => (MusicGalleryPageViewModel)DataContext; + public bool IsPlayingQueueOpened + { + get { return (bool)GetValue(IsPlayingQueueOpenedProperty); } + set { SetValue(IsPlayingQueueOpenedProperty, value); } + } + + public static readonly DependencyProperty IsPlayingQueueOpenedProperty = + DependencyProperty.Register(nameof(IsPlayingQueueOpened), typeof(bool), typeof(MusicGalleryPage), new PropertyMetadata(false, OnDependencyPropertyChanged)); + public MusicGalleryPage() { InitializeComponent(); @@ -34,6 +43,18 @@ namespace BetterLyrics.WinUI3.Views ViewModel.AppSettings.MusicGallerySettings.PropertyChanged += MusicGallerySettings_PropertyChanged; } + private static void OnDependencyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is MusicGalleryPage self) + { + if (e.Property == IsPlayingQueueOpenedProperty) + { + var newValue = (bool)e.NewValue; + self.PlayQueue.Translation = newValue ? new() : new(310, 0, 0); + } + } + } + private void ScrollToPlayingItem() { if (ViewModel.PlayingQueueItem == null) return; @@ -216,40 +237,6 @@ namespace BetterLyrics.WinUI3.Views SongListView.SelectedItems.Clear(); } - private void AddToPlaylistMenuFlyoutItem_Click(object sender, RoutedEventArgs e) - { - //((MenuFlyoutItem)sender).ContextFlyout.ShowAt(PlaylistButton); - } - - private void ToBeAddedPlaylistsListViewItemGrid_Tapped(object sender, TappedRoutedEventArgs e) - { - var songsTabInfo = ((SongsTabInfo)((FrameworkElement)sender).DataContext); - if (songsTabInfo.FilterProperty == CommonSongProperty.M3UFilePath) - { - if (songsTabInfo.FilterValue is string path) - { - if (File.Exists(path)) - { - var content = File.ReadAllText(path); - foreach (var item in ViewModel.SelectedTracks.Select(x => x.DecodedAbsoluteUri).ToList()) - { - if (!content.Contains(item)) - { - content += Environment.NewLine; - content += item; - } - } - File.WriteAllText(path, content); - ToastHelper.ShowToast("TracksAddToPlaylistSuccessfully", null, InfoBarSeverity.Success); - } - else - { - ToastHelper.ShowToast("TracksAddToPlaylistFailed", null, InfoBarSeverity.Error); - } - } - } - } - private async void SongListViewItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { var displayedTracks = SongListView.Items.Cast(); @@ -282,5 +269,52 @@ namespace BetterLyrics.WinUI3.Views ViewModel.SelectFolder(selectedFolder); } } + + private void ToBeAddedPlaylistsMenuFlyoutItem_Click(object sender, RoutedEventArgs e) + { + var songsTabInfo = ((SongsTabInfo)((FrameworkElement)sender).DataContext); + if (songsTabInfo.FilterProperty == CommonSongProperty.M3UFilePath) + { + if (songsTabInfo.FilterValue is string path) + { + if (File.Exists(path)) + { + var content = File.ReadAllText(path); + foreach (var item in ViewModel.SelectedTracks.Select(x => x.DecodedAbsoluteUri).ToList()) + { + if (!content.Contains(item)) + { + content += Environment.NewLine; + content += item; + } + } + File.WriteAllText(path, content); + ToastHelper.ShowToast("TracksAddToPlaylistSuccessfully", null, InfoBarSeverity.Success); + } + else + { + ToastHelper.ShowToast("TracksAddToPlaylistFailed", null, InfoBarSeverity.Error); + } + } + } + } + + private void AddToMenuBarItemFlyout_Opened(object sender, object e) + { + AddToCustomListMenuFlyoutSubItem.Items.Clear(); + foreach (var item in ViewModel.AppSettings.StarredPlaylists) + { + if (item.FilterProperty == CommonSongProperty.M3UFilePath) + { + var menuFlyoutItem = new MenuFlyoutItem + { + Text = item.Name, + DataContext = item, + }; + menuFlyoutItem.Click += ToBeAddedPlaylistsMenuFlyoutItem_Click; + AddToCustomListMenuFlyoutSubItem.Items.Add(menuFlyoutItem); + } + } + } } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml index 8608f2b..902c030 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml @@ -16,7 +16,7 @@ Loaded="RootGrid_Loaded" Unloaded="RootGrid_Unloaded"> - + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml.cs index c864ff0..8789483 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryWindow.xaml.cs @@ -1,3 +1,4 @@ +using BetterLyrics.WinUI3.Controls; using BetterLyrics.WinUI3.Enums; using BetterLyrics.WinUI3.Extensions; using BetterLyrics.WinUI3.Hooks; @@ -127,5 +128,10 @@ namespace BetterLyrics.WinUI3.Views { ViewModel.AppSettings.MusicGallerySettings.LyricsWindowStatus.IsOpened = false; } + + private void NowPlayingBar_PlayingQueueClick(object sender, System.EventArgs e) + { + MusicGalleryPage.IsPlayingQueueOpened = !MusicGalleryPage.IsPlayingQueueOpened; + } } }