diff --git a/Sources/Stylophone.Common/ViewModels/QueueViewModel.cs b/Sources/Stylophone.Common/ViewModels/QueueViewModel.cs index 4a9b223..6aad672 100644 --- a/Sources/Stylophone.Common/ViewModels/QueueViewModel.cs +++ b/Sources/Stylophone.Common/ViewModels/QueueViewModel.cs @@ -211,11 +211,10 @@ private async void MPDConnectionService_QueueChanged(object sender, EventArgs e) // If the response is empty, that means the last file in the source was removed. var initialPosition = response.Count() == 0 ? Source.Count - 1 : response.First().Position; + // Get all the tracks between initialPosition and the end of the Source + var tracksToRemove = Source.Skip(initialPosition).ToList(); await _dispatcherService.ExecuteOnUIThreadAsync(() => { - while (Source.Count > initialPosition) - { - Source.RemoveAt(initialPosition); - } + Source.RemoveRange(tracksToRemove); }); var toAdd = new List(); diff --git a/Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs b/Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs index 8f4e2f6..85f2852 100644 --- a/Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs +++ b/Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs @@ -238,7 +238,7 @@ private async Task UpdateServerVersionAsync() var songs = response.ContainsKey("songs") ? response["songs"] : "??"; var albums = response.ContainsKey("albums") ? response["albums"] : "??"; - if (outputs != null) + if (outputs != null && outputs.Count() > 0) { var outputString = outputs.Select(o => o.Plugin).Aggregate((s, s2) => $"{s}, {s2}"); diff --git a/Sources/Stylophone/Views/ServerQueuePage.xaml.cs b/Sources/Stylophone/Views/ServerQueuePage.xaml.cs index 3004bb0..79d6da7 100644 --- a/Sources/Stylophone/Views/ServerQueuePage.xaml.cs +++ b/Sources/Stylophone/Views/ServerQueuePage.xaml.cs @@ -7,6 +7,7 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; +using System.Collections.Specialized; namespace Stylophone.Views { @@ -31,7 +32,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - ViewModel.PropertyChanged += ViewModel_PropertyChanged; + ViewModel.Source.CollectionChanged += ScrollToPlayingSong; _mpdService.SongChanged += MPDConnectionService_SongChanged; @@ -58,19 +59,16 @@ private void MPDConnectionService_SongChanged(object sender, SongChangedEventArg }); } - private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + private void ScrollToPlayingSong(object sender, NotifyCollectionChangedEventArgs e) { - if (e.PropertyName == nameof(ViewModel.Source)) - { - if (QueueList.Items.Count == 0) - return; + if (QueueList.Items.Count == 0) + return; - var playing = ViewModel.Source.Where(t => t.IsPlaying && t.File.Id != manualSongId).FirstOrDefault(); - if (playing != null) - { - playing.UpdatePlayingStatus(); - QueueList.ScrollIntoView(playing, ScrollIntoViewAlignment.Leading); - } + var playing = ViewModel.Source.Where(t => t.IsPlaying && t.File.Id != manualSongId).FirstOrDefault(); + if (playing != null) + { + playing.UpdatePlayingStatus(); + QueueList.ScrollIntoView(playing, ScrollIntoViewAlignment.Leading); } }