Skip to content

Commit

Permalink
Fixed playlist previous/next when moving items
Browse files Browse the repository at this point in the history
  • Loading branch information
FredTungsten committed Jan 11, 2020
1 parent 16035a2 commit 4a74053
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions ScriptPlayer/ScriptPlayer/ViewModels/PlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void PlaylistEntriesHaveChanged(bool filesAdded)
UpdateFilter();
CommandManager.InvalidateRequerySuggested();
UpdateTotalDuration();
UpdateNextAndPreviousIfNull();
UpdateNextAndPrevious();
OnEntriesChanged(filesAdded);
}

Expand Down Expand Up @@ -259,8 +259,22 @@ public bool RepeatSingleFile

private void UpdateNextAndPrevious()
{
PreviousEntry = GetPreviousEntry();
NextEntry = GetNextEntry();
if(Shuffle)
UpdateNextAndPreviousIfNull();
else
{
PreviousEntry = GetPreviousEntry();
NextEntry = GetNextEntry();
}
}

private void UpdateNextAndPreviousIfNull()
{
if (NextEntry == null)
NextEntry = GetNextEntry();

if (PreviousEntry == null || PreviousEntry == NextEntry)
PreviousEntry = GetPreviousEntry();
}

public PlaylistEntry SelectedEntry
Expand Down Expand Up @@ -631,6 +645,18 @@ private bool CanRemoveSelectedEntry()
return !SelectionIsEmpty();
}

public void Clear()
{
foreach (var entry in Entries)
entry.Removed = true;

Entries.Clear();
_previousEntries.Clear();
PreviousEntry = null;
NextEntry = null;
CommandManager.InvalidateRequerySuggested();
}

private void ExecuteRemoveSelectedEntry()
{
if (!CanRemoveSelectedEntry())
Expand Down Expand Up @@ -808,15 +834,6 @@ public void AddEntries(string[] filenames)
AddEntries(filenames.Select(fn => new PlaylistEntry(fn)));
}

private void UpdateNextAndPreviousIfNull()
{
if (NextEntry == null)
NextEntry = GetNextEntry();

if (PreviousEntry == null || PreviousEntry == NextEntry)
PreviousEntry = GetPreviousEntry();
}

public void AddEntries(IEnumerable<PlaylistEntry> entries)
{
try
Expand All @@ -840,19 +857,7 @@ public void AddEntries(IEnumerable<PlaylistEntry> entries)
DeferLoading = false;
}
}

public void Clear()
{
foreach (var entry in Entries)
entry.Removed = true;

Entries.Clear();
_previousEntries.Clear();
PreviousEntry = null;
NextEntry = null;
CommandManager.InvalidateRequerySuggested();
}


public void SetCurrentEntry(string[] files)
{
PlaylistEntry existingEntry = GetEntry(files);
Expand Down

0 comments on commit 4a74053

Please sign in to comment.