Skip to content

Commit

Permalink
Close, but hanging badly.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbordeman committed Oct 31, 2024
1 parent cee1bd6 commit e443b92
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 155 deletions.
4 changes: 2 additions & 2 deletions Source/FileManager/BackgroundFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ private void Init()
fileSystemWatcher.Renamed += FileSystemWatcher_Changed;
fileSystemWatcher.Error += FileSystemWatcher_Error;

backgroundScanner = new Task(BackgroundScanner);
backgroundScanner.Start();
backgroundScanner = Task.Factory.StartNew(BackgroundScanner, TaskCreationOptions.LongRunning);
//backgroundScanner.Start();
}
private void Stop()
{
Expand Down
2 changes: 0 additions & 2 deletions Source/LibationUiBase/ViewModels/Player/PlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class BookAddedToPlaylist : PubSubEvent<ILibraryBookEntry>
public ILibraryBookEntry Book { get; }

public BookAddedToPlaylist() {}

public BookAddedToPlaylist(ILibraryBookEntry book)
{
Book = book;
Expand All @@ -20,7 +19,6 @@ public class BookRemovedFromPlaylist : PubSubEvent<ILibraryBookEntry>
public ILibraryBookEntry Book { get; }

public BookRemovedFromPlaylist() {}

public BookRemovedFromPlaylist(ILibraryBookEntry book)
{
Book = book;
Expand Down
50 changes: 32 additions & 18 deletions Source/LibationUiBase/ViewModels/Player/PlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace LibationUiBase.ViewModels.Player;

public class PlayerViewModel : ViewModelBase
{
const string CurrentIndicator = "▶";

private readonly IEventAggregator eventAggregator;
private BindingList<PlaylistEntryViewModel> playlistItems = new();
/// <summary>
Expand Down Expand Up @@ -37,20 +35,28 @@ public PlayerViewModel(IEventAggregator eventAggregator)
{
playlistItems.MoveUp(SelectedBook);
RenumberPlaylist();
}, _ => SelectedBook != null && playlistItems.IndexOf(SelectedBook) > 0);
var temp = SelectedBook;
SelectedBook = null;
SelectedBook = temp;
}, _ => SelectedBook != null && playlistItems.IndexOf(SelectedBook) > 0 &&
IsInPlaylist(SelectedBook));

MoveDownCommand = new RelayCommand(_ =>
{
playlistItems.MoveDown(SelectedBook);
RenumberPlaylist();
}, _ => SelectedBook != null && playlistItems.IndexOf(SelectedBook) < playlistItems.Count - 1);
var temp = SelectedBook;
SelectedBook = null;
SelectedBook = temp;
}, _ => SelectedBook != null && playlistItems.IndexOf(SelectedBook) < playlistItems.Count - 1 &&
IsInPlaylist(SelectedBook));

this.eventAggregator = eventAggregator;
}

private void RenumberPlaylist()
{
for (var i = 0; playlistItems.Count > 0; i++)
for (var i = 0; i < playlistItems.Count; i++)
playlistItems[i].Sequence = i + 1;
}

Expand All @@ -60,7 +66,7 @@ public async ValueTask AddToPlaylist(ILibraryBookEntry book)
await plevm.Init(book);
plevm.Sequence = playlistItems.Count + 1;
playlistItems.Add(plevm);
eventAggregator.GetEvent<BookAddedToPlaylist>().Publish(book);
//eventAggregator.GetEvent<BookAddedToPlaylist>().Publish(book);
}

public ValueTask RemoveFromPlaylist(ILibraryBookEntry book)
Expand All @@ -69,27 +75,36 @@ public ValueTask RemoveFromPlaylist(ILibraryBookEntry book)
if (plevm != null)
{
playlistItems.Remove(plevm);
eventAggregator.GetEvent<BookRemovedFromPlaylist>().Publish(book);
InvalidateCommands();
//eventAggregator.GetEvent<BookRemovedFromPlaylist>().Publish(book);
}

return ValueTask.CompletedTask;
}

private void InvalidateCommands()
{
MoveDownCommand.RaiseCanExecuteChanged();
MoveUpCommand.RaiseCanExecuteChanged();
}

