Skip to content

Commit

Permalink
Rework queue again + fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Nov 26, 2022
1 parent 0f5a5b8 commit cc25b3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
7 changes: 3 additions & 4 deletions Sources/Stylophone.Common/ViewModels/QueueViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrackViewModel>();
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down
22 changes: 10 additions & 12 deletions Sources/Stylophone/Views/ServerQueuePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;

Expand All @@ -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);
}
}

Expand Down

0 comments on commit cc25b3a

Please sign in to comment.