public bool IsInPlaylist(ILibraryBookEntry book) =>
PlaylistItems.Any(item => item.BookEntry.AudibleProductId == book.AudibleProductId);

public override string ToString() =>
string.Join(", ", playlistItems);
public bool IsInPlaylist(PlaylistEntryViewModel book) =>
PlaylistItems.Any(item => item.BookEntry.AudibleProductId == book.BookEntry.AudibleProductId);


public override string ToString() => $"{nameof(PlayerViewModel)}: {string.Join(", ", playlistItems)}";

protected override void OnPropertyChanging(string propertyName)
{
switch (propertyName)
{
case nameof(SelectedBook):
//SelectedBook.IsCurrent = false;
//SelectedBook.IsCurrentStr = null;
MoveUpCommand.RaiseCanExecuteChanged();
MoveDownCommand.RaiseCanExecuteChanged();
if (SelectedBook != null)
SelectedBook.IsCurrent = false;
InvalidateCommands();
break;
}
}
Expand All @@ -99,11 +114,10 @@ protected override void OnPropertyChanged(string propertyName)
switch (propertyName)
{
case nameof(SelectedBook):
MoveDownCommand.RaiseCanExecuteChanged();
MoveUpCommand.RaiseCanExecuteChanged();
//SelectedBook.IsCurrent = true;
//SelectedBook.IsCurrentStr = CurrentIndicator;
if (SelectedBook != null)
SelectedBook.IsCurrent = true;
InvalidateCommands();
break;
}
}
}
}
19 changes: 19 additions & 0 deletions Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace LibationUiBase.ViewModels.Player;

public class PlaylistEntryViewModel : ViewModelBase

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / windows / Windows-chardonnay

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / windows / Windows-classic

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / linux (Debian, arm64) / Debian-arm64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / linux (Debian, x64) / Debian-x64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / linux (Redhat, arm64) / Redhat-arm64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / linux (Redhat, x64) / Redhat-x64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / macos (arm64) / MacOS-arm64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in Source/LibationUiBase/ViewModels/Player/PlaylistEntryViewModel.cs

View workflow job for this annotation

GitHub Actions / build / macos (x64) / MacOS-x64

'PlaylistEntryViewModel' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
const string CurrentIndicator = "▶";

private int sequence;
public int Sequence
{
Expand Down Expand Up @@ -50,4 +52,21 @@ public async ValueTask Init(ILibraryBookEntry bookEntry)
}

public override string ToString() => Title;

protected override void OnPropertyChanged(string propertyName)
{
switch (propertyName)
{
case nameof(IsCurrent):
IsCurrentStr = IsCurrent ? CurrentIndicator : null;
break;
}
}

public override bool Equals(object obj)
{
if (obj is PlaylistEntryViewModel plevm && bookEntry != null)
return bookEntry?.AudibleProductId == plevm?.bookEntry.AudibleProductId;
return false;
}
}
6 changes: 3 additions & 3 deletions Source/LibationUiBase/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public abstract class ViewModelBase : INotifyPropertyChanged, INotifyPropertyCha
{
public ViewModelBase()
{
this.PropertyChanged += (s, e) => OnPropertyChanged(e.PropertyName);
this.PropertyChanging += (s, e) => OnPropertyChanging(e.PropertyName);
this.PropertyChanged += (_, e) => OnPropertyChanged(e.PropertyName);
this.PropertyChanging += (_, e) => OnPropertyChanging(e.PropertyName);
}

protected virtual void OnPropertyChanging(string propertyName) { }
protected virtual void OnPropertyChanged(string propertyName) { }

public TRet RaiseAndSetIfChanged<TRet>(ref TRet backingField, TRet newValue, [CallerMemberName] string propertyName = null)
{
//if (EqualityComparer<TRet>.Default.Equals(backingField, newValue)) return newValue;
if (EqualityComparer<TRet>.Default.Equals(backingField, newValue)) return newValue;

RaisePropertyChanging(propertyName);
backingField = newValue;
Expand Down
Loading

0 comments on commit e443b92

Please sign in to comment.